Skip to content

Commit

Permalink
only preload once
Browse files Browse the repository at this point in the history
Do not preload our custom sentry stuff
  • Loading branch information
mydea committed Sep 24, 2024
1 parent db46eb4 commit da5d2e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
42 changes: 24 additions & 18 deletions packages/node/src/integrations/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,34 @@ const instrumentSentryHttp = generateInstrumentOnce<{ breadcrumbs?: boolean }>(
},
);

const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConfig>(`${INTEGRATION_NAME}.otel`, config => {
const instrumentation = new HttpInstrumentation(config);

// We want to update the logger namespace so we can better identify what is happening here
try {
instrumentation['_diag'] = diag.createComponentLogger({
namespace: INSTRUMENTATION_NAME,
});
// @ts-expect-error We are writing a read-only property here...
instrumentation.instrumentationName = INSTRUMENTATION_NAME;
} catch {
// ignore errors here...
}

return instrumentation;
});
/**
* We only preload this one.
* If we preload both this and `instrumentSentryHttp`, it leads to weird issues with instrumentation.
*/
export const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConfig>(
`${INTEGRATION_NAME}.otel`,
config => {
const instrumentation = new HttpInstrumentation(config);

// We want to update the logger namespace so we can better identify what is happening here
try {
instrumentation['_diag'] = diag.createComponentLogger({
namespace: INSTRUMENTATION_NAME,
});
// @ts-expect-error We are writing a read-only property here...
instrumentation.instrumentationName = INSTRUMENTATION_NAME;
} catch {
// ignore errors here...
}

return instrumentation;
},
);

/**
* Instrument the HTTP module.
* This can only be instrumented once! If this called again later, we just update the options.
*/
export const instrumentHttp = Object.assign(
const instrumentHttp = Object.assign(
function (options: HttpOptions = {}) {
// This is the "regular" OTEL instrumentation that emits spans
if (options.spans !== false) {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/tracing/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Integration } from '@sentry/types';
import { instrumentHttp } from '../http';
import { instrumentOtelHttp } from '../http';

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

0 comments on commit da5d2e3

Please sign in to comment.