Fix span leak for inbound & outbound #922
Open
+209
−29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Span leak is a issue in observability tracing where a span is started, but is not finished. The span will not be sent to tracing backend if it is not finished, hence causing incomplete traces.
Internally at Uber, we fond incomplete traces from time to time due to span leak caused in tchannel-go library. In the happy path, the span is properly finished, but the span leak issue in tchannel-go happens in error path when a function early returns with error.
E.g.
tchannel-go/thrift/client.go
Lines 139 to 152 in af146f5
In above code snippet, A span is created within
c.startCall
, and is finished withinreadResponse
whenreader.Close()
is executed. If there is an error occurred inwriteArgs
, then the span leak happens.This PR is to fix the span leak issue.
Change Summary
2.1. Add
finishSpanWithOptions
method that allowsspan.Finish()
to be invoked many times inInboundCallResponse
.2.2 . Use
finishSpanWithOptions
indispatchInbound
to always try to finish a span after the handler is called.3.1. Add
finishSpanWithOptions
inOutboundCallResponse
similar to inbound case3.2. Use
finishSpanWithOptions
json, thrift and raw clients.Next
At Uber, YARPC (yarpc-go) is often used as a umbrella RPC framework with gRPC, TChannel and HTTP as transports. When YARPC is used with TChannel, the span leak issue does also exist.
With this PR, the span leak in inbound is expected to be fixed for YARPC as well, but for outbound, we need to add
defer call.Response().Done
here in yarpc-go after this PR is merged.