From 046bdbefcfd521c7ecbedaa832220488eeb080a2 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Wed, 14 Oct 2020 15:07:23 -0400 Subject: [PATCH] Use is_recording flag in jinja, celery, esearch, falcon instrumentations (#1241) --- .../instrumentation/tornado/__init__.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 5357be6d0..f6ae8b321 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -226,9 +226,12 @@ def _start_span(tracer, handler, start_time) -> _TraceContext: span = tracer.start_span( _get_operation_name(handler, handler.request), kind=trace.SpanKind.SERVER, - attributes=_get_attributes_from_request(handler.request), start_time=start_time, ) + if span.is_recording(): + attributes = _get_attributes_from_request(handler.request) + for key, value in attributes.items(): + span.set_attribute(key, value) activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() @@ -260,15 +263,16 @@ def _finish_span(tracer, handler, error=None): if not ctx: return - if reason: - ctx.span.set_attribute("http.status_text", reason) - ctx.span.set_attribute("http.status_code", status_code) - ctx.span.set_status( - Status( - canonical_code=http_status_to_canonical_code(status_code), - description=reason, + if ctx.span.is_recording(): + if reason: + ctx.span.set_attribute("http.status_text", reason) + ctx.span.set_attribute("http.status_code", status_code) + ctx.span.set_status( + Status( + canonical_code=http_status_to_canonical_code(status_code), + description=reason, + ) ) - ) ctx.activation.__exit__(*finish_args) context.detach(ctx.token)