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

Report correct length for trace span #435

Merged
merged 1 commit into from
May 6, 2024
Merged

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented May 2, 2024

The trace span in the TracingMiddleware should be the length it takes to return a response. Unfortunately because our Response body is a closure that will write the body at a later point and not the actual body we have not written the response body to the channel by the time we end the span in the TracingMiddleware.

To fix this I am manually starting and ending the span myself instead of using withSpan. The TracingMiddleware returns a response body that ends the span once the body has been written.

Another issue arises if I leave this as is though. Someone could drop the response body which was returned by the TracingMiddleware and the span.end would never be called. To get around this I have wrapped it in a small class which will call span.end() on deinit, if it hasn't already been called.

@adam-fowler adam-fowler requested a review from Joannis May 2, 2024 11:02
@adam-fowler
Copy link
Member Author

@slashmo You might be interested in this

Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

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

'been trying to think of a better solution - don't think there is one.

@adam-fowler adam-fowler merged commit 41b5ff6 into main May 6, 2024
5 checks passed
@adam-fowler adam-fowler deleted the tracing-span-length branch May 6, 2024 07:37
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.

2 participants