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

Add workaround for broken span propagation in streaming requests #2992

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

aleks-p
Copy link
Contributor

@aleks-p aleks-p commented Feb 8, 2024

Fixes #2923

Background:
The current instrumentation for the HTTP client is based on https://github.com/opentracing-contrib/go-stdlib. This works well enough for standard HTTP requests but does not support streaming. This instrumentation library "finishes" the opened trace spans only when the response body gets closed, which doesn't happen for streaming requests where the initial response has an empty body and is never read / closed. The result is below. Note the disconnected spans at the bottom and the empty "HTTP Client" spans:

span-propagation-before

Proper fix:
Switching to an instrumentation library that has proper support for streaming is the ideal way to address this. We will eventually switch to Open Telemetry which should offer a good path forward. This is a bigger change and in the interest of improving trace analysis I am proposing a workaround.

Workaround:
When we detect an empty response body we finish the span directly. This means that the span will report an incorrect time, but this is still an improvement over the current state where this span was completely removed which broke the span tree. In addition, I've merged the "HTTP Client" and "HTTP " spans into one for simplicity. All this is done in a new component inspired by https://github.com/opentracing-contrib/go-stdlib.

The result:
Screenshot 2024-02-07 at 15 55 40

@aleks-p aleks-p requested a review from a team as a code owner February 8, 2024 18:49
Copy link
Collaborator

@kolesnikovae kolesnikovae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you for fixing this! I like the workaround – I don't think there is a better way to to handle client spans. And I agree with your conclusions: we should migrate to OTel SDK

@aleks-p aleks-p merged commit 2fc05e8 into main Feb 9, 2024
19 checks passed
@aleks-p aleks-p deleted the fix/span-progapagion-for-streaming branch February 9, 2024 12:21
@cyriltovena
Copy link
Contributor

Thank you so much for doing this !

simonswine pushed a commit that referenced this pull request Feb 15, 2024
* Add workaround for broken span propagation in streaming requests

* Fix lint error

* Run go mod tidy
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken span context propagation for store gateway requests
3 participants