Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ console.warn = new Proxy(console.warn, {
});

Sentry.init({
traceLifecycle: 'static',
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
integrations: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
import { waitForError, collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils';

test('Sends correct error event', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-fastify-3', event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123';
});

const transactionEventPromise = waitForTransaction('node-fastify-3', event => {
return event.transaction === 'GET /test-exception/:id';
});
const segmentEventPromise = collectStreamedSpansUntilSegment('node-fastify-3', 'GET /test-exception/:id');

await fetch(`${baseURL}/test-exception/123`);

const errorEvent = await errorEventPromise;
const transactionEvent = await transactionEventPromise;
const segmentEventSpans = await segmentEventPromise;
const segmentEvent = segmentEventSpans.find(
segment => segment.is_segment && segment.name === 'GET /test-exception/:id',
)!;

expect(errorEvent.exception?.values).toHaveLength(1);
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
Expand All @@ -33,13 +34,18 @@ test('Sends correct error event', async ({ baseURL }) => {
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
});

// The error is attached to the same trace as the request transaction, and to a
// span that belongs to that transaction (its root span or one of its children).
const transactionTrace = transactionEvent.contexts?.trace;
expect(errorEvent.contexts?.trace?.trace_id).toBe(transactionTrace?.trace_id);
// The error is attached to the same trace as the request segment, and to a
// span in that segment.
const segmentTrace = segmentEvent;
expect(errorEvent.contexts?.trace?.trace_id).toBe(segmentTrace?.trace_id);

const transactionSpanIds = [transactionTrace?.span_id, ...(transactionEvent.spans ?? []).map(span => span.span_id)];
expect(transactionSpanIds).toContain(errorEvent.contexts?.trace?.span_id);
const segmentSpanIds = [
segmentTrace?.span_id,
...segmentEventSpans
.filter(span => !span.is_segment && span.attributes['sentry.segment.id']?.value === segmentEvent.span_id)
.map(span => span.span_id),
];
expect(segmentSpanIds).toContain(errorEvent.contexts?.trace?.span_id);
});

test('Does not send error when shouldHandleError returns false', async ({ baseURL }) => {
Expand Down
Loading
Loading