Skip to content

Fix charge span leak in the payment service#3276

Merged
puckpuck merged 7 commits intoopen-telemetry:mainfrom
ayoisaiah:fix-charge-span-payment-service
Apr 23, 2026
Merged

Fix charge span leak in the payment service#3276
puckpuck merged 7 commits intoopen-telemetry:mainfrom
ayoisaiah:fix-charge-span-payment-service

Conversation

@ayoisaiah
Copy link
Copy Markdown
Contributor

@ayoisaiah ayoisaiah commented Apr 17, 2026

Changes

Fix span lifecycle and exception attribution in the payment service charge span.

  • Wrap the body of charge() in a try/catch/finally so span.end() is always called, including on validation error paths where the span previously leaked.
  • Record the exception and set SpanStatusCode.ERROR on the charge span in the catch block, where the failure actually originates.
  • Remove span.recordException(err) from index.js. The gRPC span now only has its status set to ERROR with the error message, avoiding duplicate exception attribution.

Fixes #3275

Merge Requirements

For new features contributions, please make sure you have completed the following
essential items:

  • CHANGELOG.md updated to document new feature additions
  • Appropriate documentation updates in the [docs][]
  • Appropriate Helm chart updates in the [helm-charts][]

@ayoisaiah ayoisaiah requested a review from a team as a code owner April 17, 2026 11:08
Copy link
Copy Markdown
Contributor

@osullivandonal osullivandonal left a comment

Choose a reason for hiding this comment

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

Nice work on this, thanks for the contribution! Could we add a changelog entry to CHANGELOG.md.

Comment thread src/payment/charge.js
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes OpenTelemetry span lifecycle and error attribution in the payment service so the manually-created charge span is always ended and owns its own exceptions (instead of leaking or attributing exceptions to the parent gRPC span), addressing issue #3275.

Changes:

  • Wrap charge() logic in try/catch/finally to guarantee span.end() on all paths and to record exception + ERROR status on the charge span.
  • Remove explicit recordException() on the parent gRPC span and set its status to ERROR with the error message to avoid duplicate exception attribution.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/payment/index.js Stops recording exceptions on the parent gRPC span; sets ERROR status with message only.
src/payment/charge.js Ensures charge span is always ended and that exceptions/status are recorded on the charge span.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/payment/charge.js
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@puckpuck
Copy link
Copy Markdown
Contributor

@ayoisaiah Can you fix the yamllint check errors? Don't worry about the failing link checks, that's a known issue in this repo.

@ayoisaiah
Copy link
Copy Markdown
Contributor Author

@puckpuck Just pushed the fix, thanks!

Copy link
Copy Markdown
Contributor

@puckpuck puckpuck left a comment

Choose a reason for hiding this comment

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

Everything works great. Thanks for this.

@puckpuck puckpuck enabled auto-merge April 23, 2026 14:35
@puckpuck puckpuck added this pull request to the merge queue Apr 23, 2026
Merged via the queue into open-telemetry:main with commit 75dc5aa Apr 23, 2026
39 checks passed
AnjaliMishra1st pushed a commit to AnjaliMishra1st/opentelemetry-demo that referenced this pull request Apr 28, 2026
* fix charge span leak and exception misattribution

* [payment] fix charge span leak and exception misattribution

* [payment] add charge span status assertions to trace tests

* fix indentation

---------

Co-authored-by: Pierre Tessier <pierre@pierretessier.com>
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.

Payment service: charge span leaks and misattributes exceptions on validation errors

4 participants