Skip to content

Commit 82694c9

Browse files
committed
wip - still an error in backend error trace prop
1 parent 9093a6d commit 82694c9

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ const META_TAG_PARENT_SPAN_ID = '1234567890123456';
1212
const META_TAG_BAGGAGE =
1313
'sentry-trace_id=12345678901234567890123456789012,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod';
1414

15+
sentryTest('error on initial page has traceId from meta tag', async ({ getLocalTestUrl, page }) => {
16+
if (shouldSkipTracingTest()) {
17+
sentryTest.skip();
18+
}
19+
20+
const url = await getLocalTestUrl({ testDir: __dirname });
21+
await page.goto(url);
22+
23+
const errorEventPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>(
24+
page,
25+
undefined,
26+
eventAndTraceHeaderRequestParser,
27+
);
28+
29+
await page.locator('#errorBtn').click();
30+
const [errorEvent, errorTraceHeader] = await errorEventPromise;
31+
32+
expect(errorEvent.type).toEqual(undefined);
33+
expect(errorEvent.contexts?.trace).toEqual({
34+
trace_id: META_TAG_TRACE_ID,
35+
parent_span_id: META_TAG_PARENT_SPAN_ID,
36+
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
37+
});
38+
39+
expect(errorTraceHeader).toEqual({
40+
environment: 'prod',
41+
public_key: 'public',
42+
release: '1.0.0',
43+
trace_id: META_TAG_TRACE_ID,
44+
});
45+
});
46+
1547
sentryTest('error has new traceId after navigation', async ({ getLocalTestUrl, page }) => {
1648
if (shouldSkipTracingTest()) {
1749
sentryTest.skip();

dev-packages/e2e-tests/test-applications/sveltekit-2-twp/src/hooks.client.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Sentry.init({
88
dsn: env.PUBLIC_E2E_TEST_DSN,
99
release: '1.0.0',
1010
tunnel: `http://localhost:3031/`, // proxy server
11+
beforeSend(event) {
12+
console.log('beforeSend', event.contexts?.trace?.trace_id);
13+
return event;
14+
},
1115
});
1216

1317
const myErrorHandler = ({ error, event }: any) => {

dev-packages/e2e-tests/test-applications/sveltekit-2-twp/src/hooks.server.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Sentry.init({
55
environment: 'qa', // dynamic sampling bias to keep transactions
66
dsn: E2E_TEST_DSN,
77
tunnel: `http://localhost:3031/`, // proxy server
8+
beforeSend(event) {
9+
console.log('beforeSend', event.contexts?.trace?.trace_id);
10+
return event;
11+
},
812
});
913

1014
// not logging anything to console to avoid noise in the test output
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
1-
import { test } from '@playwright/test';
1+
import { expect, test } from '@playwright/test';
2+
import { waitForError } from '@sentry-internal/test-utils';
3+
test('errors on frontend and backend are connected by the same trace', async ({ page }) => {
4+
const clientErrorPromise = waitForError('sveltekit-2-twp', evt => {
5+
return evt.exception?.values?.[0].value === 'Client Error';
6+
});
27

3-
test.skip('errors on frontend and backend are connected by the same trace', async ({ page }) => {
4-
// TODO once browserTracingIntegration is always added
8+
const serverErrorPromise = waitForError('sveltekit-2-twp', evt => {
9+
return evt.exception?.values?.[0].value === 'No search query provided';
10+
});
11+
12+
await page.goto('/errors');
13+
14+
const clientError = await clientErrorPromise;
15+
const serverError = await serverErrorPromise;
16+
17+
expect(clientError).toMatchObject({
18+
contexts: {
19+
trace: {
20+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
21+
span_id: expect.stringMatching(/[a-f0-9]{16}/),
22+
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
23+
},
24+
},
25+
environment: 'qa',
26+
exception: {
27+
values: [
28+
{
29+
mechanism: {
30+
handled: false,
31+
type: 'onunhandledrejection',
32+
},
33+
stacktrace: expect.any(Object),
34+
type: 'Error',
35+
value: 'Client Error',
36+
},
37+
],
38+
},
39+
level: 'error',
40+
platform: 'javascript',
41+
release: '1.0.0',
42+
timestamp: expect.any(Number),
43+
transaction: '/errors',
44+
});
45+
46+
expect(serverError).toMatchObject({
47+
contexts: {
48+
trace: {
49+
span_id: expect.stringMatching(/[a-f0-9]{16}/),
50+
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
51+
},
52+
},
53+
environment: 'qa',
54+
exception: {
55+
values: [
56+
{
57+
mechanism: {
58+
handled: true,
59+
type: 'generic',
60+
},
61+
stacktrace: {},
62+
},
63+
],
64+
},
65+
platform: 'node',
66+
timestamp: expect.any(Number),
67+
transaction: 'GET /errors',
68+
});
69+
70+
const clientTraceId = clientError.contexts?.trace?.trace_id;
71+
const serverTraceId = serverError.contexts?.trace?.trace_id;
72+
73+
expect(clientTraceId).toBe(serverTraceId);
574
});

0 commit comments

Comments
 (0)