Skip to content

Pino instrumentation not working when using ES modules #2838

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

Open
ayoisaiah opened this issue May 20, 2025 · 1 comment
Open

Pino instrumentation not working when using ES modules #2838

ayoisaiah opened this issue May 20, 2025 · 1 comment

Comments

@ayoisaiah
Copy link

ayoisaiah commented May 20, 2025

What version of OpenTelemetry are you using?

What version of Node are you using?

Node.js 24

What did you do?

When I converted the example code in the @opentelemetry/instrumentation-pino package to ES module syntax, the instrumentation stopped working. But it works as expected when run using the original CommonJS format.

import { NodeSDK, tracing, logs, api } from "@opentelemetry/sdk-node";
import { PinoInstrumentation } from "@opentelemetry/instrumentation-pino";
import pino from "pino";

const sdk = new NodeSDK({
  spanProcessor: new tracing.SimpleSpanProcessor(
    new tracing.ConsoleSpanExporter(),
  ),
  logRecordProcessor: new logs.SimpleLogRecordProcessor(
    new logs.ConsoleLogRecordExporter(),
  ),
  instrumentations: [
    new PinoInstrumentation({
      // See below for Pino instrumentation options.
    }),
  ],
});
sdk.start();

const logger = pino();

logger.info("hi");
// 1. Log records will be sent to the SDK-registered log record processor, if any.
//    This is called "log sending".

const tracer = api.trace.getTracer("example");
tracer.startActiveSpan("manual-span", (span) => {
  logger.info("in a span");
  // 2. Fields identifying the current span will be added to log records:
  //    {"level":30,...,"msg":"in a span","trace_id":"d61b4e4af1032e0aae279d12f3ab0159","span_id":"d140da862204f2a2","trace_flags":"01"}
  //    This feature is called "log correlation".
});

What did you expect to see?

The trace_id and span_id in the logs, alongside their OTLP representation as is the case with the original CommonJS format:

{"level":30,"time":1747735809772,"pid":334794,"hostname":"Falcon","trace_id":"78765079501acd3516ae627d6c311455","span_id":"f67c2314b2cd42db","trace_flags":"01","msg":"in a span"}
{
  resource: {
    attributes: {
      'host.name': 'Falcon',
      'host.arch': 'amd64',
      'host.id': 'b8c8a123fc8c4017a34ac35736984212',
      'process.pid': 334794,
      'process.executable.name': '/home/ayo/.local/share/mise/installs/node/24.0.0/bin/node',
      'process.executable.path': '/home/ayo/.local/share/mise/installs/node/24.0.0/bin/node',
      'process.command_args': [
        '/home/ayo/.local/share/mise/installs/node/24.0.0/bin/node',
        '/home/ayo/dev/dash0/demo/pinojs-logging/pino.js'
      ],
      'process.runtime.version': '24.0.0',
      'process.runtime.name': 'nodejs',
      'process.runtime.description': 'Node.js',
      'process.command': '/home/ayo/dev/dash0/demo/pinojs-logging/pino.js',
      'process.owner': 'ayo',
      'service.name': 'unknown_service:/home/ayo/.local/share/mise/installs/node/24.0.0/bin/node',
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '2.0.1'
    }
  },
  instrumentationScope: {
    name: '@opentelemetry/instrumentation-pino',
    version: '0.48.0',
    schemaUrl: undefined
  },
  timestamp: 1747735809772000,
  traceId: '78765079501acd3516ae627d6c311455',
  spanId: 'f67c2314b2cd42db',
  traceFlags: 1,
  severityText: 'info',
  severityNumber: 9,
  body: 'in a span',
  attributes: {}
}

What did you see instead?

No trace_id or span_id. The OTLP console representation was also absent:

{"level":30,"time":1747735419210,"pid":334524,"hostname":"Falcon","msg":"in a span"}

Additional context

@ayoisaiah ayoisaiah added the bug Something isn't working label May 20, 2025
@pichlermarc
Copy link
Member

Hi @ayoisaiah, thanks for reaching out. Could it be that the loader is not registered that's required for ESM instrumentation?
For more info, please see https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants