Next.js Discord

Discord Forum

How to manually instrument a span and have the trace be part of NextServer.getServerRequestHandler

Unanswered
House Sparrow posted this in #help-forum
Open in Discord
House SparrowOP
I am trying to figure out how to intrument a trace/span and have it associated with the other spans that Next.js emits by default.

I have tried to do
  await getTracer().trace("myHandler", async () => {
    res.statusCode = 200;
    await runMiddleware(req, res, customMiddleware);  
  })

But I only seem to get the one span called myHandler. In Jaeger's UI I see "invalid parent span IDs=984948d64e31a4c4;"

I tried to see what type of active span is live when I execute this code but code like
  const tracer = getTracer();
  console.log(tracer.getRootSpanAttributes());

returns undefined.

const activeScopeSpan = getTracer().getActiveScopeSpan(); does return something but it doesn't seem to get associated to the trace.

I am importing the tracer like so:
import { getTracer } from 'next/dist/server/lib/trace/tracer';

0 Replies