Skip to content

Commit 8657ded

Browse files
authored
fix(react-router): Conditionally add ReactRouterServer integration (#16470)
1 parent 08987dc commit 8657ded

File tree

7 files changed

+88
-6
lines changed

7 files changed

+88
-6
lines changed

dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const DEPENDENTS: Dependent[] = [
5050
ignoreExports: [
5151
// not supported in bun:
5252
'NodeClient',
53+
'NODE_VERSION',
5354
'childProcessIntegration',
5455
],
5556
},

packages/astro/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export {
134134
logger,
135135
consoleLoggingIntegration,
136136
wrapMcpServerWithSentry,
137+
NODE_VERSION,
137138
} from '@sentry/node';
138139

139140
export { init } from './server/sdk';

packages/aws-serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export {
120120
logger,
121121
consoleLoggingIntegration,
122122
wrapMcpServerWithSentry,
123+
NODE_VERSION,
123124
} from '@sentry/node';
124125

125126
export {

packages/google-cloud-serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export {
120120
logger,
121121
consoleLoggingIntegration,
122122
wrapMcpServerWithSentry,
123+
NODE_VERSION,
123124
} from '@sentry/node';
124125

125126
export {

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export { createGetModuleFromFilename } from './utils/module';
5454
export { makeNodeTransport } from './transports';
5555
export { NodeClient } from './sdk/client';
5656
export { cron } from './cron';
57+
export { NODE_VERSION } from './nodeVersion';
5758

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

packages/react-router/src/server/sdk.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
22
import type { EventProcessor, Integration } from '@sentry/core';
33
import { applySdkMetadata, getGlobalScope, logger, setTag } from '@sentry/core';
44
import type { NodeClient, NodeOptions } from '@sentry/node';
5-
import { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk } from '@sentry/node';
5+
import { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk, NODE_VERSION } from '@sentry/node';
66
import { DEBUG_BUILD } from '../common/debug-build';
77
import { SEMANTIC_ATTRIBUTE_SENTRY_OVERWRITE } from './instrumentation/util';
88
import { lowQualityTransactionsFilterIntegration } from './integration/lowQualityTransactionsFilterIntegration';
@@ -13,11 +13,16 @@ import { reactRouterServerIntegration } from './integration/reactRouterServer';
1313
* @param options The options for the SDK.
1414
*/
1515
export function getDefaultReactRouterServerIntegrations(options: NodeOptions): Integration[] {
16-
return [
17-
...getNodeDefaultIntegrations(options),
18-
lowQualityTransactionsFilterIntegration(options),
19-
reactRouterServerIntegration(),
20-
];
16+
const integrations = [...getNodeDefaultIntegrations(options), lowQualityTransactionsFilterIntegration(options)];
17+
18+
if (
19+
(NODE_VERSION.major === 20 && NODE_VERSION.minor < 19) || // https://nodejs.org/en/blog/release/v20.19.0
20+
(NODE_VERSION.major === 22 && NODE_VERSION.minor < 12) // https://nodejs.org/en/blog/release/v22.12.0
21+
) {
22+
integrations.push(reactRouterServerIntegration());
23+
}
24+
25+
return integrations;
2126
}
2227

2328
/**

packages/react-router/test/server/sdk.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,77 @@ describe('React Router server SDK', () => {
7171

7272
expect(filterIntegration).toBeDefined();
7373
});
74+
75+
it('adds reactRouterServer integration for Node.js 20.18', () => {
76+
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 20, minor: 18, patch: 0 });
77+
78+
reactRouterInit({
79+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
80+
});
81+
82+
expect(nodeInit).toHaveBeenCalledTimes(1);
83+
const initOptions = nodeInit.mock.calls[0]?.[0];
84+
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];
85+
86+
const reactRouterServerIntegration = defaultIntegrations.find(
87+
integration => integration.name === 'ReactRouterServer',
88+
);
89+
90+
expect(reactRouterServerIntegration).toBeDefined();
91+
});
92+
93+
it('adds reactRouterServer integration for Node.js 22.11', () => {
94+
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 22, minor: 11, patch: 0 });
95+
96+
reactRouterInit({
97+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
98+
});
99+
100+
expect(nodeInit).toHaveBeenCalledTimes(1);
101+
const initOptions = nodeInit.mock.calls[0]?.[0];
102+
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];
103+
104+
const reactRouterServerIntegration = defaultIntegrations.find(
105+
integration => integration.name === 'ReactRouterServer',
106+
);
107+
108+
expect(reactRouterServerIntegration).toBeDefined();
109+
});
110+
111+
it('does not add reactRouterServer integration for Node.js 20.19', () => {
112+
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 20, minor: 19, patch: 0 });
113+
114+
reactRouterInit({
115+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
116+
});
117+
118+
expect(nodeInit).toHaveBeenCalledTimes(1);
119+
const initOptions = nodeInit.mock.calls[0]?.[0];
120+
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];
121+
122+
const reactRouterServerIntegration = defaultIntegrations.find(
123+
integration => integration.name === 'ReactRouterServer',
124+
);
125+
126+
expect(reactRouterServerIntegration).toBeUndefined();
127+
});
128+
129+
it('does not add reactRouterServer integration for Node.js 22.12', () => {
130+
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 22, minor: 12, patch: 0 });
131+
132+
reactRouterInit({
133+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
134+
});
135+
136+
expect(nodeInit).toHaveBeenCalledTimes(1);
137+
const initOptions = nodeInit.mock.calls[0]?.[0];
138+
const defaultIntegrations = initOptions?.defaultIntegrations as Integration[];
139+
140+
const reactRouterServerIntegration = defaultIntegrations.find(
141+
integration => integration.name === 'ReactRouterServer',
142+
);
143+
144+
expect(reactRouterServerIntegration).toBeUndefined();
145+
});
74146
});
75147
});

0 commit comments

Comments
 (0)