Skip to content

Commit

Permalink
ref: Update http instrumentation name for logging (#13716)
Browse files Browse the repository at this point in the history
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 😬
  • Loading branch information
mydea committed Sep 18, 2024
1 parent 03eb680 commit 479aa11
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ClientRequest, IncomingMessage, RequestOptions, ServerResponse } from 'node:http';
import type { Span } from '@opentelemetry/api';
import { diag } from '@opentelemetry/api';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';

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

const INTEGRATION_NAME = 'Http';

const INSTRUMENTATION_NAME = '@opentelemetry_sentry-patched/instrumentation-http';

interface HttpOptions {
/**
* Whether breadcrumbs should be recorded for requests.
Expand Down Expand Up @@ -195,6 +198,17 @@ export const instrumentHttp = Object.assign(
},
});

// We want to update the logger namespace so we can better identify what is happening here
try {
_httpInstrumentation['_diag'] = diag.createComponentLogger({
namespace: INSTRUMENTATION_NAME,
});

// @ts-expect-error This is marked as read-only, but we overwrite it anyhow
_httpInstrumentation.instrumentationName = INSTRUMENTATION_NAME;
} catch {
// ignore errors here...
}
addOpenTelemetryInstrumentation(_httpInstrumentation);
},
{
Expand Down

0 comments on commit 479aa11

Please sign in to comment.