From 640b117ab8ed96fee8a0db8ab963b5b182c81d26 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 15 Mar 2022 10:50:33 -0700 Subject: [PATCH] fix non-recording bug (#999) --- CHANGELOG.md | 9 +++++---- .../src/opentelemetry/instrumentation/flask/__init__.py | 7 +++++-- .../opentelemetry/instrumentation/tornado/__init__.py | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3449b5e72..8874dca27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,16 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.10.0-0.29b0...HEAD) +- `opentelemetry-instrumentation-flask` Fix non-recording span bug + ([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999) +- `opentelemetry-instrumentation-tornado` Fix non-recording span bug + ([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999) + ## [1.10.0-0.29b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.10.0-0.29b0) - 2022-03-10 - - - `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes ([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925) - - `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes ([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952) - - `opentelemetry-instrumentation-tornado` Tornado: Capture custom request/response headers in span attributes ([#950])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/950) diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 1db768a2c..272b0d934 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -153,7 +153,10 @@ def _rewrapped_app(wsgi_app, response_hook=None, excluded_urls=None): otel_wsgi.add_response_attributes( span, status, response_headers ) - if span.kind == trace.SpanKind.SERVER: + if ( + span.is_recording() + and span.kind == trace.SpanKind.SERVER + ): otel_wsgi.add_custom_response_headers( span, response_headers ) @@ -204,7 +207,7 @@ def _wrapped_before_request( ] = flask.request.url_rule.rule for key, value in attributes.items(): span.set_attribute(key, value) - if span.kind == trace.SpanKind.SERVER: + if span.is_recording() and span.kind == trace.SpanKind.SERVER: otel_wsgi.add_custom_request_headers( span, flask_request_environ ) 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 cec7662a2..fed27dfea 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -340,7 +340,7 @@ def _start_span(tracer, handler, start_time) -> _TraceContext: for key, value in attributes.items(): span.set_attribute(key, value) span.set_attribute("tornado.handler", _get_full_handler_name(handler)) - if span.kind == trace.SpanKind.SERVER: + if span.is_recording() and span.kind == trace.SpanKind.SERVER: _add_custom_request_headers(span, handler.request.headers) activation = trace.use_span(span, end_on_exit=True) @@ -395,7 +395,7 @@ def _finish_span(tracer, handler, error=None): description=otel_status_description, ) ) - if ctx.span.kind == trace.SpanKind.SERVER: + if ctx.span.is_recording() and ctx.span.kind == trace.SpanKind.SERVER: _add_custom_response_headers(ctx.span, handler._headers) ctx.activation.__exit__(*finish_args) # pylint: disable=E1101