Skip to content

Commit da5d2e3

Browse files
committed
only preload once
Do not preload our custom sentry stuff
1 parent db46eb4 commit da5d2e3

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

packages/node/src/integrations/http/index.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,34 @@ const instrumentSentryHttp = generateInstrumentOnce<{ breadcrumbs?: boolean }>(
8888
},
8989
);
9090

91-
const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConfig>(`${INTEGRATION_NAME}.otel`, config => {
92-
const instrumentation = new HttpInstrumentation(config);
93-
94-
// We want to update the logger namespace so we can better identify what is happening here
95-
try {
96-
instrumentation['_diag'] = diag.createComponentLogger({
97-
namespace: INSTRUMENTATION_NAME,
98-
});
99-
// @ts-expect-error We are writing a read-only property here...
100-
instrumentation.instrumentationName = INSTRUMENTATION_NAME;
101-
} catch {
102-
// ignore errors here...
103-
}
104-
105-
return instrumentation;
106-
});
91+
/**
92+
* We only preload this one.
93+
* If we preload both this and `instrumentSentryHttp`, it leads to weird issues with instrumentation.
94+
*/
95+
export const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConfig>(
96+
`${INTEGRATION_NAME}.otel`,
97+
config => {
98+
const instrumentation = new HttpInstrumentation(config);
99+
100+
// We want to update the logger namespace so we can better identify what is happening here
101+
try {
102+
instrumentation['_diag'] = diag.createComponentLogger({
103+
namespace: INSTRUMENTATION_NAME,
104+
});
105+
// @ts-expect-error We are writing a read-only property here...
106+
instrumentation.instrumentationName = INSTRUMENTATION_NAME;
107+
} catch {
108+
// ignore errors here...
109+
}
110+
111+
return instrumentation;
112+
},
113+
);
107114

108115
/**
109116
* Instrument the HTTP module.
110-
* This can only be instrumented once! If this called again later, we just update the options.
111117
*/
112-
export const instrumentHttp = Object.assign(
118+
const instrumentHttp = Object.assign(
113119
function (options: HttpOptions = {}) {
114120
// This is the "regular" OTEL instrumentation that emits spans
115121
if (options.spans !== false) {

packages/node/src/integrations/tracing/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Integration } from '@sentry/types';
2-
import { instrumentHttp } from '../http';
2+
import { instrumentOtelHttp } from '../http';
33

44
import { amqplibIntegration, instrumentAmqplib } from './amqplib';
55
import { connectIntegration, instrumentConnect } from './connect';
@@ -54,7 +54,7 @@ export function getAutoPerformanceIntegrations(): Integration[] {
5454
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5555
export function getOpenTelemetryInstrumentationToPreload(): (((options?: any) => void) & { id: string })[] {
5656
return [
57-
instrumentHttp,
57+
instrumentOtelHttp,
5858
instrumentExpress,
5959
instrumentConnect,
6060
instrumentFastify,

0 commit comments

Comments
 (0)