From 81208cd2deec03ecf4f036398fd637a3ffe2fa0a Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Mon, 6 Jan 2025 14:02:06 -0500 Subject: [PATCH] chore(otel): supress unessesary warning (#11857) Resolves: https://github.com/DataDog/dd-trace-py/issues/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) --- ddtrace/internal/opentelemetry/span.py | 9 ++++++++- tests/opentelemetry/test_span.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ddtrace/internal/opentelemetry/span.py b/ddtrace/internal/opentelemetry/span.py index 15f497a358e..acb5e066311 100644 --- a/ddtrace/internal/opentelemetry/span.py +++ b/ddtrace/internal/opentelemetry/span.py @@ -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 diff --git a/tests/opentelemetry/test_span.py b/tests/opentelemetry/test_span.py index 8909f3db07f..24b2f1524f3 100644 --- a/tests/opentelemetry/test_span.py +++ b/tests/opentelemetry/test_span.py @@ -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: