Skip to content

Commit 75870b8

Browse files
committed
conditionally instrument rr
1 parent 7153ce1 commit 75870b8

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

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: 8 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,13 @@ 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 (NODE_VERSION.major === 20 && NODE_VERSION.minor < 19) {
19+
integrations.push(reactRouterServerIntegration());
20+
}
21+
22+
return integrations;
2123
}
2224

2325
/**

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,41 @@ 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://[email protected]/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('does not add reactRouterServer integration for Node.js 20.19', () => {
94+
vi.spyOn(SentryNode, 'NODE_VERSION', 'get').mockReturnValue({ major: 20, minor: 19, patch: 0 });
95+
96+
reactRouterInit({
97+
dsn: 'https://[email protected]/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).toBeUndefined();
109+
});
74110
});
75111
});

0 commit comments

Comments
 (0)