#NestInstrumentation not working

11 messages · Page 1 of 1 (latest)

vivid mauve
#

hey i am trying to implement otel with nestjs using @opentelemetry/instrumentation-nestjs-core and i am getting this error:

i am initializing the tracing inside the bootstrap function, could someone explain what I am doing wrong?

umbral flower
#

Could you share a snippet of your code for the array instrumentations ?

#

If you are using https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node in that array, it automatically adds the nestjs-core one, so you are probably injecting it twice

#
ocean rivet
#

Hey hey, just bumping into this post.

I have a NestJS service, with instrumentation.ts looking like this:


const traceExporter = new OTLPTraceExporter({
  url: 'http://localhost:4318/v1/traces',
});

const spanProcessor = new BatchSpanProcessor(traceExporter);

const otelSDK = new NodeSDK({
  metricReader: new PrometheusExporter({
    port: 9100,
  }),

  spanProcessor,
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'authentication',
  }),
  contextManager: new AsyncLocalStorageContextManager(),
  instrumentations: [getNodeAutoInstrumentations()],
  textMapPropagator: new CompositePropagator({
    propagators: [
      new W3CTraceContextPropagator(),
      new W3CBaggagePropagator(),
      new B3Propagator(),
      new B3Propagator({
        injectEncoding: B3InjectEncoding.MULTI_HEADER,
      }),
    ],
  }),
});

export default otelSDK;

But I don't see any trace of NestJS instrumentation. Shouldn't it be part of getNodeAutoInstrumentations()?
The spans looks very Express specific

ocean rivet
ocean rivet
#

I found the issue, I need to import the otelSdk before any nest imports in main file 🙂

umbral flower
#

Hey, sorry, I've been off for a while 😂 I was waiting for an update from the OTEL JS core, yes

#

It doesn't help that I've been mostly coding in Go lol

ocean rivet
ocean rivet
#

@umbral flower Did you notice some issues with trace propagation in NestJS?
I can see on your example and one I created myself that the response headers are missing traceparent/traceId headers

I tested with NodeSDK, getNodeAutoInstrumentations and with/without the full blown of textMapPropagator (B3Propagator, W3CBaggagePropagator, W3CTraceContextPropagator)

Edit: Fetch is not instrumented