Skip to content

Commit 532ac86

Browse files
chargomeclaude
andauthored
ref(react-router): Decouple ServerBuild capture from the OTel patch (#22492)
Moves `registerServerBuildGlobal()` out of the OTel instrumentation setup and registers the Vite-plugin ServerBuild capture independently in the integration's `setupOnce()`. This keeps the capture path working once the OTel instrumentation is removed in a follow-up. No behavior change — both ServerBuild capture paths (OTel proxy and Vite plugin) remain active. Fixes #22411 <br>Ref #22290 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f6f3330 commit 532ac86

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/react-router/src/server/integration/reactRouterServer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const instrumentReactRouter = generateInstrumentOnce(INTEGRATION_NAME, () => {
1414
export const instrumentReactRouterServer = Object.assign(
1515
(): void => {
1616
instrumentReactRouter();
17-
// Register global for Vite plugin ServerBuild capture
18-
registerServerBuildGlobal();
1917
},
2018
{ id: INTEGRATION_NAME },
2119
);
@@ -27,6 +25,10 @@ export const reactRouterServerIntegration = defineIntegration(() => {
2725
return {
2826
name: INTEGRATION_NAME,
2927
setupOnce() {
28+
// Register global for Vite plugin ServerBuild capture. Registered independently of the OTEL
29+
// patch so this capture path keeps working once the OTEL instrumentation is removed.
30+
registerServerBuildGlobal();
31+
3032
// Enable OTEL data-loader spans only on Node versions without the diagnostics_channel-based instrumentation API.
3133
if (
3234
(NODE_VERSION.major === 20 && NODE_VERSION.minor < 19) ||

packages/react-router/test/server/integration/reactRouterServer.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { HTTP_ROUTE } from '@sentry/conventions/attributes';
22
import type { Client, Event, EventType, StreamedSpanJSON } from '@sentry/core';
33
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
44
import { ReactRouterInstrumentation } from '../../../src/server/instrumentation/reactRouter';
5-
import { reactRouterServerIntegration } from '../../../src/server/integration/reactRouterServer';
5+
import {
6+
instrumentReactRouterServer,
7+
reactRouterServerIntegration,
8+
} from '../../../src/server/integration/reactRouterServer';
69
import * as serverBuild from '../../../src/server/serverBuild';
710
import * as serverGlobals from '../../../src/server/serverGlobals';
811

@@ -53,6 +56,14 @@ describe('reactRouterServerIntegration', () => {
5356
expect(registerServerBuildGlobalSpy).toHaveBeenCalledTimes(1);
5457
});
5558

59+
it('does not register the server build global from the OTEL instrumentation setup', () => {
60+
// Guards against re-coupling: the Vite-plugin capture registration must not depend on the
61+
// OTEL patch being installed, so it survives once the OTEL instrumentation is removed.
62+
instrumentReactRouterServer();
63+
64+
expect(registerServerBuildGlobalSpy).not.toHaveBeenCalled();
65+
});
66+
5667
it('enables OTEL data-loader span creation on Node 20.18', () => {
5768
mockNodeVersion.major = 20;
5869
mockNodeVersion.minor = 18;

0 commit comments

Comments
 (0)