Skip to content

Commit 479aa11

Browse files
authored
ref: Update http instrumentation name for logging (#13716)
With this change, it is easier to figure out from logs if the correct or incorrect http instrumentation is added. Now, if you see e.g. this in the logs, if users have enabled logs (`debug: true` if not using `skipOpenTelemetrySetup: true`, else using native OTEL debug logs with e.g. `diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG)`): ```js @opentelemetry/instrumentation-http-sentry Applying instrumentation patch for nodejs core module on require hook { module: 'http' } @opentelemetry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' } ``` you can tell that that it has been double instrumenting this incorrectly. You should never see the `@opentelemetry/instrumentation-http` entry anymore, otherwise something is wrong there. This came out of getsentry/sentry-docs#11378, I looked into various ways to debug this but there is not really an API provided by OTEL that allows us to figure this out 😬
1 parent 03eb680 commit 479aa11

File tree

1 file changed

+14
-0
lines changed
  • packages/node/src/integrations

1 file changed

+14
-0
lines changed

packages/node/src/integrations/http.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ClientRequest, IncomingMessage, RequestOptions, ServerResponse } from 'node:http';
22
import type { Span } from '@opentelemetry/api';
3+
import { diag } from '@opentelemetry/api';
34
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
45
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
56

@@ -23,6 +24,8 @@ import { getRequestUrl } from '../utils/getRequestUrl';
2324

2425
const INTEGRATION_NAME = 'Http';
2526

27+
const INSTRUMENTATION_NAME = '@opentelemetry_sentry-patched/instrumentation-http';
28+
2629
interface HttpOptions {
2730
/**
2831
* Whether breadcrumbs should be recorded for requests.
@@ -195,6 +198,17 @@ export const instrumentHttp = Object.assign(
195198
},
196199
});
197200

201+
// We want to update the logger namespace so we can better identify what is happening here
202+
try {
203+
_httpInstrumentation['_diag'] = diag.createComponentLogger({
204+
namespace: INSTRUMENTATION_NAME,
205+
});
206+
207+
// @ts-expect-error This is marked as read-only, but we overwrite it anyhow
208+
_httpInstrumentation.instrumentationName = INSTRUMENTATION_NAME;
209+
} catch {
210+
// ignore errors here...
211+
}
198212
addOpenTelemetryInstrumentation(_httpInstrumentation);
199213
},
200214
{

0 commit comments

Comments
 (0)