Skip to content

fix(react-router): Conditionally add ReactRouterServer integration #16470

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

Merged
merged 4 commits into from
Jun 4, 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 @@ -50,6 +50,7 @@ const DEPENDENTS: Dependent[] = [
ignoreExports: [
// not supported in bun:
'NodeClient',
'NODE_VERSION',
'childProcessIntegration',
],
},
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export {
logger,
consoleLoggingIntegration,
wrapMcpServerWithSentry,
NODE_VERSION,
} from '@sentry/node';

export { init } from './server/sdk';
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export {
logger,
consoleLoggingIntegration,
wrapMcpServerWithSentry,
NODE_VERSION,
} from '@sentry/node';

export {
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export {
logger,
consoleLoggingIntegration,
wrapMcpServerWithSentry,
NODE_VERSION,
} from '@sentry/node';

export {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export { createGetModuleFromFilename } from './utils/module';
export { makeNodeTransport } from './transports';
export { NodeClient } from './sdk/client';
export { cron } from './cron';
export { NODE_VERSION } from './nodeVersion';

export type { NodeOptions } from './types';

Expand Down
17 changes: 11 additions & 6 deletions packages/react-router/src/server/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import type { EventProcessor, Integration } from '@sentry/core';
import { applySdkMetadata, getGlobalScope, logger, setTag } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk } from '@sentry/node';
import { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk, NODE_VERSION } from '@sentry/node';
import { DEBUG_BUILD } from '../common/debug-build';
import { SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE } from './instrumentation/util';
import { lowQualityTransactionsFilterIntegration } from './integration/lowQualityTransactionsFilterIntegration';
Expand All @@ -13,11 +13,16 @@ import { reactRouterServerIntegration } from './integration/reactRouterServer';
* @param options The options for the SDK.
*/
export function getDefaultReactRouterServerIntegrations(options: NodeOptions): Integration[] {
return [
...getNodeDefaultIntegrations(options),
lowQualityTransactionsFilterIntegration(options),
reactRouterServerIntegration(),
];
const integrations = [...getNodeDefaultIntegrations(options), lowQualityTransactionsFilterIntegration(options)];

if (
(NODE_VERSION.major === 20 && NODE_VERSION.minor < 19) || // https://nodejs.org/en/blog/release/v20.19.0
(NODE_VERSION.major === 22 && NODE_VERSION.minor < 12) // https://nodejs.org/en/blog/release/v22.12.0
) {
integrations.push(reactRouterServerIntegration());
}

return integrations;
}

/**
Expand Down
72 changes: 72 additions & 0 deletions packages/react-router/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,77 @@ describe('React Router server SDK', () => {

expect(filterIntegration).toBeDefined();
});

it('adds reactRouterServer integration for Node.js 20.18', () => {
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 20, minor: 18, patch: 0 });

reactRouterInit({
dsn: 'https://[email protected]/1337',
});

expect(nodeInit).toHaveBeenCalledTimes(1);
const initOptions = nodeInit.mock.calls[0]?.[0];
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];

const reactRouterServerIntegration = defaultIntegrations.find(
integration => integration.name === 'ReactRouterServer',
);

expect(reactRouterServerIntegration).toBeDefined();
});

it('adds reactRouterServer integration for Node.js 22.11', () => {
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 22, minor: 11, patch: 0 });

reactRouterInit({
dsn: 'https://[email protected]/1337',
});

expect(nodeInit).toHaveBeenCalledTimes(1);
const initOptions = nodeInit.mock.calls[0]?.[0];
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];

const reactRouterServerIntegration = defaultIntegrations.find(
integration => integration.name === 'ReactRouterServer',
);

expect(reactRouterServerIntegration).toBeDefined();
});

it('does not add reactRouterServer integration for Node.js 20.19', () => {
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 20, minor: 19, patch: 0 });

reactRouterInit({
dsn: 'https://[email protected]/1337',
});

expect(nodeInit).toHaveBeenCalledTimes(1);
const initOptions = nodeInit.mock.calls[0]?.[0];
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];

const reactRouterServerIntegration = defaultIntegrations.find(
integration => integration.name === 'ReactRouterServer',
);

expect(reactRouterServerIntegration).toBeUndefined();
});

it('does not add reactRouterServer integration for Node.js 22.12', () => {
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 22, minor: 12, patch: 0 });

reactRouterInit({
dsn: 'https://[email protected]/1337',
});

expect(nodeInit).toHaveBeenCalledTimes(1);
const initOptions = nodeInit.mock.calls[0]?.[0];
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];

const reactRouterServerIntegration = defaultIntegrations.find(
integration => integration.name === 'ReactRouterServer',
);

expect(reactRouterServerIntegration).toBeUndefined();
});
});
});
Loading