Can not execute the operation on ended Span opentelemetry-instrumentation-http

See original GitHub issue

What version of OpenTelemetry are you using?

0.18.0

What version of Node are you using?

tested 12 and 14

Please provide the code you used to setup the OpenTelemetry SDK

export class SDK {
    static setup(): void {
        diag.setLogger(new DiagConsoleLogger(), logLevel[config.loggerLevel] || DEFAULT_LOG_LEVEL);

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

        registerInstrumentations({
            instrumentations: [
                new HttpInstrumentation(),
                new GrpcInstrumentation()
            ],
            tracerProvider: provider
        });
    }
}

What did you do?

http request call

What did you expect to see?

Span created and closed with all data set

What did you see instead?

Can not execute the operation on ended Span

Additional context

That happens because request close event fired before the response end event.

socketCloseListener might emits close event before readable steam ended. image

Due to it, http instrumentation going to close Span https://github.com/open-telemetry/opentelemetry-js/blob/357ec92e95e03b4d2309c65ffb17d06105985628/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L344

Response end event will set Span status, that will lead to ended span issue. https://github.com/open-telemetry/opentelemetry-js/blob/357ec92e95e03b4d2309c65ffb17d06105985628/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L317

It might be tricky to reproduce, as I see it relay on response content size. In most cases, request close event is fired after response end. I was lucky to reproduce it. There is some logic in a stream implementation. image

Possible solution

Request end event might be changed with a close event. https://github.com/open-telemetry/opentelemetry-js/blob/357ec92e95e03b4d2309c65ffb17d06105985628/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L307

Response close event will be fired after request close by socketCloseListener implementation. Lines: 389 and 393 image

Related items

https://github.com/open-telemetry/opentelemetry-js/pull/2126

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dyladancommented, Nov 10, 2021

@vmarchaud pinged the wrong bogdan. I think he meant to ask if you @bogdanoliinyk want to make a PR

0reactions
github-actions[bot]commented, Apr 11, 2022

This issue was closed because it has been stale for 14 days with no activity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

open-telemetry/opentelemetry-node - Gitter
I don't know if this is related to my problem or not, but I ran across this: Can not execute the operation on...
Read more >
TroubleShooting OpenTelemetry NodeJS Tracing Issues
This guide is a checklist that will help you troubleshoot OpenTelemetry NodeJS tracing issues in your system.
Read more >
OpenTelemetry Tracing - Things you need to know before ...
Spans represent a single operation within a trace. ... The start and end time is managed by the OpenTelemetry SDK. Span span =...
Read more >
Instrumentation | OpenTelemetry
If a TracerProvider is not created, the OpenTelemetry APIs for tracing will ... to a Span so it carries more information about the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found