Skip to content

Commit 7c5c438

Browse files
committed
implement
1 parent 39740da commit 7c5c438

7 files changed

Lines changed: 83 additions & 0 deletions

File tree

  • dev-packages/browser-integration-tests/suites
  • packages/browser/src/integrations
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [Sentry.spanStreamingIntegration(), Sentry.browserTracingIntegration()],
8+
tracesSampleRate: 1.0,
9+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect } from '@playwright/test';
2+
import { sentryTest } from '../../../utils/fixtures';
3+
import { shouldSkipTracingTest } from '../../../utils/helpers';
4+
import { getSpanOp, waitForStreamedSpans } from '../../../utils/spanUtils';
5+
6+
sentryTest('httpContextIntegration captures url, user-agent, and referer', async ({ getLocalTestUrl, page }) => {
7+
sentryTest.skip(shouldSkipTracingTest());
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
const spansPromise = waitForStreamedSpans(page, spans => spans.some(s => getSpanOp(s) === 'pageload'));
11+
12+
await page.goto(url, { referer: 'https://sentry.io/' });
13+
14+
const spans = await spansPromise;
15+
16+
const pageloadSpan = spans.find(s => getSpanOp(s) === 'pageload');
17+
18+
expect(pageloadSpan!.attributes?.['url.full']).toEqual({ type: 'string', value: expect.any(String) });
19+
expect(pageloadSpan!.attributes?.['http.request.header.user_agent']).toEqual({
20+
type: 'string',
21+
value: expect.any(String),
22+
});
23+
expect(pageloadSpan!.attributes?.['http.request.header.referer']).toEqual({
24+
type: 'string',
25+
value: 'https://sentry.io/',
26+
});
27+
});

dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ sentryTest(
179179
type: 'string',
180180
value: expect.any(String),
181181
},
182+
'http.request.header.user_agent': {
183+
type: 'string',
184+
value: expect.any(String),
185+
},
186+
'url.full': {
187+
type: 'string',
188+
value: expect.any(String),
189+
},
182190
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: {
183191
type: 'string',
184192
value: 'test',

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/interactions-streamed/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ sentryTest('captures streamed interaction span tree. @firefox', async ({ browser
5252
type: 'string',
5353
value: expect.any(String),
5454
},
55+
'http.request.header.user_agent': {
56+
type: 'string',
57+
value: expect.any(String),
58+
},
59+
'url.full': {
60+
type: 'string',
61+
value: expect.any(String),
62+
},
5563
[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]: {
5664
type: 'string',
5765
value: 'idleTimeout',

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/navigation-streamed/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ sentryTest('starts a streamed navigation span on page navigation', async ({ brow
8181
type: 'string',
8282
value: expect.any(String),
8383
},
84+
'http.request.header.user_agent': {
85+
type: 'string',
86+
value: expect.any(String),
87+
},
88+
'url.full': {
89+
type: 'string',
90+
value: expect.any(String),
91+
},
8492
'device.processor_count': {
8593
type: expect.stringMatching(/^(integer)|(double)$/),
8694
value: expect.any(Number),

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-streamed/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ sentryTest(
7474
type: 'string',
7575
value: expect.any(String),
7676
},
77+
'http.request.header.user_agent': {
78+
type: 'string',
79+
value: expect.any(String),
80+
},
81+
'url.full': {
82+
type: 'string',
83+
value: expect.any(String),
84+
},
7785
// formerly known as 'hardwareConcurrency'
7886
'device.processor_count': {
7987
type: expect.stringMatching(/^(integer)|(double)$/),

packages/browser/src/integrations/httpcontext.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@ export const httpContextIntegration = defineIntegration(() => {
2626
headers,
2727
};
2828
},
29+
processSegmentSpan(span) {
30+
// if none of the information we want exists, don't bother
31+
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
32+
return;
33+
}
34+
35+
const reqData = getHttpRequestData();
36+
37+
span.attributes = {
38+
'url.full': reqData.url,
39+
'http.request.header.user_agent': reqData.headers['User-Agent'],
40+
'http.request.header.referer': reqData.headers['Referer'],
41+
...span.attributes,
42+
};
43+
},
2944
};
3045
});

0 commit comments

Comments
 (0)