tornado_opentracing/_tracing.py
def _apply_tracing(self, handler, attributes):
        """
        Helper function to avoid rewriting for middleware and decorator.
        Returns a new span from the request with logged attributes and
        correct operation name from the func.
        """
        operation_name = self._get_operation_name(handler)
        headers = handler.request.headers
        request = handler.request

        # start new span from trace info
        try:
            span_ctx = self._tracer.extract(opentracing.Format.HTTP_HEADERS, headers)
            scope = self._tracer.start_active_span(operation_name, child_of=span_ctx)
        except (
            opentracing.InvalidCarrierException,
            opentracing.SpanContextCorruptedException,
        ):
            scope = self._tracer.start_active_span(operation_name)

        # add span to current spans
        setattr(request, SCOPE_ATTR, scope)

        # log any traced attributes
        scope.span.set_tag(tags.COMPONENT, "tornado")
        scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        scope.span.set_tag(tags.HTTP_METHOD, request.method)
        scope.span.set_tag(tags.HTTP_URL, request.uri)

        for attr in attributes:
            if hasattr(request, attr):
                payload = str(getattr(request, attr))
                if payload:
                    scope.span.set_tag(attr, payload)

        # invoke the start span callback, if any
        self._call_start_span_cb(scope.span, request)

        if self._trace_response_headers_enabled:
            trace_id = getattr(scope.span.context, "trace_id", 0)
            span_id = getattr(scope.span.context, "span_id", 0)
            if trace_id and span_id:
                handler.add_header("Access-Control-Expose-Headers", "Server-Timing")
                handler.add_header(
                    "Server-Timing",
                    'traceparent;desc="00-{trace_id}-{span_id}-01"'.format(
                        trace_id="{:016x}".format(trace_id),
                        span_id="{:016x}".format(span_id),
                    ),
                )

        return scope

        Helper function to avoid rewriting for middleware and decorator.
        Returns a new span from the request with logged attributes and
        correct operation name from the func.
        
Helper function to avoid rewriting for middleware and decorator.
Returns a new span from the request with logged attributes and
correct operation name from the func.
Helper function to avoid rewriting for middleware and decorator . Returns a new span from the request with logged attributes and correct operation name from the func .
def _apply_tracing(self, handler, attributes):
        operation_name = self._get_operation_name(handler)
        headers = handler.request.headers
        request = handler.request
        try:
            span_ctx = self._tracer.extract(opentracing.Format.HTTP_HEADERS, headers)
            scope = self._tracer.start_active_span(operation_name, child_of=span_ctx)
        except (
            opentracing.InvalidCarrierException,
            opentracing.SpanContextCorruptedException,
        ):
            scope = self._tracer.start_active_span(operation_name)
        setattr(request, SCOPE_ATTR, scope)
        scope.span.set_tag(tags.COMPONENT, "tornado")
        scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        scope.span.set_tag(tags.HTTP_METHOD, request.method)
        scope.span.set_tag(tags.HTTP_URL, request.uri)
        for attr in attributes:
            if hasattr(request, attr):
                payload = str(getattr(request, attr))
                if payload:
                    scope.span.set_tag(attr, payload)
        self._call_start_span_cb(scope.span, request)
        if self._trace_response_headers_enabled:
            trace_id = getattr(scope.span.context, "trace_id", 0)
            span_id = getattr(scope.span.context, "span_id", 0)
            if trace_id and span_id:
                handler.add_header("Access-Control-Expose-Headers", "Server-Timing")
                handler.add_header(
                    "Server-Timing",
                    'traceparent;desc="00-{trace_id}-{span_id}-01"'.format(
                        trace_id="{:016x}".format(trace_id),
                        span_id="{:016x}".format(span_id),
                    ),
                )
        return scope
def _apply_tracing ( self , handler , attributes ) : operation_name = self . _get_operation_name ( handler ) headers = handler . request . headers request = handler . request try : span_ctx = self . _tracer . extract ( opentracing . Format . HTTP_HEADERS , headers ) scope = self . _tracer . start_active_span ( operation_name , child_of = span_ctx ) except ( opentracing . InvalidCarrierException , opentracing . SpanContextCorruptedException , ) : scope = self . _tracer . start_active_span ( operation_name ) setattr ( request , SCOPE_ATTR , scope ) scope . span . set_tag ( tags . COMPONENT , "tornado" ) scope . span . set_tag ( tags . SPAN_KIND , tags . SPAN_KIND_RPC_SERVER ) scope . span . set_tag ( tags . HTTP_METHOD , request . method ) scope . span . set_tag ( tags . HTTP_URL , request . uri ) for attr in attributes : if hasattr ( request , attr ) : payload = str ( getattr ( request , attr ) ) if payload : scope . span . set_tag ( attr , payload ) self . _call_start_span_cb ( scope . span , request ) if self . _trace_response_headers_enabled : trace_id = getattr ( scope . span . context , "trace_id" , 0 ) span_id = getattr ( scope . span . context , "span_id" , 0 ) if trace_id and span_id : handler . add_header ( "Access-Control-Expose-Headers" , "Server-Timing" ) handler . add_header ( "Server-Timing" , 'traceparent;desc="00-{trace_id}-{span_id}-01"' . format ( trace_id = "{:016x}" . format ( trace_id ) , span_id = "{:016x}" . format ( span_id ) , ) , ) return scope
Helper function to avoid rewriting for middleware and decorator.
Helper function to avoid rewriting for middleware and decorator .
"""
        Helper function to avoid rewriting for middleware and decorator.
        Returns a new span from the request with logged attributes and
        correct operation name from the func.
        """ # start new span from trace info # add span to current spans # log any traced attributes # invoke the start span callback, if any
self
handler
attributes