-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instrumentation-http: ESM instrumentation does not work on outgoing requests #5024
Comments
I also found a solution but it's really weird:
run
somehow requiring http in commonjs execution context fixed http-instrumentation hooks 🤷🏻♂️ |
Hi @constb, thanks for reaching out. This is really weird. I have tried to reproduce this locally and it behaves the exact same way for me as it does for you. I'll investigate further and will let you know what I find. |
Labelling as zipkin exporter bug (and, by proxy, sdk-node bug) as that's what's needed to surface this behavior. |
api.trace.getActiveSpan() returns undefined |
I'm still somewhat confused about this situation and have not had much time to look into this. I'll try to find someone who has more context to look into this. I suspect that importing the Zipkin exporter Here is a link to the reproducer that I created: https://github.com/pichlermarc/repro-5024 |
It's the load order issue. Zipkin requires http during the initial require https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts#L19 The way to solve this is to enable all instrumentations before any other part of the SDK is even required. Our node SDK package may need to be restructured even to make this happen, or the logic which enables all instrumentations maybe should be moved to the instrumentation package. |
I believe I understand what is happening. issue 1: whether
|
import * as http from 'http'; |
This change breaks that test:
--- a/experimental/packages/opentelemetry-instrumentation-http/test/integrations/esm.test.mjs
+++ b/experimental/packages/opentelemetry-instrumentation-http/test/integrations/esm.test.mjs
@@ -18,7 +18,7 @@
import * as assert from 'assert';
import * as fs from 'fs';
-import * as http from 'http';
+import http from 'http';
import * as https from 'https';
import { SpanKind } from '@opentelemetry/api';
I can work on a fix.
…ltExport from' style Fix instrumentation of `http.get`, `http.request`, `https.get`, and `https.request` when used from ESM code and imported via the `import defaultExport from 'http'` style. Fixes: open-telemetry#5024
What happened?
Steps to Reproduce
with node v20.17.0 or v18.20.4, install latest (0.53.0) opentelemetry sdk-node and instrumentation-http
enable ESM (set type: module in package.json)
a client makes a http request in context with trace id using
http.request()
Expected Result
server receives
traceparent
header and runs in a context with same traceId.Actual Result
server does not receive
traceparent
header and runs handler in a separate trace context.Additional Details
might be related to #5001
OpenTelemetry Setup Code
package.json
Relevant log output
The text was updated successfully, but these errors were encountered: