Skip to content

Commit 6093ab6

Browse files
committed
browser integration test
1 parent cea476c commit 6093ab6

File tree

6 files changed

+87
-19
lines changed

6 files changed

+87
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const activeSpan = Sentry.getActiveSpan();
22
const rootSpan = activeSpan && Sentry.getRootSpan(activeSpan);
3-
rootSpan?.updateName('new name');
3+
rootSpan.updateName('new name');

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-update-txn-name/test.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,34 @@ import {
1010
import { sentryTest } from '../../../../utils/fixtures';
1111
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
1212

13-
sentryTest('sets the source to custom when updating the transaction name', async ({ getLocalTestUrl, page }) => {
14-
if (shouldSkipTracingTest()) {
15-
sentryTest.skip();
16-
}
13+
sentryTest(
14+
'sets the source to custom when updating the transaction name with `span.updateName`',
15+
async ({ getLocalTestUrl, page }) => {
16+
if (shouldSkipTracingTest()) {
17+
sentryTest.skip();
18+
}
1719

18-
const url = await getLocalTestUrl({ testDir: __dirname });
20+
const url = await getLocalTestUrl({ testDir: __dirname });
1921

20-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
22+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
2123

22-
const traceContextData = eventData.contexts?.trace?.data;
24+
const traceContextData = eventData.contexts?.trace?.data;
2325

24-
expect(traceContextData).toMatchObject({
25-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.browser',
26-
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
27-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
28-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
29-
});
26+
expect(traceContextData).toBeDefined();
3027

31-
expect(eventData.transaction).toBe('new name');
28+
expect(eventData.transaction).toBe('new name');
3229

33-
expect(eventData.contexts?.trace?.op).toBe('pageload');
34-
expect(eventData.spans?.length).toBeGreaterThan(0);
35-
expect(eventData.transaction_info?.source).toEqual('custom');
36-
});
30+
expect(traceContextData).toMatchObject({
31+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.browser',
32+
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
33+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
34+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
35+
});
36+
37+
expect(traceContextData!._sentry_span_name_set_by_user).toBeUndefined();
38+
39+
expect(eventData.contexts?.trace?.op).toBe('pageload');
40+
expect(eventData.spans?.length).toBeGreaterThan(0);
41+
expect(eventData.transaction_info?.source).toEqual('custom');
42+
},
43+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window._testBaseTimestamp = performance.timeOrigin / 1000;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [Sentry.browserTracingIntegration()],
9+
tracesSampleRate: 1,
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const activeSpan = Sentry.getActiveSpan();
2+
const rootSpan = activeSpan && Sentry.getRootSpan(activeSpan);
3+
4+
Sentry.updateSpanName(rootSpan, 'new name');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import {
5+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
6+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
7+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
8+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
9+
} from '@sentry/browser';
10+
import { sentryTest } from '../../../../utils/fixtures';
11+
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
12+
13+
sentryTest(
14+
'sets the source to custom when updating the transaction name with Sentry.updateSpanName',
15+
async ({ getLocalTestPath, page }) => {
16+
if (shouldSkipTracingTest()) {
17+
sentryTest.skip();
18+
}
19+
20+
const url = await getLocalTestPath({ testDir: __dirname });
21+
22+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
23+
24+
const traceContextData = eventData.contexts?.trace?.data;
25+
26+
expect(traceContextData).toBeDefined();
27+
28+
expect(traceContextData).toMatchObject({
29+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.browser',
30+
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
31+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
32+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
33+
});
34+
35+
expect(traceContextData!._sentry_span_name_set_by_user).toBeUndefined();
36+
37+
expect(eventData.transaction).toBe('new name');
38+
39+
expect(eventData.contexts?.trace?.op).toBe('pageload');
40+
expect(eventData.spans?.length).toBeGreaterThan(0);
41+
expect(eventData.transaction_info?.source).toEqual('custom');
42+
},
43+
);

dev-packages/browser-integration-tests/suites/tracing/dsc-txn-name-update/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,9 @@ async function captureErrorAndGetEnvelopeTraceHeader(page: Page): Promise<Partia
181181
await page.locator('#btnCaptureError').click();
182182

183183
const [, errorEnvelopeTraceHeader] = (await errorEventPromise)[0];
184+
185+
// @ts-expect-error - EventEnvelopeHeaders type in (types/envelope.ts) suggests that trace_id is optional,
186+
// which the DynamicSamplingContext type does not permit.
187+
// TODO(v9): We should adjust the EventEnvelopeHeaders type because the trace header always needs to have a trace_id
184188
return errorEnvelopeTraceHeader;
185189
}

0 commit comments

Comments
 (0)