Skip to content

[Core] Add method for setting span error status #40703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

pvaneck
Copy link
Member

@pvaneck pvaneck commented Apr 24, 2025

Spans started by OpenTelemetryTracer in core return an OpenTelemetry span. The set_status on this method requires that a user imports opentelemetry types for StatusCode enums.

We want to avoid SDK developers needing to import opentelemetry in order to set a span status. However, in all cases so far, where a status on a span is being set, it's to set it to ERROR. Here, we are adding a utility method on the OpenTelemetryTracer class to enable setting an error status on a provided span.

@pvaneck pvaneck force-pushed the core-tracing-status branch from a6f0e1a to e63f6f6 Compare April 24, 2025 01:24
@azure-sdk
Copy link
Collaborator

azure-sdk commented Apr 24, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-core

@pvaneck pvaneck marked this pull request as ready for review April 24, 2025 21:05
@Copilot Copilot AI review requested due to automatic review settings April 24, 2025 21:05
Copy link
Contributor

@Copilot 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

This PR adds a utility method (set_span_status) to the OpenTelemetryTracer class so that users can set span statuses without having to import opentelemetry types.

  • Introduces a static method set_span_status in opentelemetry.py that maps string status values ("OK", "ERROR", "UNSET") to corresponding Opentelemetry StatusCode enums.
  • Adds tests in test_tracer_otel.py to verify correct behavior for valid statuses and proper error handling for invalid statuses.
  • Updates the CHANGELOG to document the new feature.

Reviewed Changes

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

File Description
sdk/core/azure-core/tests/test_tracer_otel.py Added unit tests covering valid, case-insensitive, and invalid span status cases.
sdk/core/azure-core/azure/core/tracing/opentelemetry.py Defined the new set_span_status method to simplify span status setting.
sdk/core/azure-core/CHANGELOG.md Updated changelog to include the set_span_status feature.
Comments suppressed due to low confidence (1)

sdk/core/azure-core/tests/test_tracer_otel.py:378

  • [nitpick] Consider asserting the exception message to confirm that the raised ValueError contains the expected error message. This can help ensure that the error is being raised for the correct reason.
with pytest.raises(ValueError):

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-core

Spans started by `OpenTelemetryTracer` in core return an OpenTelemetry
span. The set_status on this method requires that a user imports
`opentelemetry` types for `StatusCode` enums.

We want to avoid SDK developers needing to import
`opentelemetry` in order to set a span status, however it all cases so
far where a user is setting a status, it's to set it to ERROR.  Here, we are adding a
utility method on the `OpenTelemetryTracer` class to enable setting an
error status on a provided span.

Signed-off-by: Paul Van Eck <[email protected]>
@pvaneck pvaneck force-pushed the core-tracing-status branch from e5bb939 to 6b81910 Compare April 29, 2025 00:58
@pvaneck pvaneck changed the title [Core] Add method for setting span status [Core] Add method for setting span error status Apr 29, 2025
@kashifkhan
Copy link
Member

will there be other methods that do need an import however, even if right now its largely the error scenario?

@pvaneck
Copy link
Member Author

pvaneck commented Apr 29, 2025

/check-enforcer override

@pvaneck pvaneck merged commit 8e7f1a8 into Azure:main Apr 29, 2025
47 of 50 checks passed
@pvaneck pvaneck deleted the core-tracing-status branch April 29, 2025 23:44
bambriz pushed a commit to bambriz/azure-sdk-for-python that referenced this pull request May 5, 2025
Spans started by `OpenTelemetryTracer` in core return an OpenTelemetry
span. The set_status on this method requires that a user imports
`opentelemetry` types for `StatusCode` enums.

We want to avoid SDK developers needing to import
`opentelemetry` in order to set a span status, however in all cases so
far where a user is setting a status, it's to set it to ERROR.  Here, we are adding a
utility method on the `OpenTelemetryTracer` class to enable setting an
error status on a provided span.

Signed-off-by: Paul Van Eck <[email protected]>
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.

3 participants