Skip to content

Commit

Permalink
wip - still an error in backend error trace prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Sep 18, 2024
1 parent eb62e10 commit 8285c6f
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ const META_TAG_PARENT_SPAN_ID = '1234567890123456';
const META_TAG_BAGGAGE =
'sentry-trace_id=12345678901234567890123456789012,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod';

sentryTest('error on initial page has traceId from meta tag', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);

const errorEventPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>(
page,
undefined,
eventAndTraceHeaderRequestParser,
);

await page.locator('#errorBtn').click();
const [errorEvent, errorTraceHeader] = await errorEventPromise;

expect(errorEvent.type).toEqual(undefined);
expect(errorEvent.contexts?.trace).toEqual({
trace_id: META_TAG_TRACE_ID,
parent_span_id: META_TAG_PARENT_SPAN_ID,
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});

expect(errorTraceHeader).toEqual({
environment: 'prod',
public_key: 'public',
release: '1.0.0',
trace_id: META_TAG_TRACE_ID,
});
});

sentryTest('error has new traceId after navigation', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Sentry.init({
dsn: env.PUBLIC_E2E_TEST_DSN,
release: '1.0.0',
tunnel: `http://localhost:3031/`, // proxy server
beforeSend(event) {
console.log('beforeSend', event.contexts?.trace?.trace_id);
return event;
},
});

const myErrorHandler = ({ error, event }: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
beforeSend(event) {
console.log('beforeSend', event.contexts?.trace?.trace_id);
return event;
},
});

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

test.skip('errors on frontend and backend are connected by the same trace', async ({ page }) => {
// TODO once browserTracingIntegration is always added
const serverErrorPromise = waitForError('sveltekit-2-twp', evt => {
return evt.exception?.values?.[0].value === 'No search query provided';
});

await page.goto('/errors');

const clientError = await clientErrorPromise;
const serverError = await serverErrorPromise;

expect(clientError).toMatchObject({
contexts: {
trace: {
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
},
},
environment: 'qa',
exception: {
values: [
{
mechanism: {
handled: false,
type: 'onunhandledrejection',
},
stacktrace: expect.any(Object),
type: 'Error',
value: 'Client Error',
},
],
},
level: 'error',
platform: 'javascript',
release: '1.0.0',
timestamp: expect.any(Number),
transaction: '/errors',
});

expect(serverError).toMatchObject({
contexts: {
trace: {
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
},
},
environment: 'qa',
exception: {
values: [
{
mechanism: {
handled: true,
type: 'generic',
},
stacktrace: {},
},
],
},
platform: 'node',
timestamp: expect.any(Number),
transaction: 'GET /errors',
});

const clientTraceId = clientError.contexts?.trace?.trace_id;
const serverTraceId = serverError.contexts?.trace?.trace_id;

expect(clientTraceId).toBe(serverTraceId);
});

0 comments on commit 8285c6f

Please sign in to comment.