opentelemetry-js
opentelemetry-js copied to clipboard
Exporter shutdown method does not flush spans when wrapped with SimpleSpanProcessor
What happened?
Steps to Reproduce
When I end a span, then next call shutdown, the ended span is not flushed. If I wait for the next event loop tick, the span is flushed as-expected. See this example in the repo that demonstrates the problem and an example work-around.
parentSpan.end();
// give some time before it is closed
setTimeout(() => {
// flush and close the connection.
exporter.shutdown();
}, 2000);
Providing 0 to setTimeout also resolved the issue for me.
parentSpan.end();
setTimeout(() => {
exporter.shutdown();
}, 0);
Additional Details
See this other comment where the issue is shared.
Ideally, updating the example to below would work without the event loop wait.
parentSpan.end();
exporter.shutdown();
OpenTelemetry Setup Code
package.json
Relevant log output
Operating System and Version
No response
Runtime and Version
No response
Hi @chasestarr thanks for reaching out.
I see that the example there is misleading. Shutting down the exporter does not flush data from the SDK, it only shuts down the exporter itself. There is a NodeTracerProvider#shutdown() method that can be called that will also flush data, that's the one we want to show in the example.
I'll open a PR to update the example.