Skip to content

Commit 17030c5

Browse files
s1gr1dclaude
andcommitted
test(e2e): Use collectStreamedSpansUntilSegment helper in nitro-3 tests
Replace the hand-rolled accumulate-until-segment logic with the shared test-utils helper, as suggested in review. The helper already scopes the result to the matched trace, so the per-trace filtering falls away. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 8f7542e commit 17030c5

4 files changed

Lines changed: 16 additions & 42 deletions

File tree

dev-packages/e2e-tests/test-applications/nitro-3/tests/cache.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import { expect, test } from '@playwright/test';
2-
import { collectStreamedSpans } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils';
33

44
test.describe('Cache Instrumentation', () => {
55
const SEMANTIC_ATTRIBUTE_CACHE_KEY = 'cache.key';
66
const SEMANTIC_ATTRIBUTE_CACHE_HIT = 'cache.hit';
77

8-
// Streamed spans arrive across several envelopes (a child can flush before its segment),
9-
// so accumulate until the segment span has arrived and filter by its trace.
108
async function collectCacheSpans() {
11-
const spans = await collectStreamedSpans('nitro-3', spans =>
12-
spans.some(span => span.is_segment && span.attributes['url.path']?.value === '/api/test-cache'),
9+
const spans = await collectStreamedSpansUntilSegment(
10+
'nitro-3',
11+
span => span.attributes['url.path']?.value === '/api/test-cache',
1312
);
14-
const segmentSpan = spans.find(span => span.is_segment && span.attributes['url.path']?.value === '/api/test-cache');
1513

16-
return spans.filter(
17-
span => span.trace_id === segmentSpan?.trace_id && span.attributes['sentry.origin']?.value === 'auto.cache.nitro',
18-
);
14+
return spans.filter(span => span.attributes['sentry.origin']?.value === 'auto.cache.nitro');
1915
}
2016

2117
test('instruments cachedFunction and cachedHandler calls and creates spans with correct attributes', async ({

dev-packages/e2e-tests/test-applications/nitro-3/tests/span-nesting.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import { expect, test } from '@playwright/test';
2-
import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpansUntilSegment, getSpanOp } from '@sentry-internal/test-utils';
33

4-
// Streamed spans arrive across several envelopes (a child can flush before its segment),
5-
// so accumulate until the segment span has arrived and filter by its trace.
6-
async function collectNestingSpans() {
7-
const spans = await collectStreamedSpans('nitro-3', spans =>
8-
spans.some(span => span.is_segment && span.name === 'GET /api/test-nesting'),
9-
);
10-
const segmentSpan = spans.find(span => span.is_segment && span.name === 'GET /api/test-nesting');
11-
return spans.filter(span => span.trace_id === segmentSpan?.trace_id);
4+
function collectNestingSpans() {
5+
return collectStreamedSpansUntilSegment('nitro-3', 'GET /api/test-nesting');
126
}
137

148
test('Span nesting: all spans share the same trace_id', async ({ request }) => {
15-
const spansPromise = collectStreamedSpans('nitro-3', spans =>
16-
spans.some(span => span.is_segment && span.name === 'GET /api/test-nesting'),
17-
);
9+
const spansPromise = collectNestingSpans();
1810

1911
await request.get('/api/test-nesting');
2012

dev-packages/e2e-tests/test-applications/nitro-3/tests/storage-aliases.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { expect, test } from '@playwright/test';
2-
import { collectStreamedSpans } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils';
33

4-
// Streamed spans arrive across several envelopes (a child can flush before its segment),
5-
// so accumulate until the segment span has arrived and filter by its trace.
64
async function collectStorageSpans(route: string) {
7-
const spans = await collectStreamedSpans('nitro-3', spans =>
8-
spans.some(span => span.is_segment && span.attributes['url.path']?.value === route),
9-
);
10-
const segmentSpan = spans.find(span => span.is_segment && span.attributes['url.path']?.value === route);
5+
const spans = await collectStreamedSpansUntilSegment('nitro-3', span => span.attributes['url.path']?.value === route);
116

12-
return spans.filter(
13-
span => span.trace_id === segmentSpan?.trace_id && span.attributes['sentry.origin']?.value === 'auto.cache.nitro',
14-
);
7+
return spans.filter(span => span.attributes['sentry.origin']?.value === 'auto.cache.nitro');
158
}
169

1710
test.describe('Storage Instrumentation - Aliases', () => {

dev-packages/e2e-tests/test-applications/nitro-3/tests/storage.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { expect, test } from '@playwright/test';
2-
import { collectStreamedSpans } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils';
33

4-
// Streamed spans arrive across several envelopes (a child can flush before its segment),
5-
// so accumulate until the segment span has arrived and filter by its trace.
64
async function collectStorageSpans(route: string) {
7-
const spans = await collectStreamedSpans('nitro-3', spans =>
8-
spans.some(span => span.is_segment && span.attributes['url.path']?.value === route),
9-
);
10-
const segmentSpan = spans.find(span => span.is_segment && span.attributes['url.path']?.value === route);
11-
12-
return spans.filter(
13-
span => span.trace_id === segmentSpan?.trace_id && span.attributes['sentry.origin']?.value === 'auto.cache.nitro',
14-
);
5+
const spans = await collectStreamedSpansUntilSegment('nitro-3', span => span.attributes['url.path']?.value === route);
6+
7+
return spans.filter(span => span.attributes['sentry.origin']?.value === 'auto.cache.nitro');
158
}
169

1710
test.describe('Storage Instrumentation', () => {

0 commit comments

Comments
 (0)