Skip to content

Commit

Permalink
Added ability to extract span attributes from tornado request objects (
Browse files Browse the repository at this point in the history
#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 <enruizno@uwaterloo.ca>
  • Loading branch information
owais and NathanielRN authored Oct 8, 2020
1 parent 899ffd1 commit acf02f1
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit acf02f1

Please sign in to comment.