From a3b383ad66015fbc2970876a6c4dfe0009046abd Mon Sep 17 00:00:00 2001 From: Anshul Asawa <35421635+TheAnshul756@users.noreply.github.com> Date: Thu, 6 Oct 2022 15:40:27 +0530 Subject: [PATCH] fix span detech issue. --- .../instrumentation/falcon/__init__.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 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 f41bf893ea..2e78479861 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -312,36 +312,36 @@ def __call__(self, env, start_response): activation.__enter__() env[_ENVIRON_SPAN_KEY] = span env[_ENVIRON_ACTIVATION_KEY] = activation + exception = None def _start_response(status, response_headers, *args, **kwargs): response = start_response( status, response_headers, *args, **kwargs ) - activation.__exit__(None, None, None) - if token is not None: - context.detach(token) return response start = default_timer() try: return super().__call__(env, _start_response) except Exception as exc: - activation.__exit__( - type(exc), - exc, - getattr(exc, "__traceback__", None), - ) - if token is not None: - context.detach(token) + exception = exc raise finally: if span.is_recording(): duration_attrs[ SpanAttributes.HTTP_STATUS_CODE ] = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE) - duration = max(round((default_timer() - start) * 1000), 0) - self.duration_histogram.record(duration, duration_attrs) + duration = max(round((default_timer() - start) * 1000), 0) + self.duration_histogram.record(duration, duration_attrs) self.active_requests_counter.add(-1, active_requests_count_attrs) + if exception is None: + activation.__exit__(None, None, None) + else: + activation.__exit__( + type(exception), exception, getattr(exception, "__traceback__", None) + ) + if token is not None: + context.detach(token) class _TraceMiddleware: