From 8491e6b50e281b7cf988d0b812cb62e5b2e6ee08 Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Fri, 9 Jun 2023 11:23:54 +0200 Subject: [PATCH 1/5] Fix falcon usage of Span Status to only set the description if the status code is ERROR --- .../instrumentation/falcon/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 3a6a86e4fb..5dcc08468b 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -208,7 +208,7 @@ def response_hook(span, req, resp): from opentelemetry.metrics import get_meter from opentelemetry.semconv.metrics import MetricInstruments from opentelemetry.semconv.trace import SpanAttributes -from opentelemetry.trace.status import Status +from opentelemetry.trace.status import Status, StatusCode from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs _logger = getLogger(__name__) @@ -461,12 +461,17 @@ def process_response( try: status_code = int(status) span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code) + otel_status_code = http_status_to_status_code(status_code, server_span=True) + + # set the description only when the status code is ERROR + otel_status_description = None + if otel_status_code is StatusCode.ERROR: + otel_status_description = reason + span.set_status( Status( - status_code=http_status_to_status_code( - status_code, server_span=True - ), - description=reason, + status_code=otel_status_code, + description=otel_status_description, ) ) From 5eb37cd625781b45868b4aadd0ca1962cc196412 Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Fri, 9 Jun 2023 11:30:33 +0200 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee92bdab7a..675e1a5e46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR. + ## Version 1.18.0/0.39b0 (2023-05-10) - `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) @@ -21,9 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1778](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1778)) - Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations ([#1733](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1733)) -- Make Django request span attributes available for `start_span`. +- Make Django request span attributes available for `start_span`. ([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730)) -- Make ASGI request span attributes available for `start_span`. +- Make ASGI request span attributes available for `start_span`. ([#1762](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1762)) - `opentelemetry-instrumentation-celery` Add support for anonymous tasks. ([#1407](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1407)) From 6758c45603716f6a78073f9a50d11c07b6a13e31 Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Mon, 12 Jun 2023 08:34:21 +0200 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Srikanth Chekuri --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 675e1a5e46..e8ed162f8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR. - + ([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840)) ## Version 1.18.0/0.39b0 (2023-05-10) - `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) From 5d18eba8dfffea296a1ad9165d2a5cd7162f00ff Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Mon, 12 Jun 2023 08:38:12 +0200 Subject: [PATCH 4/5] fix lint --- .../src/opentelemetry/instrumentation/falcon/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 5dcc08468b..f9e9dd3ea6 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -461,7 +461,9 @@ def process_response( try: status_code = int(status) span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code) - otel_status_code = http_status_to_status_code(status_code, server_span=True) + otel_status_code = http_status_to_status_code( + status_code, server_span=True + ) # set the description only when the status code is ERROR otel_status_description = None From 6ccd25410382138dc901a0ce54aad54673da7b29 Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Mon, 12 Jun 2023 09:41:38 +0200 Subject: [PATCH 5/5] Use fewer variables to satisfy R0914 lint rule --- .../src/opentelemetry/instrumentation/falcon/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index f9e9dd3ea6..73c005fa17 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -466,14 +466,13 @@ def process_response( ) # set the description only when the status code is ERROR - otel_status_description = None - if otel_status_code is StatusCode.ERROR: - otel_status_description = reason + if otel_status_code is not StatusCode.ERROR: + reason = None span.set_status( Status( status_code=otel_status_code, - description=otel_status_description, + description=reason, ) )