Skip to content

Commit f25fb26

Browse files
authored
ref: DSN to Dsn casing change (#1503)
* ref: Rename any DSN occurence to Dsn * ref: User API to filter sentry requests in breadcrumbs
1 parent 4b40c39 commit f25fb26

File tree

24 files changed

+122
-123
lines changed

24 files changed

+122
-123
lines changed

packages/browser/src/backend.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class BrowserBackend implements Backend {
4444
* @inheritDoc
4545
*/
4646
public install(): boolean {
47-
// We are only called by the client if the SDK is enabled and a valid DSN
48-
// has been configured. If no DSN is present, this indicates a programming
47+
// We are only called by the client if the SDK is enabled and a valid Dsn
48+
// has been configured. If no Dsn is present, this indicates a programming
4949
// error.
5050
const dsn = this.options.dsn;
5151
if (!dsn) {
@@ -140,8 +140,8 @@ export class BrowserBackend implements Backend {
140140
*/
141141
public async sendEvent(event: SentryEvent): Promise<SentryResponse> {
142142
if (!this.options.dsn) {
143-
logger.warn(`Event has been skipped because no DSN is configured.`);
144-
// We do nothing in case there is no DSN
143+
logger.warn(`Event has been skipped because no Dsn is configured.`);
144+
// We do nothing in case there is no Dsn
145145
return { status: Status.Skipped };
146146
}
147147

packages/browser/src/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API, BaseClient, SentryError } from '@sentry/core';
2-
import { DSNLike } from '@sentry/types';
2+
import { DsnLike } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44
import { BrowserBackend, BrowserOptions } from './backend';
55

@@ -23,7 +23,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
2323
public showReportDialog(options: {
2424
[key: string]: any;
2525
eventId?: string;
26-
dsn?: DSNLike;
26+
dsn?: DsnLike;
2727
user?: {
2828
email?: string;
2929
name?: string;
@@ -47,14 +47,14 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
4747
return;
4848
}
4949

50-
const dsn = options.dsn || this.getDSN();
50+
const dsn = options.dsn || this.getDsn();
5151

5252
if (!options.eventId) {
5353
throw new SentryError('Missing `eventId` option in showReportDialog call');
5454
}
5555

5656
if (!dsn) {
57-
throw new SentryError('Missing `DSN` option in showReportDialog call');
57+
throw new SentryError('Missing `Dsn` option in showReportDialog call');
5858
}
5959

6060
const script = document.createElement('script');

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DSN } from '@sentry/core';
1+
import { API } from '@sentry/core';
22
import { getCurrentHub } from '@sentry/hub';
33
import { Integration, Severity } from '@sentry/types';
44
import { isFunction, isString } from '@sentry/utils/is';
@@ -354,8 +354,7 @@ export class Breadcrumbs implements Integration {
354354
* Can be disabled or individually configured via the `autoBreadcrumbs` config option
355355
*/
356356
public install(options: BrowserOptions = {}): void {
357-
// TODO: Use API provider instead of raw `new DSN`
358-
const filterUrl = options.dsn && new DSN(options.dsn).user;
357+
const filterUrl = options.dsn && new API(options.dsn).getStoreEndpoint();
359358

360359
if (this.config.console) {
361360
this.instrumentConsole();

packages/browser/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const defaultIntegrations = [
3232
* import { init } from '@sentry/browser';
3333
*
3434
* init({
35-
* dsn: '__DSN__',
35+
* dsn: '__Dsn__',
3636
* // ...
3737
* });
3838
*

packages/browser/test/backend.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ let backend: BrowserBackend;
2424

2525
describe('BrowserBackend', () => {
2626
describe('sendEvent()', () => {
27-
it('should throw when no DSN is provided', async () => {
27+
it('should throw when no Dsn is provided', async () => {
2828
backend = new BrowserBackend({ dsn });
2929

3030
try {
3131
await backend.sendEvent(testEvent);
3232
} catch (e) {
33-
expect(e.message).equal('Cannot sendEvent without a valid DSN');
33+
expect(e.message).equal('Cannot sendEvent without a valid Dsn');
3434
}
3535
});
3636

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { expect } from 'chai';
22
import { BaseTransport } from '../../src/transports/base';
33

4-
const testDSN = 'https://[email protected]/42';
4+
const testDsn = 'https://[email protected]/42';
55

66
class SimpleTransport extends BaseTransport {}
77

88
describe('BaseTransport', () => {
99
it('doesnt provide send() implementation', async () => {
10-
const transport = new SimpleTransport({ dsn: testDSN });
10+
const transport = new SimpleTransport({ dsn: testDsn });
1111

1212
try {
1313
await transport.send({});
@@ -17,7 +17,7 @@ describe('BaseTransport', () => {
1717
});
1818

1919
it('has correct endpoint url', () => {
20-
const transport = new SimpleTransport({ dsn: testDSN });
20+
const transport = new SimpleTransport({ dsn: testDsn });
2121
expect(transport.url).equal('https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7');
2222
});
2323
});

packages/browser/test/transports/beacon.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import { SinonStub, stub } from 'sinon';
33
import { Status, Transports } from '../../src';
44

5-
const testDSN = 'https://[email protected]/42';
5+
const testDsn = 'https://[email protected]/42';
66
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
77
const payload = {
88
event_id: '1337',
@@ -18,7 +18,7 @@ let transport: Transports.BaseTransport;
1818
describe('BeaconTransport', () => {
1919
beforeEach(() => {
2020
sendBeacon = stub(window.navigator, 'sendBeacon');
21-
transport = new Transports.BeaconTransport({ dsn: testDSN });
21+
transport = new Transports.BeaconTransport({ dsn: testDsn });
2222
});
2323

2424
afterEach(() => {

packages/browser/test/transports/fetch.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import { SinonStub, stub } from 'sinon';
33
import { Status, Transports } from '../../src';
44

5-
const testDSN = 'https://[email protected]/42';
5+
const testDsn = 'https://[email protected]/42';
66
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
77
const payload = {
88
event_id: '1337',
@@ -18,7 +18,7 @@ let transport: Transports.BaseTransport;
1818
describe('FetchTransport', () => {
1919
beforeEach(() => {
2020
fetch = stub(window, 'fetch');
21-
transport = new Transports.FetchTransport({ dsn: testDSN });
21+
transport = new Transports.FetchTransport({ dsn: testDsn });
2222
});
2323

2424
afterEach(() => {

packages/browser/test/transports/xhr.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import { fakeServer, SinonFakeServer } from 'sinon';
33
import { Status, Transports } from '../../src';
44

5-
const testDSN = 'https://[email protected]/42';
5+
const testDsn = 'https://[email protected]/42';
66
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
77
const payload = {
88
event_id: '1337',
@@ -19,7 +19,7 @@ describe('XHRTransport', () => {
1919
beforeEach(() => {
2020
server = fakeServer.create();
2121
server.respondImmediately = true;
22-
transport = new Transports.XHRTransport({ dsn: testDSN });
22+
transport = new Transports.XHRTransport({ dsn: testDsn });
2323
});
2424

2525
afterEach(() => {

packages/core/src/api.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { DSNLike } from '@sentry/types';
1+
import { DsnLike } from '@sentry/types';
22
import { urlEncode } from '@sentry/utils/object';
3-
import { DSN } from './dsn';
3+
import { Dsn } from './dsn';
44

55
const SENTRY_API_VERSION = '7';
66

77
/** Helper class to provide urls to different Sentry endpoints. */
88
export class API {
9-
/** The internally used DSN object. */
10-
private readonly dsnObject: DSN;
9+
/** The internally used Dsn object. */
10+
private readonly dsnObject: Dsn;
1111
/** Create a new instance of API */
12-
public constructor(public dsn: DSNLike) {
13-
this.dsnObject = new DSN(dsn);
12+
public constructor(public dsn: DsnLike) {
13+
this.dsnObject = new Dsn(dsn);
1414
}
1515

16-
/** Returns the DSN object. */
17-
public getDSN(): DSN {
16+
/** Returns the Dsn object. */
17+
public getDsn(): Dsn {
1818
return this.dsnObject;
1919
}
2020

packages/core/src/base.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Scope } from '@sentry/hub';
22
import { Breadcrumb, SentryEvent, SentryEventHint, SentryResponse, Severity, Status } from '@sentry/types';
33
import { uuid4 } from '@sentry/utils/misc';
44
import { truncate } from '@sentry/utils/string';
5-
import { DSN } from './dsn';
5+
import { Dsn } from './dsn';
66
import { Backend, Client, Options } from './interfaces';
77

88
/**
@@ -35,10 +35,10 @@ export interface BackendClass<B extends Backend, O extends Options> {
3535
* {@link Client.getOptions}. Also, the Backend instance is available via
3636
* {@link Client.getBackend}.
3737
*
38-
* If a DSN is specified in the options, it will be parsed and stored. Use
39-
* {@link Client.getDSN} to retrieve the DSN at any moment. In case the DSN is
38+
* If a Dsn is specified in the options, it will be parsed and stored. Use
39+
* {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is
4040
* invalid, the constructor will throw a {@link SentryException}. Note that
41-
* without a valid DSN, the SDK will not send any events to Sentry.
41+
* without a valid Dsn, the SDK will not send any events to Sentry.
4242
*
4343
* Before sending an event via the backend, it is passed through
4444
* {@link BaseClient.prepareEvent} to add SDK information and scope data
@@ -71,10 +71,10 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
7171
private readonly options: O;
7272

7373
/**
74-
* The client DSN, if specified in options. Without this DSN, the SDK will be
74+
* The client Dsn, if specified in options. Without this Dsn, the SDK will be
7575
* disabled.
7676
*/
77-
private readonly dsn?: DSN;
77+
private readonly dsn?: Dsn;
7878

7979
/**
8080
* Stores whether installation has been performed and was successful. Before
@@ -93,7 +93,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
9393
this.options = options;
9494

9595
if (options.dsn) {
96-
this.dsn = new DSN(options.dsn);
96+
this.dsn = new Dsn(options.dsn);
9797
}
9898
}
9999

@@ -167,7 +167,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
167167
/**
168168
* @inheritDoc
169169
*/
170-
public getDSN(): DSN | undefined {
170+
public getDsn(): Dsn | undefined {
171171
return this.dsn;
172172
}
173173

@@ -183,7 +183,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
183183
return this.backend;
184184
}
185185

186-
/** Determines whether this SDK is enabled and a valid DSN is present. */
186+
/** Determines whether this SDK is enabled and a valid Dsn is present. */
187187
protected isEnabled(): boolean {
188188
return this.getOptions().enabled !== false && this.dsn !== undefined;
189189
}

packages/core/src/dsn.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { DSNComponents, DSNLike, DSNProtocol } from '@sentry/types';
1+
import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
22
import { SentryError } from './error';
33

4-
/** Regular expression used to parse a DSN. */
4+
/** Regular expression used to parse a Dsn. */
55
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w\.-]+)(?::(\d+))?\/(.+)/;
66

7-
/** The Sentry DSN, identifying a Sentry instance and project. */
8-
export class DSN implements DSNComponents {
7+
/** The Sentry Dsn, identifying a Sentry instance and project. */
8+
export class Dsn implements DsnComponents {
99
/** Protocol used to connect to Sentry. */
10-
public protocol!: DSNProtocol;
10+
public protocol!: DsnProtocol;
1111
/** Public authorization key. */
1212
public user!: string;
1313
/** Private authorization key (deprecated, optional). */
@@ -21,8 +21,8 @@ export class DSN implements DSNComponents {
2121
/** Project ID */
2222
public projectId!: string;
2323

24-
/** Creates a new DSN component */
25-
public constructor(from: DSNLike) {
24+
/** Creates a new Dsn component */
25+
public constructor(from: DsnLike) {
2626
if (typeof from === 'string') {
2727
this.fromString(from);
2828
} else {
@@ -33,7 +33,7 @@ export class DSN implements DSNComponents {
3333
}
3434

3535
/**
36-
* Renders the string representation of this DSN.
36+
* Renders the string representation of this Dsn.
3737
*
3838
* By default, this will render the public representation without the password
3939
* component. To get the deprecated private representation, set `withPassword`
@@ -50,11 +50,11 @@ export class DSN implements DSNComponents {
5050
);
5151
}
5252

53-
/** Parses a string into this DSN. */
53+
/** Parses a string into this Dsn. */
5454
private fromString(str: string): void {
5555
const match = DSN_REGEX.exec(str);
5656
if (!match) {
57-
throw new SentryError('Invalid DSN');
57+
throw new SentryError('Invalid Dsn');
5858
}
5959

6060
const [protocol, user, pass = '', host, port = '', lastPath] = match.slice(1);
@@ -68,8 +68,8 @@ export class DSN implements DSNComponents {
6868
Object.assign(this, { host, pass, path, projectId, port, protocol, user });
6969
}
7070

71-
/** Maps DSN components into this instance. */
72-
private fromComponents(components: DSNComponents): void {
71+
/** Maps Dsn components into this instance. */
72+
private fromComponents(components: DsnComponents): void {
7373
this.protocol = components.protocol;
7474
this.user = components.user;
7575
this.pass = components.pass || '';
@@ -79,20 +79,20 @@ export class DSN implements DSNComponents {
7979
this.projectId = components.projectId;
8080
}
8181

82-
/** Validates this DSN and throws on error. */
82+
/** Validates this Dsn and throws on error. */
8383
private validate(): void {
8484
for (const component of ['protocol', 'user', 'host', 'projectId']) {
85-
if (!this[component as keyof DSNComponents]) {
86-
throw new SentryError(`Invalid DSN: Missing ${component}`);
85+
if (!this[component as keyof DsnComponents]) {
86+
throw new SentryError(`Invalid Dsn: Missing ${component}`);
8787
}
8888
}
8989

9090
if (this.protocol !== 'http' && this.protocol !== 'https') {
91-
throw new SentryError(`Invalid DSN: Unsupported protocol "${this.protocol}"`);
91+
throw new SentryError(`Invalid Dsn: Unsupported protocol "${this.protocol}"`);
9292
}
9393

9494
if (this.port && isNaN(parseInt(this.port, 10))) {
95-
throw new SentryError(`Invalid DSN: Invalid port number "${this.port}"`);
95+
throw new SentryError(`Invalid Dsn: Invalid port number "${this.port}"`);
9696
}
9797
}
9898
}

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { captureException, captureMessage, configureScope } from '@sentry/minima
33
export { Hub, Scope } from '@sentry/hub';
44
export { API } from './api';
55
export { BackendClass, BaseClient } from './base';
6-
export { DSN } from './dsn';
6+
export { Dsn } from './dsn';
77
export { SentryError } from './error';
88
export { Backend, Client, LogLevel, Options } from './interfaces';
99
export { initAndBind, ClientClass } from './sdk';

packages/core/src/interfaces.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
TransportClass,
1212
TransportOptions,
1313
} from '@sentry/types';
14-
import { DSN } from './dsn';
14+
import { Dsn } from './dsn';
1515

1616
/** Console logging verbosity for the SDK. */
1717
export enum LogLevel {
@@ -40,7 +40,7 @@ export interface Options {
4040
enabled?: boolean;
4141

4242
/**
43-
* The DSN used to connect to Sentry and identify the project. If omitted, the
43+
* The Dsn used to connect to Sentry and identify the project. If omitted, the
4444
* SDK will not send any data to Sentry.
4545
*/
4646
dsn?: string;
@@ -189,8 +189,8 @@ export interface Client<O extends Options = Options> {
189189
*/
190190
addBreadcrumb(breadcrumb: Breadcrumb, scope?: Scope): void;
191191

192-
/** Returns the current DSN. */
193-
getDSN(): DSN | undefined;
192+
/** Returns the current Dsn. */
193+
getDsn(): Dsn | undefined;
194194

195195
/** Returns the current options. */
196196
getOptions(): O;

0 commit comments

Comments
 (0)