Skip to content

Commit

Permalink
ref: Update http instrumentation name for logging
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 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.
  • Loading branch information
mydea committed Sep 18, 2024
1 parent e1783a6 commit 062de4d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 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 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/instrumentation-http-sentry';

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 062de4d

Please sign in to comment.