Skip to content
Open
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
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test';
import type { SerializedStreamedSpan } from '@sentry-internal/test-utils';
import {
collectStreamedSpansUntilSegment,
getSpanOp,
Expand Down Expand Up @@ -72,18 +73,25 @@ test.describe('server - instrumentation API error capture', () => {
return errorEvent.exception?.values?.[0]?.value === 'Loader error for testing';
});

const spanPromise = waitForStreamedSpan(APP_NAME, span => {
return span.name === 'GET /performance/error-loader' && span.is_segment;
// Streamed spans flush later than errors, so a segment span from an earlier test hitting the same
// route can still be arriving here. Collect them and look for the one in the error's trace.
const segmentSpans: SerializedStreamedSpan[] = [];
void waitForStreamedSpan(APP_NAME, span => {
if (span.name === 'GET /performance/error-loader' && span.is_segment) {
segmentSpans.push(span);
}
return false;
});

await page.goto(`/performance/error-loader`).catch(() => {
// Expected to fail due to loader error
});

const [error, span] = await Promise.all([errorPromise, spanPromise]);
const error = await errorPromise;
const traceId = error.contexts?.trace?.trace_id;
expect(traceId).toMatch(/^[a-f0-9]{32}$/);

// Error and segment span should have the same trace_id
expect(error.contexts?.trace?.trace_id).toBe(span.trace_id);
await expect.poll(() => segmentSpans.some(span => span.trace_id === traceId)).toBe(true);
});

// Skipped in dev: the action error is sometimes captured via the client instrumentation path
Expand Down
Loading