Skip to content

Commit 52e26df

Browse files
chargomeclaude
andauthored
test(e2e): Tell the two nestjs-basic interceptor specs traces apart (#24211)
Both specs of each interceptor route produce a trace with the same segment name, and `collectStreamedSpans` resolves with any trace satisfying the predicate, so a leftover trace from the preceding spec could satisfy it instead. Each request now carries a `spec` query marker, which lands in `url.query` and not in the span name. This was meant to ship with #24099 but landed on the branch after it merged. Ref: #23801 Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent aa191b1 commit 52e26df

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

  • dev-packages/e2e-tests/test-applications/nestjs-basic/tests

‎dev-packages/e2e-tests/test-applications/nestjs-basic/tests/spans.test.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ test('Sends an app_creation span', async () => {
105105
});
106106
});
107107

108+
/**
109+
* Two specs hit each interceptor route, and `collectStreamedSpans` resolves with any trace that
110+
* satisfies the predicate - including one left over from the spec before. Each request therefore
111+
* carries a marker that tells its own trace apart. `url.query` keeps it out of the span name.
112+
*/
113+
function collectSpansOfRequest(segmentName: string, spec: string): Promise<SerializedStreamedSpan[]> {
114+
return collectStreamedSpansUntilSegment(
115+
APP_NAME,
116+
span => span.name === segmentName && span.attributes['url.query']?.value === `spec=${spec}`,
117+
);
118+
}
119+
108120
test('Sends streamed spans for an API route', async ({ baseURL }) => {
109121
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /test-transaction');
110122

@@ -292,9 +304,9 @@ test('API route trace includes nest pipe span for invalid request', async ({ bas
292304
test('API route trace includes nest interceptor spans before route execution. Spans created in and after interceptor are nested correctly', async ({
293305
baseURL,
294306
}) => {
295-
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /test-interceptor-instrumentation');
307+
const spansPromise = collectSpansOfRequest('GET /test-interceptor-instrumentation', 'interceptor-before-route');
296308

297-
const response = await fetch(`${baseURL}/test-interceptor-instrumentation`);
309+
const response = await fetch(`${baseURL}/test-interceptor-instrumentation?spec=interceptor-before-route`);
298310
expect(response.status).toBe(200);
299311

300312
const spans = await spansPromise;
@@ -328,9 +340,9 @@ test('API route trace includes nest interceptor spans before route execution. Sp
328340
test('API route trace includes exactly one nest interceptor span after route execution. Spans created in controller and in interceptor are nested correctly', async ({
329341
baseURL,
330342
}) => {
331-
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /test-interceptor-instrumentation');
343+
const spansPromise = collectSpansOfRequest('GET /test-interceptor-instrumentation', 'interceptor-after-route');
332344

333-
const response = await fetch(`${baseURL}/test-interceptor-instrumentation`);
345+
const response = await fetch(`${baseURL}/test-interceptor-instrumentation?spec=interceptor-after-route`);
334346
expect(response.status).toBe(200);
335347

336348
const spans = await spansPromise;
@@ -356,9 +368,12 @@ test('API route trace includes exactly one nest interceptor span after route exe
356368
test('API route trace includes nest async interceptor spans before route execution. Spans created in and after async interceptor are nested correctly', async ({
357369
baseURL,
358370
}) => {
359-
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /test-async-interceptor-instrumentation');
371+
const spansPromise = collectSpansOfRequest(
372+
'GET /test-async-interceptor-instrumentation',
373+
'async-interceptor-before-route',
374+
);
360375

361-
const response = await fetch(`${baseURL}/test-async-interceptor-instrumentation`);
376+
const response = await fetch(`${baseURL}/test-async-interceptor-instrumentation?spec=async-interceptor-before-route`);
362377
expect(response.status).toBe(200);
363378

364379
const spans = await spansPromise;
@@ -384,9 +399,12 @@ test('API route trace includes nest async interceptor spans before route executi
384399
test('API route trace includes exactly one nest async interceptor span after route execution. Spans created in controller and in async interceptor are nested correctly', async ({
385400
baseURL,
386401
}) => {
387-
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /test-async-interceptor-instrumentation');
402+
const spansPromise = collectSpansOfRequest(
403+
'GET /test-async-interceptor-instrumentation',
404+
'async-interceptor-after-route',
405+
);
388406

389-
const response = await fetch(`${baseURL}/test-async-interceptor-instrumentation`);
407+
const response = await fetch(`${baseURL}/test-async-interceptor-instrumentation?spec=async-interceptor-after-route`);
390408
expect(response.status).toBe(200);
391409

392410
const spans = await spansPromise;

0 commit comments

Comments
 (0)