Skip to content

HttpInstrumentation does not create outgoing request span for http.get in ESM #4857

Closed
@Lms24

Description

@Lms24

What happened?

Steps to Reproduce

I created a minimal reproduction that demonstrates the bug in this repository: https://github.com/Lms24/otel-node-http-get-esm-reproduction

To reproduce the bug, follow these instructions:

  1. run npm install
  2. run npm run start:cjs to observe http.get call span being printed to console
  3. run npm run start:esm to observe http.get call span NOT being printed to console
  4. uncomment http.request call in both, esm and cjs app.js files to observe that both start a span.

Expected Result

When making http.get calls from node:http(s), for example

import * as http from "node:http";
http.get("http://example.com", {...});

HttpInstrumentation should create a span for the outgoing request when the app is running in ESM mode, just like it does in CJS mode.

Actual Result

No span is created for http.get calls in ESM.

Additional Details

In ESM, http.request calls create a span (see commented out call in my reproduction repo).

In CJS, both, http.get and http.request calls create spans. So as far as I can tell, for CJS, everything works correctly.

OpenTelemetry Setup Code

import * as opentelemetry from "@opentelemetry/sdk-node";
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
import moduleModule from "module";

const sdk = new opentelemetry.NodeSDK({
  traceExporter: new ConsoleSpanExporter(),
  instrumentations: [new HttpInstrumentation()],
});

moduleModule.register(
  "@opentelemetry/instrumentation/hook.mjs",
  import.meta.url
);

sdk.start();

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);

package.json

{
  "name": "otel-http-get",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start:cjs": "node --require ./cjs/instrument.js ./cjs/app.js",
    "start:esm": "node --import ./esm/instrument.mjs ./esm/app.mjs"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/instrumentation-http": "^0.52.1",
    "@opentelemetry/sdk-metrics": "^1.25.1",
    "@opentelemetry/sdk-node": "^0.52.1",
    "@opentelemetry/sdk-trace-node": "^1.25.1"
  }
}

Relevant log output

No log output from ConsoleSpanExporter because no span is created/emitted.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghas:reproducerThis bug/feature has a minimal reproducer providedpriority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions