Open
Description
I’m looking for best practices around span lifecycle management in Node.js SDK using OpenTelemetry.
We have a streaming API where we create a new span at the start of the stream. Currently, we end the span in the end
event handler. However, in some edge cases (e.g., unhandled errors or early termination), the end
event is not emitted. To ensure the span is always ended, we’ve also added span.end()
in the finish
event handler.
This approach works, but when the OpenTelemetry trace debugger is enabled, we get error Error: span is already ended
Is it safe to call span.end()
multiple times? I am able to handle this by adding a check (span as any).ended === false
but since ended property is not exposed, I am not sure if this is the right way ?
Metadata
Metadata
Assignees
Labels
No labels