Description
What version of OpenTelemetry are you using?
├── @opentelemetry/[email protected]
└─┬ @opentelemetry/[email protected]
├── @opentelemetry/[email protected] deduped
└── @opentelemetry/[email protected]
What version of Node are you using?
v18.19.1
What did you do?
Run the included express sample https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/express
What did you expect to see?
Child spans of the handler should be children under the request handler
span
What did you see instead?
Child spans created under the request handler fall under the top level server span (GET /run_test
), which I believe is created by the @opentelemetry/instrumentation-http
. I.e. they appear as siblings of the server span, next to middleware. This is really confusing because you can't tell if the span belongs to a middleware or the handler.
This screenshot demonstrates the problems
Additional context
It looks like the wrapped handler is not executed with the created span set in context:
Maybe this is intentional for 3-arg handlers that accept a next()
function, as the next layer would be running in the parent's span context. If that is considered incorrect, you could probably solve this by wrapping the next()
function to restore the parent context before executing the next layer to keep everything as siblings.