fix non-recording bug (#999)

This commit is contained in:
Alex Boten
2022-03-15 10:50:33 -07:00
committed by GitHub
parent 8fc95cab64
commit 640b117ab8
3 changed files with 12 additions and 8 deletions

View File

@ -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) ## [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 ## [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 - `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes
([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925) ([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925)
- `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes - `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes
([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952) ([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952)
- `opentelemetry-instrumentation-tornado` Tornado: Capture custom request/response headers in span attributes - `opentelemetry-instrumentation-tornado` Tornado: Capture custom request/response headers in span attributes
([#950])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/950) ([#950])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/950)

View File

@ -153,7 +153,10 @@ def _rewrapped_app(wsgi_app, response_hook=None, excluded_urls=None):
otel_wsgi.add_response_attributes( otel_wsgi.add_response_attributes(
span, status, response_headers 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( otel_wsgi.add_custom_response_headers(
span, response_headers span, response_headers
) )
@ -204,7 +207,7 @@ def _wrapped_before_request(
] = flask.request.url_rule.rule ] = flask.request.url_rule.rule
for key, value in attributes.items(): for key, value in attributes.items():
span.set_attribute(key, value) 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( otel_wsgi.add_custom_request_headers(
span, flask_request_environ span, flask_request_environ
) )

View File

@ -340,7 +340,7 @@ def _start_span(tracer, handler, start_time) -> _TraceContext:
for key, value in attributes.items(): for key, value in attributes.items():
span.set_attribute(key, value) span.set_attribute(key, value)
span.set_attribute("tornado.handler", _get_full_handler_name(handler)) 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) _add_custom_request_headers(span, handler.request.headers)
activation = trace.use_span(span, end_on_exit=True) activation = trace.use_span(span, end_on_exit=True)
@ -395,7 +395,7 @@ def _finish_span(tracer, handler, error=None):
description=otel_status_description, 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) _add_custom_response_headers(ctx.span, handler._headers)
ctx.activation.__exit__(*finish_args) # pylint: disable=E1101 ctx.activation.__exit__(*finish_args) # pylint: disable=E1101