Skip to content

Ensure we handle the scenario the payment service code expects there to be an active span but finds none#2129

Merged
puckpuck merged 6 commits intoopen-telemetry:mainfrom
keyoke:users/gareth
Apr 20, 2025
Merged

Ensure we handle the scenario the payment service code expects there to be an active span but finds none#2129
puckpuck merged 6 commits intoopen-telemetry:mainfrom
keyoke:users/gareth

Conversation

@keyoke
Copy link
Contributor

@keyoke keyoke commented Mar 20, 2025

I am proposing a very minor change to handle when auto-instrumentation is disabled( similar to #2124 ) for the payment service. In this scenario, an exception is raised but I would expect it to be handled gracefully.

Changes

Added some very simple logic to check if the current active span is undefined, if it is we create a new span & mark this as the active span.

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

Maintainers will not merge until the above have been completed. If you're unsure
which docs need to be changed ping the
@open-telemetry/demo-approvers.

@keyoke keyoke requested a review from a team as a code owner March 20, 2025 17:33
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@keyoke keyoke changed the title Ensure we handle the scenario the payment service code expects there to be an active span Ensure we handle the scenario the payment service code expects there to be an active span but finds none Mar 20, 2025
@julianocosta89
Copy link
Member

@pichlermarc I would love to hear your opinion here

@puckpuck
Copy link
Contributor

I understand if the SDK is disabled, the service should not throw an error which is what #2124 discusses.

I struggle to understand in what scenario we need to start a trace if one does not exists.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

I struggle to understand in what scenario we need to start a trace if one does not exists.

I agree - in my opinion the way to address the problem of the crashing app would be either to:

  • optional chain on the span object obtained via getActiveSpan() wherever it's used
    • example: span.setAttributes({...}) -> span?.setAttributes({...})
  • create and end an internal span always no matter if a trace was already started or not to which you can attach any attributes and errors you like, while retaining semantics for the grpc span that's likely being modified here (since that one is strictly supposed to follow the gRPC semconv anyway and modifying error status may interfere with that).

@github-actions
Copy link

github-actions bot commented Apr 4, 2025

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@julianocosta89
Copy link
Member

@pichlermarc this is the issue I've mentioned to you during KubeCon.
Would you mind taking a look?

@github-actions
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 17, 2025
@puckpuck puckpuck removed the Stale label Apr 17, 2025
@pichlermarc
Copy link
Member

@julianocosta89 - sorry for the delay. This looks good.
Thank you @keyoke for working on this 🙂

@puckpuck puckpuck merged commit 8d1afe7 into open-telemetry:main Apr 20, 2025
31 checks passed
cloud-hb pushed a commit to cloud-hb/opentelemetry-demo that referenced this pull request Nov 17, 2025
…to be an active span but finds none (open-telemetry#2129)

* Ensure we handle the scenario where there is currently no active span for e.g. open-telemetry#2124

* Mark this new span as active

* incorporate review comments

* revert var def change

---------

Co-authored-by: Juliano Costa <julianocosta89@outlook.com>
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.

4 participants