Skip to content
Draft
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
@@ -0,0 +1,29 @@
import { expect, test } from '@playwright/test';
import { getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils';
import { isDevMode } from './isDevMode';

const NEXT_DEV_REQUEST_URL =
/^https:\/\/(telemetry\.nextjs\.org\/api\/v1\/record|registry\.npmjs\.org\/-\/package\/next\/dist-tags)$/;

test('Sends no spans for the telemetry and version check requests of `next dev`', async ({ page }) => {
test.skip(!isDevMode, '`next dev` sends these requests only in development');

// `next dev` sends its telemetry at startup, before any test runs, so the search starts at the first envelope.
const nextDevRequestSpanPromise = waitForStreamedSpan(
'nextjs-16',
span => {
const url = span.attributes['url.full']?.value;
return getSpanOp(span) === 'http.client' && typeof url === 'string' && NEXT_DEV_REQUEST_URL.test(url);
},
0,
);

// The dev overlay connects to the dev server, which then runs the version check.
await page.goto('/');

const result = await Promise.race([
nextDevRequestSpanPromise.then(span => span.name),
new Promise(resolve => setTimeout(() => resolve('timeout'), 5000)),
]);
expect(result).toBe('timeout');
});
12 changes: 11 additions & 1 deletion packages/nextjs/src/server/serverSpanHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
HTTP_ROUTE,
SENTRY_OP,
SENTRY_ORIGIN,
URL_FULL,
} from '@sentry/conventions/attributes';
import { MIDDLEWARE } from '@sentry/conventions/op';
import { HTTP_CLIENT, MIDDLEWARE } from '@sentry/conventions/op';
import type { Client, Options, Span } from '@sentry/core';
import {
getIsolationScope,
Expand Down Expand Up @@ -49,6 +50,15 @@ export const NEXTJS_SERVER_IGNORE_SPANS: NonNullable<Options['ignoreSpans']> = [
// Spans flagged via TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION
// (set in `dropMiddlewareTunnelRequests` during `spanStart`)
{ attributes: { [TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION]: true } },
// Requests that `next dev` sends on its own, for its telemetry and its version check. They are not part of a
// request, so with span streaming they would each become a root span.
{
op: HTTP_CLIENT,
attributes: {
[URL_FULL]:
/^https:\/\/(telemetry\.nextjs\.org\/api\/v1\/record|registry\.npmjs\.org\/-\/package\/next\/dist-tags)$/,
},
},
];

/**
Expand Down
Loading