From f4a2b615ed0b9a26a3535d5c74a2d45050f1a79c Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Mon, 24 May 2021 22:22:00 +0530 Subject: [PATCH] Fix tornado instrumentation's usage of Span Status (#504) --- CHANGELOG.md | 3 +++ .../opentelemetry/instrumentation/tornado/__init__.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5af519fd7..629dc47018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.2.0-0.21b0...HEAD) +- Fixed cases where description was used with non-error status code when creating Status objects. + ([#504](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/504)) + ### Added - `opentelemetry-instrumentation-botocore` now supports context propagation for lambda invoke via Payload embedded headers. diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index e13d24c971..e0e1e54e5c 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -95,7 +95,7 @@ def client_resposne_hook(span, future): ) from opentelemetry.propagate import extract from opentelemetry.semconv.trace import SpanAttributes -from opentelemetry.trace.status import Status +from opentelemetry.trace.status import Status, StatusCode from opentelemetry.util._time import _time_ns from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs @@ -299,10 +299,14 @@ def _finish_span(tracer, handler, error=None): if ctx.span.is_recording(): ctx.span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code) + otel_status_code = http_status_to_status_code(status_code) + otel_status_description = None + if otel_status_code is StatusCode.ERROR: + otel_status_description = reason ctx.span.set_status( Status( - status_code=http_status_to_status_code(status_code), - description=reason, + status_code=otel_status_code, + description=otel_status_description, ) )