From acf02f1b56e80126a66ad736b10cde31e5f112da Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Thu, 8 Oct 2020 08:22:58 +0530 Subject: [PATCH] Added ability to extract span attributes from tornado request objects (#1178) OTEL_PYTHON_TONADO_TRACED_REQUEST_ATTRS env var can be set to a command separated list of attributes names that will be extracted from Tornado's request object and set as attributes on spans. Co-authored-by: (Eliseo) Nathaniel Ruiz Nowell --- .../instrumentation/falcon/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 660fc23063c0..bfcd45a8b585 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -53,7 +53,10 @@ def on_get(self, req, resp): from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.falcon.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor -from opentelemetry.instrumentation.utils import http_status_to_canonical_code +from opentelemetry.instrumentation.utils import ( + extract_attributes_from_object, + http_status_to_canonical_code, +) from opentelemetry.trace.status import Status from opentelemetry.util import ExcludeList, time_ns @@ -162,10 +165,11 @@ def process_request(self, req, resp): if not span: return - for attr in self._traced_request_attrs: - value = getattr(req, attr, None) - if value is not None: - span.set_attribute(attr, str(value)) + attributes = extract_attributes_from_object( + req, self._traced_request_attrs + ) + for key, value in attributes.items(): + span.set_attribute(key, value) def process_resource(self, req, resp, resource, params): span = req.env.get(_ENVIRON_SPAN_KEY)