Skip to content

Commit 088d041

Browse files
committed
test for realz
1 parent a1bdc49 commit 088d041

File tree

2 files changed

+87
-0
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/startNewTrace

2 files changed

+87
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const fetchBtn = document.getElementById('fetchBtn');
2+
fetchBtn.addEventListener('click', async () => {
3+
Sentry.startNewTrace();
4+
Sentry.startSpan({ op: 'ui.interaction.click', name: 'fetch click' }, async () => {
5+
await fetch('http://example.com');
6+
});
7+
});
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { expect } from '@playwright/test';
2+
import { sentryTest } from '../../../../utils/fixtures';
3+
import type { EventAndTraceHeader } from '../../../../utils/helpers';
4+
import {
5+
eventAndTraceHeaderRequestParser,
6+
getFirstSentryEnvelopeRequest,
7+
shouldSkipTracingTest,
8+
} from '../../../../utils/helpers';
9+
10+
sentryTest('should create a new trace if `startNewTrace` is called', async ({ getLocalTestUrl, page }) => {
11+
if (shouldSkipTracingTest()) {
12+
sentryTest.skip();
13+
}
14+
15+
const url = await getLocalTestUrl({ testDir: __dirname });
16+
17+
await page.route('http://example.com/**', route => {
18+
return route.fulfill({
19+
status: 200,
20+
contentType: 'application/json',
21+
body: JSON.stringify({}),
22+
});
23+
});
24+
25+
const [pageloadEvent, pageloadTraceHeaders] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>(
26+
page,
27+
url,
28+
eventAndTraceHeaderRequestParser,
29+
);
30+
31+
const pageloadTraceContext = pageloadEvent.contexts?.trace;
32+
33+
expect(pageloadEvent.type).toEqual('transaction');
34+
35+
expect(pageloadTraceContext).toMatchObject({
36+
op: 'pageload',
37+
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
38+
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
39+
});
40+
expect(pageloadTraceContext).not.toHaveProperty('parent_span_id');
41+
42+
expect(pageloadTraceHeaders).toEqual({
43+
environment: 'production',
44+
public_key: 'public',
45+
sample_rate: '1',
46+
sampled: 'true',
47+
trace_id: pageloadTraceContext?.trace_id,
48+
});
49+
50+
const customTransactionPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>(
51+
page,
52+
undefined,
53+
eventAndTraceHeaderRequestParser,
54+
);
55+
56+
await page.locator('#fetchBtn').click();
57+
58+
const [customTransactionEvent, customTransactionTraceHeaders] = await customTransactionPromise;
59+
60+
expect(customTransactionEvent.type).toEqual('transaction');
61+
expect(customTransactionEvent.transaction).toEqual('fetch click');
62+
63+
const customTransactionTraceContext = customTransactionEvent.contexts?.trace;
64+
expect(customTransactionTraceContext).toMatchObject({
65+
op: 'ui.interaction.click',
66+
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
67+
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
68+
});
69+
70+
expect(customTransactionTraceHeaders).toEqual({
71+
environment: 'production',
72+
public_key: 'public',
73+
sample_rate: '1',
74+
sampled: 'true',
75+
trace_id: customTransactionTraceContext?.trace_id,
76+
transaction: 'fetch click',
77+
});
78+
79+
expect(customTransactionTraceContext?.trace_id).not.toEqual(pageloadTraceContext?.trace_id);
80+
});

0 commit comments

Comments
 (0)