Skip to content

Commit 2fb3a76

Browse files
committed
add tests for trace context data
1 parent a2cb952 commit 2fb3a76

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

  • dev-packages/browser-integration-tests/suites/profiling

dev-packages/browser-integration-tests/suites/profiling/legacyMode/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ sentryTest('sends profile envelope in legacy mode', async ({ page, getLocalTestU
3636
const url = await getLocalTestUrl({ testDir: __dirname, responseHeaders: { 'Document-Policy': 'js-profiling' } });
3737

3838
const req = await waitForTransactionRequestOnUrl(page, url);
39+
const transactionEvent = properEnvelopeRequestParser<Event>(req, 0);
3940
const profileEvent = properEnvelopeRequestParser<Profile>(req, 1);
41+
4042
expect(profileEvent).toBeDefined();
4143

4244
const profile = profileEvent.profile;
@@ -54,4 +56,8 @@ sentryTest('sends profile envelope in legacy mode', async ({ page, getLocalTestU
5456
minSampleDurationMs: 20,
5557
isChunkFormat: false,
5658
});
59+
60+
// contexts.trace.data must include thread.id to identify which thread is associated with the transaction
61+
expect(transactionEvent?.contexts?.trace?.data?.['thread.id']).toBe('0');
62+
expect(transactionEvent?.contexts?.trace?.data?.['thread.name']).toBe('main');
5763
});

dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_multiple-chunks/test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { expect } from '@playwright/test';
2-
import type { ProfileChunkEnvelope } from '@sentry/core';
2+
import type { Event, ProfileChunkEnvelope } from '@sentry/core';
33
import { sentryTest } from '../../../utils/fixtures';
44
import {
55
countEnvelopes,
66
getMultipleSentryEnvelopeRequests,
7+
properEnvelopeRequestParser,
78
properFullEnvelopeRequestParser,
89
shouldSkipTracingTest,
10+
waitForTransactionRequestOnUrl,
911
} from '../../../utils/helpers';
1012
import { validateProfile, validateProfilePayloadMetadata } from '../test-utils';
1113

@@ -96,3 +98,25 @@ sentryTest(
9698
});
9799
},
98100
);
101+
102+
sentryTest(
103+
'attaches profiler_id and thread data to transaction events (trace mode)',
104+
async ({ page, getLocalTestUrl, browserName }) => {
105+
if (shouldSkipTracingTest() || browserName !== 'chromium') {
106+
sentryTest.skip();
107+
}
108+
109+
const url = await getLocalTestUrl({ testDir: __dirname, responseHeaders: { 'Document-Policy': 'js-profiling' } });
110+
111+
const req = await waitForTransactionRequestOnUrl(page, url);
112+
const transactionEvent = properEnvelopeRequestParser<Event>(req, 0) as any;
113+
114+
expect(transactionEvent?.type).toBe('transaction');
115+
116+
expect(transactionEvent?.contexts?.profile?.profiler_id).toMatch(/^[a-f\d]{32}$/);
117+
118+
// contexts.trace.data must include thread.id to identify which thread is associated with the transaction
119+
expect(transactionEvent?.contexts?.trace?.data?.['thread.id']).toBe('0');
120+
expect(transactionEvent?.contexts?.trace?.data?.['thread.name']).toBe('main');
121+
},
122+
);

dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_overlapping-spans/test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ sentryTest('attaches thread data to child spans (trace mode)', async ({ page, ge
8989

9090
const profilerId = rootSpan?.contexts?.profile?.profiler_id as string | undefined;
9191
expect(typeof profilerId).toBe('string');
92-
9392
expect(profilerId).toMatch(/^[a-f\d]{32}$/);
9493

94+
// contexts.trace.data must include thread.id to identify which thread is associated with the transaction
95+
expect(rootSpan?.contexts?.trace?.data?.['thread.id']).toBe('0');
96+
expect(rootSpan?.contexts?.trace?.data?.['thread.name']).toBe('main');
97+
9598
const spans = (rootSpan?.spans ?? []) as Array<{ data?: Record<string, unknown> }>;
9699
expect(spans.length).toBeGreaterThan(0);
97100
for (const span of spans) {

0 commit comments

Comments
 (0)