Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): Record turbopack as tag #15928

Merged
merged 6 commits into from
Apr 2, 2025
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 @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/node": "^18.19.1",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"next": "15.3.0-canary.8",
"next": "15.3.0-canary.26",
"react": "rc",
"react-dom": "rc",
"typescript": "~5.0.0"
Expand Down
11 changes: 11 additions & 0 deletions packages/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Client, EventProcessor, Integration } from '@sentry/core';
import { getGlobalScope } from '@sentry/core';
import { GLOBAL_OBJ, addEventProcessor, applySdkMetadata } from '@sentry/core';
import type { BrowserOptions } from '@sentry/react';
import { getDefaultIntegrations as getReactDefaultIntegrations, init as reactInit } from '@sentry/react';
Expand Down Expand Up @@ -61,6 +62,16 @@ export function init(options: BrowserOptions): Client | undefined {
addEventProcessor(devErrorSymbolicationEventProcessor);
}

try {
// @ts-expect-error `process.turbopack` is a magic string that will be replaced by Next.js
if (process.turbopack) {
getGlobalScope().setTag('turbopack', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm are we sure we want to set a tag over a context here? Is there value in making this searchable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say yes - for now. Sigrid is working on some stuff in the protocol that will allow us to send stuff like this in a more structured way. It will be invaluable for us in the transitionary period when turbopack ships and we have to debug potential issues with the SDK.

}
} catch (e) {
// Noop
// The statement above can throw because process is not defined on the client
}

return client;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/nextjs/src/edge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
applySdkMetadata,
getGlobalScope,
getRootSpan,
registerSpanErrorInstrumentation,
spanToJSON,
Expand Down Expand Up @@ -90,6 +91,16 @@ export function init(options: VercelEdgeOptions = {}): void {
vercelWaitUntil(flushSafelyWithTimeout());
}
});

try {
// @ts-expect-error `process.turbopack` is a magic string that will be replaced by Next.js
if (process.turbopack) {
getGlobalScope().setTag('turbopack', true);
}
} catch {
// Noop
// The statement above can throw because process is not defined on the client
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ export function init(options: NodeOptions): NodeClient | undefined {
getGlobalScope().addEventProcessor(devErrorSymbolicationEventProcessor);
}

try {
// @ts-expect-error `process.turbopack` is a magic string that will be replaced by Next.js
if (process.turbopack) {
getGlobalScope().setTag('turbopack', true);
}
} catch {
// Noop
// The statement above can throw because process is not defined on the client
}

DEBUG_BUILD && logger.log('SDK successfully initialized');

return client;
Expand Down
Loading