Skip to content

Can't get active span in Express instrumentation. #2617

Closed
@ScottChapman

Description

@ScottChapman

I followed the very simple instrumentation instructions:

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    // Express instrumentation expects HTTP layer to be instrumented
    new HttpInstrumentation(),
    new ExpressInstrumentation(),
  ],
});

And in my express code I am trying to get the active span:

app.get("/api/results/:id", async (req, res) => {
  const localSpan = opentelemetry.trace.getActiveSpan();

But it ends up being null??

Metadata

Metadata

Labels

bugSomething isn't workingpkg:instrumentation-expresspriority: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