Skip to content

Commit

Permalink
chore(otel): supress unessesary warning (#11857)
Browse files Browse the repository at this point in the history
Resolves: #10818

Ensure set status warning log is only generated when
`Span.set_status(...)` is called with two conflicting descriptions.
Right now this warning is logged every time the status argument is and
instance of opentelemetry.trace.Status.

Opentelemetry-sdk:
https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L971

## Checklist
- [ ] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [ ] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
mabdinur authored Jan 6, 2025
1 parent 148da15 commit 81208cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ddtrace/internal/opentelemetry/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,16 @@ def set_status(self, status, description=None):
return

if isinstance(status, Status):
if description is not None and description != status.description:
log.warning(
"Conflicting descriptions detected. The following description will not be set on the %s span: %s. "
"Ensure `Span.set_status(...)` is called with `(Status(status_code, description), None)` "
"or `(status_code, description)`",
self._ddspan.name,
description,
)
status_code = status.status_code
message = status.description
log.warning("Description %s ignored. Use either `Status` or `(StatusCode, Description)`", description)
else:
status_code = status
message = description
Expand Down
5 changes: 3 additions & 2 deletions tests/opentelemetry/test_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ def test_otel_span_status_with_status_obj(oteltracer, caplog):
assert errspan_dup_des._ddspan.error == 1
assert errspan_dup_des._ddspan.get_tag("error.message") in "main otel err message"
assert (
"Description ot_duplicate_message ignored. Use either `Status` or `(StatusCode, Description)`"
in caplog.text
"Conflicting descriptions detected. The following description will not be set "
"on the otel-error-dup-description span: ot_duplicate_message. Ensure `Span.set_status(...)` "
"is called with `(Status(status_code, description), None)` or `(status_code, description)`" in caplog.text
)

with oteltracer.start_span("set-status-on-otel-span") as span1:
Expand Down

0 comments on commit 81208cd

Please sign in to comment.