Skip to content

rpc,internal/telemetry: fix deferred spanEnd to capture errors via pointer#33772

Merged
fjl merged 2 commits intoethereum:masterfrom
jrhea:otel-fix-span-error
Feb 14, 2026
Merged

rpc,internal/telemetry: fix deferred spanEnd to capture errors via pointer#33772
fjl merged 2 commits intoethereum:masterfrom
jrhea:otel-fix-span-error

Conversation

@jrhea
Copy link
Copy Markdown
Contributor

@jrhea jrhea commented Feb 5, 2026

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

  • Changed endSpan to accept *error
  • Updated all call sites in rpc/handler.go to pass error pointers, and adjusted handleCall to avoid propagating child-span errors to the parent
  • Added TestTracingHTTPErrorRecording to verify that errors from RPC methods are properly recorded on the rpc.runMethod span

@jrhea jrhea requested a review from fjl as a code owner February 5, 2026 18:33
@jrhea
Copy link
Copy Markdown
Contributor Author

jrhea commented Feb 5, 2026

cc @lightclient

Copy link
Copy Markdown
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM, but it kinda feels like we are fixing the API because people are using it incorrectly, but I guess its okay

fjl
fjl previously approved these changes Feb 12, 2026
@fjl fjl added this to the 1.17.0 milestone Feb 12, 2026
@jrhea
Copy link
Copy Markdown
Contributor Author

jrhea commented Feb 12, 2026

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:

https://go.dev/play/p/GYTfThDS-Y2

lightclient
lightclient previously approved these changes Feb 12, 2026
Copy link
Copy Markdown
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

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.

}
spans := exporter.GetSpans()

// Only the server span and runMethod span should have error status.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

server span doesn't propagate error anymore, eh?

Copy link
Copy Markdown
Contributor Author

@jrhea jrhea Feb 13, 2026

Choose a reason for hiding this comment

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

good catch. i think that part of the comment needs to be removed.

@jrhea jrhea dismissed stale reviews from lightclient, fjl, and MariusVanDerWijden via f2efd27 February 13, 2026 03:21
@fjl fjl merged commit d8b92cb into ethereum:master Feb 14, 2026
7 of 8 checks passed
@jrhea jrhea deleted the otel-fix-span-error branch February 14, 2026 01:24
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.

4 participants