Skip to content

Commit 6fc1b69

Browse files
authored
test(browser-integration-tests): Ensure error after navigation has navigation traceId (#11601)
Adds a test to ensure that errors thrown after a navigation transaction finished are still associated with he trace started from the navigation.
1 parent 3d34752 commit 6fc1b69

File tree

1 file changed

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

1 file changed

+25
-0
lines changed

dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/navigation/test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,28 @@ sentryTest('should create a new trace on each navigation', async ({ getLocalTest
2424
expect(navigation2TraceId).toMatch(/^[0-9a-f]{32}$/);
2525
expect(navigation1TraceId).not.toEqual(navigation2TraceId);
2626
});
27+
28+
sentryTest('error after navigation has navigation traceId', async ({ getLocalTestPath, page }) => {
29+
if (shouldSkipTracingTest()) {
30+
sentryTest.skip();
31+
}
32+
33+
const url = await getLocalTestPath({ testDir: __dirname });
34+
35+
// ensure navigation transaction is finished
36+
await getFirstSentryEnvelopeRequest<Event>(page, url);
37+
38+
const navigationEvent1 = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
39+
expect(navigationEvent1.contexts?.trace?.op).toBe('navigation');
40+
41+
const navigationTraceId = navigationEvent1.contexts?.trace?.trace_id;
42+
expect(navigationTraceId).toMatch(/^[0-9a-f]{32}$/);
43+
44+
const [, errorEvent] = await Promise.all([
45+
page.locator('#errorBtn').click(),
46+
getFirstSentryEnvelopeRequest<Event>(page),
47+
]);
48+
49+
const errorTraceId = errorEvent.contexts?.trace?.trace_id;
50+
expect(errorTraceId).toBe(navigationTraceId);
51+
});

0 commit comments

Comments
 (0)