Merged
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,4 +9,7 @@ const nextConfig = {

module.exports = withSentryConfig(nextConfig, {
silent: true,
release: {
name: 'foobar123',
},
});
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,4 +28,14 @@ test('Should propagate traces from server to client in pages router', async ({ p

expect(serverTransaction.contexts?.trace?.trace_id).toBeDefined();
expect(pageloadTransaction.contexts?.trace?.trace_id).toBe(serverTransaction.contexts?.trace?.trace_id);

await test.step('release was successfully injected on the serverside', () => {
// Release as defined in next.config.js
expect(serverTransaction.release).toBe('foobar123');
});

await test.step('release was successfully injected on the clientside', () => {
// Release as defined in next.config.js
expect(pageloadTransaction.release).toBe('foobar123');
});
});
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
_sentryRewriteFramesAssetPrefixPath: string;
_sentryAssetPrefix?: string;
_sentryBasePath?: string;
_sentryRelease?: string;
_experimentalThirdPartyOriginStackFrames?: string;
};

Expand All@@ -31,6 +32,7 @@ export function init(options: BrowserOptions): Client | undefined {
const opts = {
environment: getVercelEnv(true) || process.env.NODE_ENV,
defaultIntegrations: getDefaultIntegrations(options),
release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease,
...options,
} satisfies BrowserOptions;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,8 @@ function getFinalConfigObject(
incomingUserNextConfigObject: NextConfigObject,
userSentryOptions: SentryBuildOptions,
): NextConfigObject {
const releaseName = userSentryOptions.release?.name ?? getSentryRelease() ?? getGitRevision();

if (userSentryOptions?.tunnelRoute) {
if (incomingUserNextConfigObject.output === 'export') {
if (!showedExportModeTunnelWarning) {
Expand All@@ -64,7 +66,7 @@ function getFinalConfigObject(
}
}

setUpBuildTimeVariables(incomingUserNextConfigObject, userSentryOptions);
setUpBuildTimeVariables(incomingUserNextConfigObject, userSentryOptions, releaseName);

const nextJsVersion = getNextjsVersion();

Expand DownExpand Up@@ -207,8 +209,6 @@ function getFinalConfigObject(
);
}

const releaseName = userSentryOptions.release?.name ?? getSentryRelease() ?? getGitRevision();

return {
...incomingUserNextConfigObject,
webpack: constructWebpackConfigFunction(incomingUserNextConfigObject, userSentryOptions, releaseName),
Expand DownExpand Up@@ -291,8 +291,11 @@ function setUpTunnelRewriteRules(userNextConfig: NextConfigObject, tunnelPath: s
};
}

// TODO: For Turbopack we need to pass the release name here and pick it up in the SDK
function setUpBuildTimeVariables(userNextConfig: NextConfigObject, userSentryOptions: SentryBuildOptions): void {
function setUpBuildTimeVariables(
userNextConfig: NextConfigObject,
userSentryOptions: SentryBuildOptions,
releaseName: string | undefined,
): void {
const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || '';
const basePath = userNextConfig.basePath ?? '';
const rewritesTunnelPath =
Expand DownExpand Up@@ -335,6 +338,10 @@ function setUpBuildTimeVariables(userNextConfig: NextConfigObject, userSentryOpt
buildTimeVariables._experimentalThirdPartyOriginStackFrames = 'true';
}

if (releaseName) {
buildTimeVariables._sentryRelease = releaseName;
}

if (typeof userNextConfig.env === 'object') {
userNextConfig.env = { ...buildTimeVariables, ...userNextConfig.env };
} else if (userNextConfig.env === undefined) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@ export type EdgeOptions = VercelEdgeOptions;

const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
_sentryRewriteFramesDistDir?: string;
_sentryRelease?: string;
};

/** Inits the Sentry NextJS SDK on the Edge Runtime. */
Expand All@@ -48,6 +49,7 @@ export function init(options: VercelEdgeOptions = {}): void {

const opts = {
defaultIntegrations: customDefaultIntegrations,
release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease,
...options,
};

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ export { captureUnderscoreErrorException } from '../common/pages-router-instrume
const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
_sentryRewriteFramesDistDir?: string;
_sentryRewritesTunnelPath?: string;
_sentryRelease?: string;
};

/**
Expand DownExpand Up@@ -115,6 +116,7 @@ export function init(options: NodeOptions): NodeClient | undefined {

const opts: NodeOptions = {
environment: process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV,
release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease,
defaultIntegrations: customDefaultIntegrations,
...options,
};
Expand Down
Loading