Skip to content
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

Fastify instrumentation not working for named import for ESM #2253

Open
andreiborza opened this issue Jun 4, 2024 · 0 comments
Open

Fastify instrumentation not working for named import for ESM #2253

andreiborza opened this issue Jun 4, 2024 · 0 comments
Assignees
Labels
bug Something isn't working priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Comments

@andreiborza
Copy link

What version of OpenTelemetry are you using?

@opentelemetry/instrumentation-fastify 0.36.1

What version of Node are you using?

v18.19

What did you do?

opentelemetry.mjs:

import { register } from 'module';
register('@opentelemetry/instrumentation/hook.mjs', import.meta.url);

import {
  diag,
  DiagConsoleLogger,
  DiagLogLevel,
} from '@opentelemetry/api';

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

import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
import { NodeSDK, metrics } from '@opentelemetry/sdk-node';

const sdk = new NodeSDK({
  instrumentations: [
    HttpInstrumentation,
    new FastifyInstrumentation(),
  ],
  traceExporter: new OTLPTraceExporter(),
  metricReader: new metrics.PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter(),
  }),
});

process.on('beforeExit', async () => {
  await sdk.shutdown();
});

sdk.start();

app.mjs with named import:

import { fastify } from "fastify";
import { isWrapped} from "@opentelemetry/core";

const app = fastify()
app.listen({ port: 3000 })

console.log(isWrapped(app.addHook)) 
// -> false

app.mjs with default import:

import fastify from "fastify";
import { isWrapped} from "@opentelemetry/core";

const app = fastify()
app.listen({ port: 3000 })

console.log(isWrapped(app.addHook))
// -> true

ran with
node --import ./opentelemetry.mjs app.mjs

What did you expect to see?

The named export of fastify to be correctly instrumented (isWrapped(app.addHook) to return true), like the second instance of app.mjs with the default import of fastify.

What did you see instead?

fastify was not instrumented correctly, isWrapped(app.addHook) returned false.

Additional context

First came up in our SDK: getsentry/sentry-javascript#12119

@andreiborza andreiborza added the bug Something isn't working label Jun 4, 2024
@pichlermarc pichlermarc self-assigned this Jun 26, 2024
@pichlermarc pichlermarc added the priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect label Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect
Projects
None yet
Development

No branches or pull requests

2 participants