Skip to content

Commit e25d00b

Browse files
committed
ref: User API to filter sentry requests in breadcrumbs
1 parent 673454d commit e25d00b

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

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/core/src/dsn.ts

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

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

77
/** The Sentry Dsn, identifying a Sentry instance and project. */
88
export class Dsn implements DsnComponents {
@@ -52,7 +52,7 @@ export class Dsn implements DsnComponents {
5252

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

packages/core/test/lib/base.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SentryError } from '../../src/error';
44
import { TestBackend } from '../mocks/backend';
55
import { TestClient } from '../mocks/client';
66

7-
const PUBLIC_Dsn = 'https://username@domain/path';
7+
const PUBLIC_DSN = 'https://username@domain/path';
88

99
jest.mock('@sentry/utils/misc', () => ({
1010
uuid4(): string {
@@ -24,8 +24,8 @@ jest.mock('@sentry/utils/string', () => ({
2424
describe('BaseClient', () => {
2525
describe('constructor() / getDsn()', () => {
2626
test('returns the Dsn', () => {
27-
const client = new TestClient({ dsn: PUBLIC_Dsn });
28-
expect(client.getDsn()!.toString()).toBe(PUBLIC_Dsn);
27+
const client = new TestClient({ dsn: PUBLIC_DSN });
28+
expect(client.getDsn()!.toString()).toBe(PUBLIC_DSN);
2929
});
3030

3131
test('allows missing Dsn', () => {
@@ -40,13 +40,13 @@ describe('BaseClient', () => {
4040

4141
describe('install()', () => {
4242
test('calls install() on Backend', async () => {
43-
const client = new TestClient({ dsn: PUBLIC_Dsn });
43+
const client = new TestClient({ dsn: PUBLIC_DSN });
4444
client.install();
4545
expect(TestBackend.instance!.installed).toBe(1);
4646
});
4747

4848
test('calls install() only once', async () => {
49-
const client = new TestClient({ dsn: PUBLIC_Dsn });
49+
const client = new TestClient({ dsn: PUBLIC_DSN });
5050
client.install();
5151
client.install();
5252
expect(TestBackend.instance!.installed).toBe(1);
@@ -59,7 +59,7 @@ describe('BaseClient', () => {
5959
});
6060

6161
test('does not install() when disabled', async () => {
62-
const client = new TestClient({ enabled: false, dsn: PUBLIC_Dsn });
62+
const client = new TestClient({ enabled: false, dsn: PUBLIC_DSN });
6363
client.install();
6464
expect(TestBackend.instance!.installed).toBe(0);
6565
});
@@ -73,7 +73,7 @@ describe('BaseClient', () => {
7373

7474
describe('getOptions()', () => {
7575
test('returns the options', () => {
76-
const options = { dsn: PUBLIC_Dsn, test: true };
76+
const options = { dsn: PUBLIC_DSN, test: true };
7777
const client = new TestClient(options);
7878
expect(client.getOptions()).toEqual(options);
7979
});
@@ -142,7 +142,7 @@ describe('BaseClient', () => {
142142

143143
describe('captures', () => {
144144
test('captures and sends exceptions', async () => {
145-
const client = new TestClient({ dsn: PUBLIC_Dsn });
145+
const client = new TestClient({ dsn: PUBLIC_DSN });
146146
const scope = new Scope();
147147
await client.captureException(new Error('test exception'), undefined, scope);
148148
expect(TestBackend.instance!.event).toEqual({
@@ -160,7 +160,7 @@ describe('BaseClient', () => {
160160
});
161161

162162
test('captures and sends messages', async () => {
163-
const client = new TestClient({ dsn: PUBLIC_Dsn });
163+
const client = new TestClient({ dsn: PUBLIC_DSN });
164164
const scope = new Scope();
165165
await client.captureMessage('test message', undefined, undefined, scope);
166166
expect(TestBackend.instance!.event).toEqual({
@@ -172,7 +172,7 @@ describe('BaseClient', () => {
172172

173173
describe('captureEvent() / prepareEvent()', () => {
174174
test('skips when disabled', async () => {
175-
const client = new TestClient({ enabled: false, dsn: PUBLIC_Dsn });
175+
const client = new TestClient({ enabled: false, dsn: PUBLIC_DSN });
176176
const scope = new Scope();
177177
await client.captureEvent({}, undefined, scope);
178178
expect(TestBackend.instance!.event).toBeUndefined();
@@ -186,7 +186,7 @@ describe('BaseClient', () => {
186186
});
187187

188188
test('sends an event', async () => {
189-
const client = new TestClient({ dsn: PUBLIC_Dsn });
189+
const client = new TestClient({ dsn: PUBLIC_DSN });
190190
const scope = new Scope();
191191
await client.captureEvent({ message: 'message' }, undefined, scope);
192192
expect(TestBackend.instance!.event!.message).toBe('message');
@@ -198,7 +198,7 @@ describe('BaseClient', () => {
198198

199199
test('adds the configured environment', async () => {
200200
const client = new TestClient({
201-
dsn: PUBLIC_Dsn,
201+
dsn: PUBLIC_DSN,
202202
environment: 'env',
203203
});
204204
const scope = new Scope();
@@ -212,7 +212,7 @@ describe('BaseClient', () => {
212212

213213
test('adds the configured release', async () => {
214214
const client = new TestClient({
215-
dsn: PUBLIC_Dsn,
215+
dsn: PUBLIC_DSN,
216216
release: 'v1.0.0',
217217
});
218218
const scope = new Scope();
@@ -225,7 +225,7 @@ describe('BaseClient', () => {
225225
});
226226

227227
test('adds breadcrumbs', async () => {
228-
const client = new TestClient({ dsn: PUBLIC_Dsn });
228+
const client = new TestClient({ dsn: PUBLIC_DSN });
229229
const scope = new Scope();
230230
scope.addBreadcrumb({ message: 'breadcrumb' }, 100);
231231
await client.captureEvent({ message: 'message' }, undefined, scope);
@@ -237,7 +237,7 @@ describe('BaseClient', () => {
237237
});
238238

239239
test('limits previously saved breadcrumbs', async () => {
240-
const client = new TestClient({ dsn: PUBLIC_Dsn, maxBreadcrumbs: 1 });
240+
const client = new TestClient({ dsn: PUBLIC_DSN, maxBreadcrumbs: 1 });
241241
const scope = new Scope();
242242
scope.addBreadcrumb({ message: '1' }, 100);
243243
scope.addBreadcrumb({ message: '2' }, 200);
@@ -250,7 +250,7 @@ describe('BaseClient', () => {
250250
});
251251

252252
test('adds context data', async () => {
253-
const client = new TestClient({ dsn: PUBLIC_Dsn });
253+
const client = new TestClient({ dsn: PUBLIC_DSN });
254254
const scope = new Scope();
255255
scope.setExtra('b', 'b');
256256
scope.setTag('a', 'a');
@@ -266,7 +266,7 @@ describe('BaseClient', () => {
266266
});
267267

268268
test('adds fingerprint', async () => {
269-
const client = new TestClient({ dsn: PUBLIC_Dsn });
269+
const client = new TestClient({ dsn: PUBLIC_DSN });
270270
const scope = new Scope();
271271
scope.setFingerprint(['abcd']);
272272
await client.captureEvent({ message: 'message' }, undefined, scope);
@@ -279,22 +279,22 @@ describe('BaseClient', () => {
279279

280280
test('calls beforeSend and discards the event', async () => {
281281
const beforeSend = jest.fn(() => null);
282-
const client = new TestClient({ dsn: PUBLIC_Dsn, beforeSend });
282+
const client = new TestClient({ dsn: PUBLIC_DSN, beforeSend });
283283
const scope = new Scope();
284284
await client.captureEvent({ message: 'hello' }, undefined, scope);
285285
expect(TestBackend.instance!.event).toBeUndefined();
286286
});
287287

288288
test('calls beforeSend and uses the new one', async () => {
289289
const beforeSend = jest.fn(() => ({ message: 'changed' }));
290-
const client = new TestClient({ dsn: PUBLIC_Dsn, beforeSend });
290+
const client = new TestClient({ dsn: PUBLIC_DSN, beforeSend });
291291
const scope = new Scope();
292292
await client.captureEvent({ message: 'hello' }, undefined, scope);
293293
expect(TestBackend.instance!.event!.message).toBe('changed');
294294
});
295295

296296
it("doesn't do anything with rate limits yet", async () => {
297-
const client = new TestClient({ dsn: PUBLIC_Dsn });
297+
const client = new TestClient({ dsn: PUBLIC_DSN });
298298
TestBackend.instance!.sendEvent = async () => ({ status: Status.RateLimit });
299299
const scope = new Scope();
300300
await client.captureEvent({}, undefined, scope);

packages/node/src/integrations/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ function emitWrapper(origEmit: EventListener): (event: string, response: ServerR
112112
return origEmit.apply(this, arguments);
113113
}
114114

115-
const Dsn = getCurrentHub()
115+
const dsn = getCurrentHub()
116116
.getClient()
117117
.getDsn();
118118

119119
const isInterestingEvent = event === 'response' || event === 'error';
120-
const isNotSentryRequest = Dsn && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(Dsn.host);
120+
const isNotSentryRequest = dsn && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(dsn.host);
121121

122122
if (isInterestingEvent && isNotSentryRequest) {
123123
addBreadcrumb({

0 commit comments

Comments
 (0)