Skip to content

Commit 3dd0cce

Browse files
committed
apply review suggestions
1 parent c5de662 commit 3dd0cce

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/tracing/src/browser/request.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010

1111
import { getActiveTransaction, hasTracingEnabled } from '../utils';
1212

13-
// TODO (v8): Remove `tracingOrigins`
14-
export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//];
1513
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//];
1614

1715
/** Options for Request Instrumentation */
@@ -140,13 +138,16 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
140138
/**
141139
* Creates a function that determines whether to attach tracing headers to a request.
142140
* This was extracted from `instrumentOutgoingRequests` to make it easier to test shouldAttachHeaders.
141+
* We only export this fuction for testing purposes.
143142
* TODO (v8): Remove `tracingOrigins` which should drastically simplify this function.
144143
*/
145144
export function makeShouldAttachHeaders(
146145
tracePropagationTargets: (string | RegExp)[] | undefined,
147146
tracingOrigins: (string | RegExp)[] | undefined,
148147
) {
149148
return (url: string): boolean => {
149+
// TODO (v8): Replace the code below with this one-liner:
150+
// return stringMatchesSomePattern(url, tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS);
150151
if (tracePropagationTargets || tracingOrigins) {
151152
return stringMatchesSomePattern(url, tracePropagationTargets || tracingOrigins);
152153
}

packages/tracing/test/browser/request.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,12 @@ describe('[pre-v8]: shouldAttachHeaders', () => {
398398
const shouldAttachHeaders = makeShouldAttachHeaders(['example.com'], undefined);
399399
expect(shouldAttachHeaders('http://example.com')).toBe(true);
400400
});
401+
401402
it('should return `false` if tracePropagationTargets array is empty', () => {
402403
const shouldAttachHeaders = makeShouldAttachHeaders([], ['localhost']);
403404
expect(shouldAttachHeaders('http://localhost:3000/test')).toBe(false);
404405
});
406+
405407
it("should return `false` if tracePropagationTargets array doesn't match", () => {
406408
const shouldAttachHeaders = makeShouldAttachHeaders(['example.com'], ['localhost']);
407409
expect(shouldAttachHeaders('http://localhost:3000/test')).toBe(false);
@@ -413,10 +415,12 @@ describe('[pre-v8]: shouldAttachHeaders', () => {
413415
const shouldAttachHeaders = makeShouldAttachHeaders(undefined, ['example.com']);
414416
expect(shouldAttachHeaders('http://example.com')).toBe(true);
415417
});
418+
416419
it('should return `false` if tracePropagationTargets array is empty', () => {
417420
const shouldAttachHeaders = makeShouldAttachHeaders(undefined, []);
418421
expect(shouldAttachHeaders('http://localhost:3000/test')).toBe(false);
419422
});
423+
420424
it("should return `false` if tracePropagationTargets array doesn't match", () => {
421425
const shouldAttachHeaders = makeShouldAttachHeaders(undefined, ['example.com']);
422426
expect(shouldAttachHeaders('http://localhost:3000/test')).toBe(false);
@@ -433,6 +437,7 @@ describe('[pre-v8]: shouldAttachHeaders', () => {
433437
const shouldAttachHeaders = makeShouldAttachHeaders(undefined, undefined);
434438
expect(shouldAttachHeaders(url)).toBe(true);
435439
});
440+
436441
it.each(['notmydoman/api/test', 'example.com'])('return `false` for urls not matching defaults (%s)', url => {
437442
const shouldAttachHeaders = makeShouldAttachHeaders(undefined, undefined);
438443
expect(shouldAttachHeaders(url)).toBe(false);

0 commit comments

Comments
 (0)