diff --git a/packages/browser/src/backend.ts b/packages/browser/src/backend.ts index ebc270a14f04..f28593b7851d 100644 --- a/packages/browser/src/backend.ts +++ b/packages/browser/src/backend.ts @@ -44,8 +44,8 @@ export class BrowserBackend implements Backend { * @inheritDoc */ public install(): boolean { - // We are only called by the client if the SDK is enabled and a valid DSN - // has been configured. If no DSN is present, this indicates a programming + // We are only called by the client if the SDK is enabled and a valid Dsn + // has been configured. If no Dsn is present, this indicates a programming // error. const dsn = this.options.dsn; if (!dsn) { @@ -140,8 +140,8 @@ export class BrowserBackend implements Backend { */ public async sendEvent(event: SentryEvent): Promise { if (!this.options.dsn) { - logger.warn(`Event has been skipped because no DSN is configured.`); - // We do nothing in case there is no DSN + logger.warn(`Event has been skipped because no Dsn is configured.`); + // We do nothing in case there is no Dsn return { status: Status.Skipped }; } diff --git a/packages/browser/src/client.ts b/packages/browser/src/client.ts index 060858fcb13e..1deaa3d45eca 100644 --- a/packages/browser/src/client.ts +++ b/packages/browser/src/client.ts @@ -1,5 +1,5 @@ import { API, BaseClient, SentryError } from '@sentry/core'; -import { DSNLike } from '@sentry/types'; +import { DsnLike } from '@sentry/types'; import { getGlobalObject } from '@sentry/utils/misc'; import { BrowserBackend, BrowserOptions } from './backend'; @@ -23,7 +23,7 @@ export class BrowserClient extends BaseClient { public showReportDialog(options: { [key: string]: any; eventId?: string; - dsn?: DSNLike; + dsn?: DsnLike; user?: { email?: string; name?: string; @@ -47,14 +47,14 @@ export class BrowserClient extends BaseClient { return; } - const dsn = options.dsn || this.getDSN(); + const dsn = options.dsn || this.getDsn(); if (!options.eventId) { throw new SentryError('Missing `eventId` option in showReportDialog call'); } if (!dsn) { - throw new SentryError('Missing `DSN` option in showReportDialog call'); + throw new SentryError('Missing `Dsn` option in showReportDialog call'); } const script = document.createElement('script'); diff --git a/packages/browser/src/integrations/breadcrumbs.ts b/packages/browser/src/integrations/breadcrumbs.ts index a8eda53f686f..b38849863ff3 100644 --- a/packages/browser/src/integrations/breadcrumbs.ts +++ b/packages/browser/src/integrations/breadcrumbs.ts @@ -1,4 +1,4 @@ -import { DSN } from '@sentry/core'; +import { API } from '@sentry/core'; import { getCurrentHub } from '@sentry/hub'; import { Integration, Severity } from '@sentry/types'; import { isFunction, isString } from '@sentry/utils/is'; @@ -354,8 +354,7 @@ export class Breadcrumbs implements Integration { * Can be disabled or individually configured via the `autoBreadcrumbs` config option */ public install(options: BrowserOptions = {}): void { - // TODO: Use API provider instead of raw `new DSN` - const filterUrl = options.dsn && new DSN(options.dsn).user; + const filterUrl = options.dsn && new API(options.dsn).getStoreEndpoint(); if (this.config.console) { this.instrumentConsole(); diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 8d3fe733b75a..b28cd9ceeb22 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -32,7 +32,7 @@ export const defaultIntegrations = [ * import { init } from '@sentry/browser'; * * init({ - * dsn: '__DSN__', + * dsn: '__Dsn__', * // ... * }); * diff --git a/packages/browser/test/backend.test.ts b/packages/browser/test/backend.test.ts index 1599ed9c1895..671b0c106539 100644 --- a/packages/browser/test/backend.test.ts +++ b/packages/browser/test/backend.test.ts @@ -24,13 +24,13 @@ let backend: BrowserBackend; describe('BrowserBackend', () => { describe('sendEvent()', () => { - it('should throw when no DSN is provided', async () => { + it('should throw when no Dsn is provided', async () => { backend = new BrowserBackend({ dsn }); try { await backend.sendEvent(testEvent); } catch (e) { - expect(e.message).equal('Cannot sendEvent without a valid DSN'); + expect(e.message).equal('Cannot sendEvent without a valid Dsn'); } }); diff --git a/packages/browser/test/transports/base.test.ts b/packages/browser/test/transports/base.test.ts index f990591700df..0ca1490948b7 100644 --- a/packages/browser/test/transports/base.test.ts +++ b/packages/browser/test/transports/base.test.ts @@ -1,13 +1,13 @@ import { expect } from 'chai'; import { BaseTransport } from '../../src/transports/base'; -const testDSN = 'https://123@sentry.io/42'; +const testDsn = 'https://123@sentry.io/42'; class SimpleTransport extends BaseTransport {} describe('BaseTransport', () => { it('doesnt provide send() implementation', async () => { - const transport = new SimpleTransport({ dsn: testDSN }); + const transport = new SimpleTransport({ dsn: testDsn }); try { await transport.send({}); @@ -17,7 +17,7 @@ describe('BaseTransport', () => { }); it('has correct endpoint url', () => { - const transport = new SimpleTransport({ dsn: testDSN }); + const transport = new SimpleTransport({ dsn: testDsn }); expect(transport.url).equal('https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7'); }); }); diff --git a/packages/browser/test/transports/beacon.test.ts b/packages/browser/test/transports/beacon.test.ts index bb99deb20671..2e975e1ca3d0 100644 --- a/packages/browser/test/transports/beacon.test.ts +++ b/packages/browser/test/transports/beacon.test.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { SinonStub, stub } from 'sinon'; import { Status, Transports } from '../../src'; -const testDSN = 'https://123@sentry.io/42'; +const testDsn = 'https://123@sentry.io/42'; const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7'; const payload = { event_id: '1337', @@ -18,7 +18,7 @@ let transport: Transports.BaseTransport; describe('BeaconTransport', () => { beforeEach(() => { sendBeacon = stub(window.navigator, 'sendBeacon'); - transport = new Transports.BeaconTransport({ dsn: testDSN }); + transport = new Transports.BeaconTransport({ dsn: testDsn }); }); afterEach(() => { diff --git a/packages/browser/test/transports/fetch.test.ts b/packages/browser/test/transports/fetch.test.ts index b57b85ae3bd0..533848b0910c 100644 --- a/packages/browser/test/transports/fetch.test.ts +++ b/packages/browser/test/transports/fetch.test.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { SinonStub, stub } from 'sinon'; import { Status, Transports } from '../../src'; -const testDSN = 'https://123@sentry.io/42'; +const testDsn = 'https://123@sentry.io/42'; const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7'; const payload = { event_id: '1337', @@ -18,7 +18,7 @@ let transport: Transports.BaseTransport; describe('FetchTransport', () => { beforeEach(() => { fetch = stub(window, 'fetch'); - transport = new Transports.FetchTransport({ dsn: testDSN }); + transport = new Transports.FetchTransport({ dsn: testDsn }); }); afterEach(() => { diff --git a/packages/browser/test/transports/xhr.test.ts b/packages/browser/test/transports/xhr.test.ts index 8d06a098310c..9a617431329b 100644 --- a/packages/browser/test/transports/xhr.test.ts +++ b/packages/browser/test/transports/xhr.test.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { fakeServer, SinonFakeServer } from 'sinon'; import { Status, Transports } from '../../src'; -const testDSN = 'https://123@sentry.io/42'; +const testDsn = 'https://123@sentry.io/42'; const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7'; const payload = { event_id: '1337', @@ -19,7 +19,7 @@ describe('XHRTransport', () => { beforeEach(() => { server = fakeServer.create(); server.respondImmediately = true; - transport = new Transports.XHRTransport({ dsn: testDSN }); + transport = new Transports.XHRTransport({ dsn: testDsn }); }); afterEach(() => { diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index d095c83d9fc3..6bc2cc334f67 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,20 +1,20 @@ -import { DSNLike } from '@sentry/types'; +import { DsnLike } from '@sentry/types'; import { urlEncode } from '@sentry/utils/object'; -import { DSN } from './dsn'; +import { Dsn } from './dsn'; const SENTRY_API_VERSION = '7'; /** Helper class to provide urls to different Sentry endpoints. */ export class API { - /** The internally used DSN object. */ - private readonly dsnObject: DSN; + /** The internally used Dsn object. */ + private readonly dsnObject: Dsn; /** Create a new instance of API */ - public constructor(public dsn: DSNLike) { - this.dsnObject = new DSN(dsn); + public constructor(public dsn: DsnLike) { + this.dsnObject = new Dsn(dsn); } - /** Returns the DSN object. */ - public getDSN(): DSN { + /** Returns the Dsn object. */ + public getDsn(): Dsn { return this.dsnObject; } diff --git a/packages/core/src/base.ts b/packages/core/src/base.ts index 233b82f176ef..54b2e3b65227 100644 --- a/packages/core/src/base.ts +++ b/packages/core/src/base.ts @@ -2,7 +2,7 @@ import { Scope } from '@sentry/hub'; import { Breadcrumb, SentryEvent, SentryEventHint, SentryResponse, Severity, Status } from '@sentry/types'; import { uuid4 } from '@sentry/utils/misc'; import { truncate } from '@sentry/utils/string'; -import { DSN } from './dsn'; +import { Dsn } from './dsn'; import { Backend, Client, Options } from './interfaces'; /** @@ -35,10 +35,10 @@ export interface BackendClass { * {@link Client.getOptions}. Also, the Backend instance is available via * {@link Client.getBackend}. * - * If a DSN is specified in the options, it will be parsed and stored. Use - * {@link Client.getDSN} to retrieve the DSN at any moment. In case the DSN is + * If a Dsn is specified in the options, it will be parsed and stored. Use + * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is * invalid, the constructor will throw a {@link SentryException}. Note that - * without a valid DSN, the SDK will not send any events to Sentry. + * without a valid Dsn, the SDK will not send any events to Sentry. * * Before sending an event via the backend, it is passed through * {@link BaseClient.prepareEvent} to add SDK information and scope data @@ -71,10 +71,10 @@ export abstract class BaseClient implement private readonly options: O; /** - * The client DSN, if specified in options. Without this DSN, the SDK will be + * The client Dsn, if specified in options. Without this Dsn, the SDK will be * disabled. */ - private readonly dsn?: DSN; + private readonly dsn?: Dsn; /** * Stores whether installation has been performed and was successful. Before @@ -93,7 +93,7 @@ export abstract class BaseClient implement this.options = options; if (options.dsn) { - this.dsn = new DSN(options.dsn); + this.dsn = new Dsn(options.dsn); } } @@ -167,7 +167,7 @@ export abstract class BaseClient implement /** * @inheritDoc */ - public getDSN(): DSN | undefined { + public getDsn(): Dsn | undefined { return this.dsn; } @@ -183,7 +183,7 @@ export abstract class BaseClient implement return this.backend; } - /** Determines whether this SDK is enabled and a valid DSN is present. */ + /** Determines whether this SDK is enabled and a valid Dsn is present. */ protected isEnabled(): boolean { return this.getOptions().enabled !== false && this.dsn !== undefined; } diff --git a/packages/core/src/dsn.ts b/packages/core/src/dsn.ts index 641546d4c673..60851601f20c 100644 --- a/packages/core/src/dsn.ts +++ b/packages/core/src/dsn.ts @@ -1,13 +1,13 @@ -import { DSNComponents, DSNLike, DSNProtocol } from '@sentry/types'; +import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types'; import { SentryError } from './error'; -/** Regular expression used to parse a DSN. */ +/** Regular expression used to parse a Dsn. */ const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w\.-]+)(?::(\d+))?\/(.+)/; -/** The Sentry DSN, identifying a Sentry instance and project. */ -export class DSN implements DSNComponents { +/** The Sentry Dsn, identifying a Sentry instance and project. */ +export class Dsn implements DsnComponents { /** Protocol used to connect to Sentry. */ - public protocol!: DSNProtocol; + public protocol!: DsnProtocol; /** Public authorization key. */ public user!: string; /** Private authorization key (deprecated, optional). */ @@ -21,8 +21,8 @@ export class DSN implements DSNComponents { /** Project ID */ public projectId!: string; - /** Creates a new DSN component */ - public constructor(from: DSNLike) { + /** Creates a new Dsn component */ + public constructor(from: DsnLike) { if (typeof from === 'string') { this.fromString(from); } else { @@ -33,7 +33,7 @@ export class DSN implements DSNComponents { } /** - * Renders the string representation of this DSN. + * Renders the string representation of this Dsn. * * By default, this will render the public representation without the password * component. To get the deprecated private representation, set `withPassword` @@ -50,11 +50,11 @@ export class DSN implements DSNComponents { ); } - /** Parses a string into this DSN. */ + /** Parses a string into this Dsn. */ private fromString(str: string): void { const match = DSN_REGEX.exec(str); if (!match) { - throw new SentryError('Invalid DSN'); + throw new SentryError('Invalid Dsn'); } const [protocol, user, pass = '', host, port = '', lastPath] = match.slice(1); @@ -68,8 +68,8 @@ export class DSN implements DSNComponents { Object.assign(this, { host, pass, path, projectId, port, protocol, user }); } - /** Maps DSN components into this instance. */ - private fromComponents(components: DSNComponents): void { + /** Maps Dsn components into this instance. */ + private fromComponents(components: DsnComponents): void { this.protocol = components.protocol; this.user = components.user; this.pass = components.pass || ''; @@ -79,20 +79,20 @@ export class DSN implements DSNComponents { this.projectId = components.projectId; } - /** Validates this DSN and throws on error. */ + /** Validates this Dsn and throws on error. */ private validate(): void { for (const component of ['protocol', 'user', 'host', 'projectId']) { - if (!this[component as keyof DSNComponents]) { - throw new SentryError(`Invalid DSN: Missing ${component}`); + if (!this[component as keyof DsnComponents]) { + throw new SentryError(`Invalid Dsn: Missing ${component}`); } } if (this.protocol !== 'http' && this.protocol !== 'https') { - throw new SentryError(`Invalid DSN: Unsupported protocol "${this.protocol}"`); + throw new SentryError(`Invalid Dsn: Unsupported protocol "${this.protocol}"`); } if (this.port && isNaN(parseInt(this.port, 10))) { - throw new SentryError(`Invalid DSN: Invalid port number "${this.port}"`); + throw new SentryError(`Invalid Dsn: Invalid port number "${this.port}"`); } } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 861576bbc369..53a7651da691 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -3,7 +3,7 @@ export { captureException, captureMessage, configureScope } from '@sentry/minima export { Hub, Scope } from '@sentry/hub'; export { API } from './api'; export { BackendClass, BaseClient } from './base'; -export { DSN } from './dsn'; +export { Dsn } from './dsn'; export { SentryError } from './error'; export { Backend, Client, LogLevel, Options } from './interfaces'; export { initAndBind, ClientClass } from './sdk'; diff --git a/packages/core/src/interfaces.ts b/packages/core/src/interfaces.ts index 635371579409..718a1eabcd68 100644 --- a/packages/core/src/interfaces.ts +++ b/packages/core/src/interfaces.ts @@ -11,7 +11,7 @@ import { TransportClass, TransportOptions, } from '@sentry/types'; -import { DSN } from './dsn'; +import { Dsn } from './dsn'; /** Console logging verbosity for the SDK. */ export enum LogLevel { @@ -40,7 +40,7 @@ export interface Options { enabled?: boolean; /** - * The DSN used to connect to Sentry and identify the project. If omitted, the + * The Dsn used to connect to Sentry and identify the project. If omitted, the * SDK will not send any data to Sentry. */ dsn?: string; @@ -189,8 +189,8 @@ export interface Client { */ addBreadcrumb(breadcrumb: Breadcrumb, scope?: Scope): void; - /** Returns the current DSN. */ - getDSN(): DSN | undefined; + /** Returns the current Dsn. */ + getDsn(): Dsn | undefined; /** Returns the current options. */ getOptions(): O; diff --git a/packages/core/test/lib/api.test.ts b/packages/core/test/lib/api.test.ts index 0266aad88dc8..9fe2007c365a 100644 --- a/packages/core/test/lib/api.test.ts +++ b/packages/core/test/lib/api.test.ts @@ -1,5 +1,5 @@ import { API } from '../../src/api'; -import { DSN } from '../../src/dsn'; +import { Dsn } from '../../src/dsn'; const dsnPublic = 'https://abc@sentry.io:1234/subpath/123'; @@ -47,7 +47,7 @@ describe('API', () => { }), ).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc'); }); - test('getDSN', () => { - expect(new API(dsnPublic).getDSN()).toEqual(new DSN(dsnPublic)); + test('getDsn', () => { + expect(new API(dsnPublic).getDsn()).toEqual(new Dsn(dsnPublic)); }); }); diff --git a/packages/core/test/lib/base.test.ts b/packages/core/test/lib/base.test.ts index 2accf1a05e43..4de0651d2d6a 100644 --- a/packages/core/test/lib/base.test.ts +++ b/packages/core/test/lib/base.test.ts @@ -22,18 +22,18 @@ jest.mock('@sentry/utils/string', () => ({ })); describe('BaseClient', () => { - describe('constructor() / getDSN()', () => { - test('returns the DSN', () => { + describe('constructor() / getDsn()', () => { + test('returns the Dsn', () => { const client = new TestClient({ dsn: PUBLIC_DSN }); - expect(client.getDSN()!.toString()).toBe(PUBLIC_DSN); + expect(client.getDsn()!.toString()).toBe(PUBLIC_DSN); }); - test('allows missing DSN', () => { + test('allows missing Dsn', () => { const client = new TestClient({}); - expect(client.getDSN()).toBeUndefined(); + expect(client.getDsn()).toBeUndefined(); }); - test('throws with invalid DSN', () => { + test('throws with invalid Dsn', () => { expect(() => new TestClient({ dsn: 'abc' })).toThrow(SentryError); }); }); @@ -64,7 +64,7 @@ describe('BaseClient', () => { expect(TestBackend.instance!.installed).toBe(0); }); - test('does not install() without DSN', async () => { + test('does not install() without Dsn', async () => { const client = new TestClient({}); client.install(); expect(TestBackend.instance!.installed).toBe(0); @@ -178,7 +178,7 @@ describe('BaseClient', () => { expect(TestBackend.instance!.event).toBeUndefined(); }); - test('skips without a DSN', async () => { + test('skips without a Dsn', async () => { const client = new TestClient({}); const scope = new Scope(); await client.captureEvent({}, undefined, scope); diff --git a/packages/core/test/lib/dsn.test.ts b/packages/core/test/lib/dsn.test.ts index bd335332193a..fc91da7bf3df 100644 --- a/packages/core/test/lib/dsn.test.ts +++ b/packages/core/test/lib/dsn.test.ts @@ -1,10 +1,10 @@ -import { DSN } from '../../src/dsn'; +import { Dsn } from '../../src/dsn'; import { SentryError } from '../../src/error'; -describe('DSN', () => { +describe('Dsn', () => { describe('fromComponents', () => { test('applies all components', () => { - const dsn = new DSN({ + const dsn = new Dsn({ host: 'sentry.io', pass: 'xyz', port: '1234', @@ -22,7 +22,7 @@ describe('DSN', () => { }); test('applies partial components', () => { - const dsn = new DSN({ + const dsn = new Dsn({ host: 'sentry.io', projectId: '123', protocol: 'https', @@ -40,7 +40,7 @@ describe('DSN', () => { test('throws for missing components', () => { expect( () => - new DSN({ + new Dsn({ host: '', projectId: '123', protocol: 'https', @@ -49,7 +49,7 @@ describe('DSN', () => { ).toThrow(SentryError); expect( () => - new DSN({ + new Dsn({ host: 'sentry.io', projectId: '', protocol: 'https', @@ -58,7 +58,7 @@ describe('DSN', () => { ).toThrow(SentryError); expect( () => - new DSN({ + new Dsn({ host: 'sentry.io', projectId: '123', protocol: '' as 'http', // Trick the type checker here @@ -67,7 +67,7 @@ describe('DSN', () => { ).toThrow(SentryError); expect( () => - new DSN({ + new Dsn({ host: 'sentry.io', projectId: '123', protocol: 'https', @@ -79,7 +79,7 @@ describe('DSN', () => { test('throws for invalid components', () => { expect( () => - new DSN({ + new Dsn({ host: 'sentry.io', projectId: '123', protocol: 'httpx' as 'http', // Trick the type checker here @@ -88,7 +88,7 @@ describe('DSN', () => { ).toThrow(SentryError); expect( () => - new DSN({ + new Dsn({ host: 'sentry.io', port: 'xxx', projectId: '123', @@ -100,8 +100,8 @@ describe('DSN', () => { }); describe('fromString', () => { - test('parses a valid full DSN', () => { - const dsn = new DSN('https://abc:xyz@sentry.io:1234/123'); + test('parses a valid full Dsn', () => { + const dsn = new Dsn('https://abc:xyz@sentry.io:1234/123'); expect(dsn.protocol).toBe('https'); expect(dsn.user).toBe('abc'); expect(dsn.pass).toBe('xyz'); @@ -111,8 +111,8 @@ describe('DSN', () => { expect(dsn.path).toBe(''); }); - test('parses a valid partial DSN', () => { - const dsn = new DSN('https://abc@sentry.io/123/321'); + test('parses a valid partial Dsn', () => { + const dsn = new Dsn('https://abc@sentry.io/123/321'); expect(dsn.protocol).toBe('https'); expect(dsn.user).toBe('abc'); expect(dsn.pass).toBe(''); @@ -123,7 +123,7 @@ describe('DSN', () => { }); test('with a long path', () => { - const dsn = new DSN('https://abc@sentry.io/sentry/custom/installation/321'); + const dsn = new Dsn('https://abc@sentry.io/sentry/custom/installation/321'); expect(dsn.protocol).toBe('https'); expect(dsn.user).toBe('abc'); expect(dsn.pass).toBe(''); @@ -133,46 +133,46 @@ describe('DSN', () => { expect(dsn.projectId).toBe('321'); }); - test('throws when provided invalid DSN', () => { - expect(() => new DSN('some@random.dsn')).toThrow(SentryError); + test('throws when provided invalid Dsn', () => { + expect(() => new Dsn('some@random.dsn')).toThrow(SentryError); }); test('throws without mandatory fields', () => { - expect(() => new DSN('://abc@sentry.io/123')).toThrow(SentryError); - expect(() => new DSN('https://@sentry.io/123')).toThrow(SentryError); - expect(() => new DSN('https://abc@123')).toThrow(SentryError); - expect(() => new DSN('https://abc@sentry.io/')).toThrow(SentryError); + expect(() => new Dsn('://abc@sentry.io/123')).toThrow(SentryError); + expect(() => new Dsn('https://@sentry.io/123')).toThrow(SentryError); + expect(() => new Dsn('https://abc@123')).toThrow(SentryError); + expect(() => new Dsn('https://abc@sentry.io/')).toThrow(SentryError); }); test('throws for invalid fields', () => { - expect(() => new DSN('httpx://abc@sentry.io/123')).toThrow(SentryError); - expect(() => new DSN('httpx://abc@sentry.io:xxx/123')).toThrow(SentryError); + expect(() => new Dsn('httpx://abc@sentry.io/123')).toThrow(SentryError); + expect(() => new Dsn('httpx://abc@sentry.io:xxx/123')).toThrow(SentryError); }); }); describe('toString', () => { test('excludes the password by default', () => { - const dsn = new DSN('https://abc:xyz@sentry.io:1234/123'); + const dsn = new Dsn('https://abc:xyz@sentry.io:1234/123'); expect(dsn.toString()).toBe('https://abc@sentry.io:1234/123'); }); test('optionally includes the password', () => { - const dsn = new DSN('https://abc:xyz@sentry.io:1234/123'); + const dsn = new Dsn('https://abc:xyz@sentry.io:1234/123'); expect(dsn.toString(true)).toBe('https://abc:xyz@sentry.io:1234/123'); }); test('renders no password if missing', () => { - const dsn = new DSN('https://abc@sentry.io:1234/123'); + const dsn = new Dsn('https://abc@sentry.io:1234/123'); expect(dsn.toString(true)).toBe('https://abc@sentry.io:1234/123'); }); test('renders no port if missing', () => { - const dsn = new DSN('https://abc@sentry.io/123'); + const dsn = new Dsn('https://abc@sentry.io/123'); expect(dsn.toString()).toBe('https://abc@sentry.io/123'); }); test('renders the full path correctly', () => { - const dsn = new DSN('https://abc@sentry.io/sentry/custom/installation/321'); + const dsn = new Dsn('https://abc@sentry.io/sentry/custom/installation/321'); expect(dsn.toString()).toBe('https://abc@sentry.io/sentry/custom/installation/321'); }); }); diff --git a/packages/node/src/backend.ts b/packages/node/src/backend.ts index d35f51ccaa8b..a69c7a8590c1 100644 --- a/packages/node/src/backend.ts +++ b/packages/node/src/backend.ts @@ -1,4 +1,4 @@ -import { Backend, DSN, Options, SentryError } from '@sentry/core'; +import { Backend, Dsn, Options, SentryError } from '@sentry/core'; import { getCurrentHub } from '@sentry/hub'; import { SentryEvent, SentryEventHint, SentryResponse, Severity, Transport } from '@sentry/types'; import { isError, isPlainObject } from '@sentry/utils/is'; @@ -88,12 +88,12 @@ export class NodeBackend implements Backend { * @inheritDoc */ public async sendEvent(event: SentryEvent): Promise { - let dsn: DSN; + let dsn: Dsn; if (!this.options.dsn) { - throw new SentryError('Cannot sendEvent without a valid DSN'); + throw new SentryError('Cannot sendEvent without a valid Dsn'); } else { - dsn = new DSN(this.options.dsn); + dsn = new Dsn(this.options.dsn); } if (!this.transport) { diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 2a4f38d1bdea..8ff60964df64 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -112,12 +112,12 @@ function emitWrapper(origEmit: EventListener): (event: string, response: ServerR return origEmit.apply(this, arguments); } - const DSN = getCurrentHub() + const dsn = getCurrentHub() .getClient() - .getDSN(); + .getDsn(); const isInterestingEvent = event === 'response' || event === 'error'; - const isNotSentryRequest = DSN && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(DSN.host); + const isNotSentryRequest = dsn && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(dsn.host); if (isInterestingEvent && isNotSentryRequest) { addBreadcrumb({ diff --git a/packages/node/src/sdk.ts b/packages/node/src/sdk.ts index aea33c919254..abd64b9833dd 100644 --- a/packages/node/src/sdk.ts +++ b/packages/node/src/sdk.ts @@ -30,7 +30,7 @@ export const defaultIntegrations = [ * const { init } = require('@sentry/node'); * * init({ - * dsn: '__DSN__', + * dsn: '__Dsn__', * // ... * }); * diff --git a/packages/node/src/transports/base.ts b/packages/node/src/transports/base.ts index 64e810eaea53..52d0b227f7a7 100644 --- a/packages/node/src/transports/base.ts +++ b/packages/node/src/transports/base.ts @@ -36,10 +36,10 @@ export abstract class BaseTransport implements Transport { return { agent: this.client, headers, - hostname: this.api.getDSN().host, + hostname: this.api.getDsn().host, method: 'POST', path: this.api.getStoreEndpointPath(), - port: this.api.getDSN().port, + port: this.api.getDsn().port, }; } diff --git a/packages/node/test/transports/http.test.ts b/packages/node/test/transports/http.test.ts index 2a7af9fb292b..d7b82b19a64a 100644 --- a/packages/node/test/transports/http.test.ts +++ b/packages/node/test/transports/http.test.ts @@ -28,7 +28,7 @@ jest.mock('http', () => ({ }, })); -import { DSN, SentryError } from '@sentry/core'; +import { Dsn, SentryError } from '@sentry/core'; import { getCurrentHub, init, NodeClient } from '../../src'; const dsn = 'http://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622'; @@ -73,7 +73,7 @@ describe('HTTPTransport', () => { const client = new NodeClient({ dsn, transportOptions: { - dsn: new DSN(dsn), + dsn: new Dsn(dsn), headers: { a: 'b', }, diff --git a/packages/node/test/transports/https.test.ts b/packages/node/test/transports/https.test.ts index 92421931c8dc..f2553ad3c19c 100644 --- a/packages/node/test/transports/https.test.ts +++ b/packages/node/test/transports/https.test.ts @@ -28,7 +28,7 @@ jest.mock('https', () => ({ }, })); -import { DSN, SentryError } from '@sentry/core'; +import { Dsn, SentryError } from '@sentry/core'; import { getCurrentHub, init, NodeClient } from '../../src'; const dsn = 'https://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622'; @@ -73,7 +73,7 @@ describe('HTTPSTransport', () => { const client = new NodeClient({ dsn, transportOptions: { - dsn: new DSN(dsn), + dsn: new Dsn(dsn), headers: { a: 'b', }, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index eecde01dd5aa..76acb9d14e03 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,10 +1,10 @@ -/** Supported Sentry transport protocols in a DSN. */ -export type DSNProtocol = 'http' | 'https'; +/** Supported Sentry transport protocols in a Dsn. */ +export type DsnProtocol = 'http' | 'https'; -/** Primitive components of a DSN. */ -export interface DSNComponents { +/** Primitive components of a Dsn. */ +export interface DsnComponents { /** Protocol used to connect to Sentry. */ - protocol: DSNProtocol; + protocol: DsnProtocol; /** Public authorization key. */ user: string; /** Private authorization key (deprecated, optional). */ @@ -19,8 +19,8 @@ export interface DSNComponents { projectId: string; } -/** Anything that can be parsed into a DSN. */ -export type DSNLike = string | DSNComponents; +/** Anything that can be parsed into a Dsn. */ +export type DsnLike = string | DsnComponents; /** JSDoc */ export enum Severity { @@ -215,7 +215,7 @@ export interface SentryResponse { /** JSDoc */ export interface TransportOptions { - dsn: DSNLike; + dsn: DsnLike; /** Define custom headers */ headers?: object; }