fix NonRecordSpan.attributes access (#1377)

This commit is contained in:
Adrian Garcia Badaracco
2022-10-21 10:58:00 -05:00
committed by GitHub
parent 75953f3b25
commit 99f29b4b08
2 changed files with 19 additions and 13 deletions

View File

@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.13.0-0.34b0...HEAD) ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.13.0-0.34b0...HEAD)
- Add metric instrumentation for tornado - Add metric instrumentation for tornado
([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252)) ([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252))
- Fix bug in Falcon instrumentation
([#1377](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1377))
### Added ### Added

View File

@ -277,6 +277,7 @@ class _InstrumentedFalconAPI(getattr(falcon, _instrument_app)):
def __call__(self, env, start_response): def __call__(self, env, start_response):
# pylint: disable=E1101 # pylint: disable=E1101
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
# pylint: disable=too-many-branches
if self._otel_excluded_urls.url_disabled(env.get("PATH_INFO", "/")): if self._otel_excluded_urls.url_disabled(env.get("PATH_INFO", "/")):
return super().__call__(env, start_response) return super().__call__(env, start_response)
@ -313,35 +314,38 @@ class _InstrumentedFalconAPI(getattr(falcon, _instrument_app)):
activation.__enter__() activation.__enter__()
env[_ENVIRON_SPAN_KEY] = span env[_ENVIRON_SPAN_KEY] = span
env[_ENVIRON_ACTIVATION_KEY] = activation env[_ENVIRON_ACTIVATION_KEY] = activation
exception = None
def _start_response(status, response_headers, *args, **kwargs): def _start_response(status, response_headers, *args, **kwargs):
response = start_response( response = start_response(
status, response_headers, *args, **kwargs status, response_headers, *args, **kwargs
) )
activation.__exit__(None, None, None)
if token is not None:
context.detach(token)
return response return response
start = default_timer() start = default_timer()
try: try:
return super().__call__(env, _start_response) return super().__call__(env, _start_response)
except Exception as exc: except Exception as exc:
activation.__exit__( exception = exc
type(exc),
exc,
getattr(exc, "__traceback__", None),
)
if token is not None:
context.detach(token)
raise raise
finally: finally:
duration_attrs[ if span.is_recording():
SpanAttributes.HTTP_STATUS_CODE duration_attrs[
] = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE) SpanAttributes.HTTP_STATUS_CODE
] = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE)
duration = max(round((default_timer() - start) * 1000), 0) duration = max(round((default_timer() - start) * 1000), 0)
self.duration_histogram.record(duration, duration_attrs) self.duration_histogram.record(duration, duration_attrs)
self.active_requests_counter.add(-1, active_requests_count_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: class _TraceMiddleware: