rpc,internal/telemetry: fix deferred spanEnd to capture errors via pointer#33772
rpc,internal/telemetry: fix deferred spanEnd to capture errors via pointer#33772fjl merged 2 commits intoethereum:masterfrom
Conversation
…can record errors and set status on spans
|
cc @lightclient |
MariusVanDerWijden
left a comment
There was a problem hiding this comment.
LGTM, but it kinda feels like we are fixing the API because people are using it incorrectly, but I guess its okay
if you ask me, I should have done it this way from the beginning. the options were to either make spanEnd() accept a pointer to an error or we need to do something ugly like defer func() { spanEnd(err) }(). I made this example in go playground to demonstrate: |
lightclient
left a comment
There was a problem hiding this comment.
LGTM.
Sorry this API with the pointer error really threw me when I was reviewing originally, so I pushed Jonny to remove. But in retrospect now, I see that you definitely want to be able to defer the spanEnd calls, so this is needed.
rpc/tracing_test.go
Outdated
| } | ||
| spans := exporter.GetSpans() | ||
|
|
||
| // Only the server span and runMethod span should have error status. |
There was a problem hiding this comment.
server span doesn't propagate error anymore, eh?
There was a problem hiding this comment.
good catch. i think that part of the comment needs to be removed.
f2efd27
Summary
The endSpan closure accepted error by value, meaning deferred calls like defer spanEnd(err) captured the error at defer-time (always nil), not at function-return time. This meant errors were never recorded on spans.
Changes