Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bogdanoliinyk opened this issue Oct 29, 2021 · 11 comments · Fixed by #3625
Closed

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

bogdanoliinyk opened this issue Oct 29, 2021 · 11 comments · Fixed by #3625
Labels
bug Something isn't working priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect up-for-grabs Good for taking. Extra help will be provided by maintainers

Comments

@bogdanoliinyk
Copy link

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

Response end event will set Span status, that will lead to ended span issue.

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.

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

Related items

#2126

@bogdanoliinyk bogdanoliinyk added the bug Something isn't working label Oct 29, 2021
@dyladan
Copy link
Member

dyladan commented Oct 29, 2021

Looking at all the events in https://nodejs.org/api/http.html#httprequesturl-options-callback I think close might make sense but would like to get @vmarchaud opinion since he wrote the original version afaik.

@vmarchaud
Copy link
Member

vmarchaud commented Oct 29, 2021

I did rewrite the old plugin to the new instrumentation system but i didn't write the original code which i'm pretty sure was ported from opencensus.
From what i read here (https://nodejs.org/api/net.html#event-end), the end event indeed is fired when we can't read anymore from it but it can still be written to. Updating it to close looks fine to me.

EDIT: @bogdandrutu Do you want/have the time to make a PR to fix this ?

PS: thanks for the detailed bug report, really appreciated

@bogdanoliinyk
Copy link
Author

Hi guys, is there any news ?
@dyladan @vmarchaud @bogdandrutu

@dyladan
Copy link
Member

dyladan commented Nov 10, 2021

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

@vmarchaud
Copy link
Member

I think he meant to ask if you @bogdanoliinyk want to make a PR

Yep, github username suggestions sometimes betray me :)

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jan 17, 2022
@dyladan dyladan removed the stale label Jan 19, 2022
@vmarchaud vmarchaud removed their assignment Jan 20, 2022
@vmarchaud vmarchaud added the up-for-grabs Good for taking. Extra help will be provided by maintainers label Jan 20, 2022
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Mar 28, 2022
@github-actions
Copy link

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

@SimenB
Copy link
Contributor

SimenB commented Feb 21, 2023

I'm hitting this (I think), but I'm unable to consistently reproduce. In our case it happens with the https instrumentation when fetching data from GCS.

Looking at the code I don't really understand why _spanNotEnded does not prevent this from happening, tho. That's only checked for end, not setStatus

@SimenB
Copy link
Contributor

SimenB commented Feb 21, 2023

By adding some logging, I can see it's the same response.on('end', () => { call identified in the OP. Using 18.14.1, so still an issue in the latest LTS (at the time of writing)

@dyladan
Copy link
Member

dyladan commented Feb 22, 2023

I did rewrite the old plugin to the new instrumentation system but i didn't write the original code which i'm pretty sure was ported from opencensus. From what i read here (https://nodejs.org/api/net.html#event-end), the end event indeed is fired when we can't read anymore from it but it can still be written to. Updating it to close looks fine to me.

EDIT: @bogdandrutu Do you want/have the time to make a PR to fix this ?

PS: thanks for the detailed bug report, really appreciated

The docs listed here are for the net socket. Are these events emitted on the request/response from http? They're not listed in https://nodejs.org/api/http.html#httprequesturl-options-callback

nevermind i'm just confusing myself in the maze of docs

@pichlermarc pichlermarc added the priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect up-for-grabs Good for taking. Extra help will be provided by maintainers
Projects
None yet
5 participants