From 3ce216ede9e46c86d6688b3d31cf6ad9d8d4469e Mon Sep 17 00:00:00 2001 From: Prajilesh N Date: Mon, 2 Nov 2020 09:42:47 +0530 Subject: [PATCH] Converted TextMap propagator getter to a class and added keys method (#1196) Co-authored-by: alrex --- .../instrumentation/tornado/__init__.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 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 9a7959ab9..6bb956ecb 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -54,6 +54,7 @@ from opentelemetry.instrumentation.utils import ( http_status_to_status_code, unwrap, ) +from opentelemetry.trace.propagation.textmap import DictGetter from opentelemetry.trace.status import Status from opentelemetry.util import ExcludeList, time_ns @@ -84,6 +85,8 @@ def get_traced_request_attrs(): _excluded_urls = get_excluded_urls() _traced_attrs = get_traced_request_attrs() +carrier_getter = DictGetter() + class TornadoInstrumentor(BaseInstrumentor): patched_handlers = [] @@ -185,13 +188,6 @@ def _log_exception(tracer, func, handler, args, kwargs): return func(*args, **kwargs) -def _get_header_from_request_headers( - headers: dict, header_name: str -) -> typing.List[str]: - header = headers.get(header_name) - return [header] if header else [] - - def _get_attributes_from_request(request): attrs = { "component": "tornado", @@ -218,9 +214,7 @@ def _get_operation_name(handler, request): def _start_span(tracer, handler, start_time) -> _TraceContext: token = context.attach( - propagators.extract( - _get_header_from_request_headers, handler.request.headers, - ) + propagators.extract(carrier_getter, handler.request.headers,) ) span = tracer.start_span(