Skip to content

Commit 77dd704

Browse files
authored
fix(tracing): Pass tracePropagationTargets to instrumentOutgoingRequests (#6259)
Fix a bug in our `BrowserTracing` integration which caused the new `tracePropagationTargets` option not to be passed to `instrumentOutgoingRequests` where it was needed to decide if our tracing headers should be attached to outgoing requests or not. Because we never passed this value to the instrumentation function, custom-defined `tracePropagationTargets` values were not respected by the SDK and headers were attached to requests whose URLs matched the default targets or custom specified `tracingOrigins`. With this fix, we also make a change how we internally handle the co-existance between the deprecated `tracingOrigins` and `tracePropagationTargets` options. We now simply overwrite the default `tracePropagationTargets` values with custom `tracingOrigins` (if available and no custom `tracePropagationTargets` were set). This enables us to internally only rely on `tracePropagationTargets`. Note that we still have to keep setting `tracingOrigins` to `browserTracing.options`, as removing this field or changing the type would break users. This field however is not used internally anymore. This patch also adds a bunch of unit and integration tests to make sure, `tracePropagationTargets` works as expected this time. Also, the tests check that `tracingOrigins` is still respected properly.
1 parent 74810e0 commit 77dd704

File tree

19 files changed

+270
-41
lines changed

19 files changed

+270
-41
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing({ tracePropagationTargets: ['http://example.com'] })],
9+
tracesSampleRate: 1,
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'should attach `sentry-trace` and `baggage` header to request matching tracePropagationTargets',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [
9+
new Integrations.BrowserTracing({ tracePropagationTargets: [], tracingOrigins: ['http://example.com'] }),
10+
],
11+
tracesSampleRate: 1,
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'[pre-v8] should prefer custom tracePropagationTargets over tracingOrigins',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).not.toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing({ tracingOrigins: ['http://example.com'] })],
9+
tracesSampleRate: 1,
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'[pre-v8] should attach `sentry-trace` and `baggage` header to request matching tracingOrigins',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing()],
9+
tracesSampleRate: 1,
10+
});

0 commit comments

Comments
 (0)