ddtrace/contrib/tornado/handlers.py
def execute(func, handler, args, kwargs):
    """
    Wrap the handler execute method so that the entire request is within the same
    ``TracerStackContext``. This simplifies users code when the automatic ``Context``
    retrieval is used via ``Tracer.trace()`` method.
    """
    # retrieve tracing settings
    settings = handler.settings[CONFIG_KEY]
    tracer = settings['tracer']
    service = settings['default_service']
    distributed_tracing = settings['distributed_tracing']

    with TracerStackContext():
        # attach the context to the request
        setattr(handler.request, REQUEST_CONTEXT_KEY, tracer.get_call_context())

        # Read and use propagated context from HTTP headers
        if distributed_tracing:
            propagator = HTTPPropagator()
            context = propagator.extract(handler.request.headers)
            if context.trace_id:
                tracer.context_provider.activate(context)

        # store the request span in the request so that it can be used later
        request_span = tracer.trace(
            'tornado.request',
            service=service,
            span_type=http.TYPE
        )
        setattr(handler.request, REQUEST_SPAN_KEY, request_span)

        return func(*args, **kwargs)

    Wrap the handler execute method so that the entire request is within the same
    ``TracerStackContext``. This simplifies users code when the automatic ``Context``
    retrieval is used via ``Tracer.trace()`` method.
    
Wrap the handler execute method so that the entire request is within the same
``TracerStackContext``.
Wrap the handler execute method so that the entire request is within the same ` ` TracerStackContext ` ` .
def execute(func, handler, args, kwargs):
    settings = handler.settings[CONFIG_KEY]
    tracer = settings['tracer']
    service = settings['default_service']
    distributed_tracing = settings['distributed_tracing']
    with TracerStackContext():
        setattr(handler.request, REQUEST_CONTEXT_KEY, tracer.get_call_context())
        if distributed_tracing:
            propagator = HTTPPropagator()
            context = propagator.extract(handler.request.headers)
            if context.trace_id:
                tracer.context_provider.activate(context)
        request_span = tracer.trace(
            'tornado.request',
            service=service,
            span_type=http.TYPE
        )
        setattr(handler.request, REQUEST_SPAN_KEY, request_span)
        return func(*args, **kwargs)
def execute ( func , handler , args , kwargs ) : settings = handler . settings [ CONFIG_KEY ] tracer = settings [ 'tracer' ] service = settings [ 'default_service' ] distributed_tracing = settings [ 'distributed_tracing' ] with TracerStackContext ( ) : setattr ( handler . request , REQUEST_CONTEXT_KEY , tracer . get_call_context ( ) ) if distributed_tracing : propagator = HTTPPropagator ( ) context = propagator . extract ( handler . request . headers ) if context . trace_id : tracer . context_provider . activate ( context ) request_span = tracer . trace ( 'tornado.request' , service = service , span_type = http . TYPE ) setattr ( handler . request , REQUEST_SPAN_KEY , request_span ) return func ( * args , ** kwargs )
Wrap the handler execute method so that the entire request is within the same
``TracerStackContext``.
Wrap the handler execute method so that the entire request is within the same ` ` TracerStackContext ` ` .
"""
    Wrap the handler execute method so that the entire request is within the same
    ``TracerStackContext``. This simplifies users code when the automatic ``Context``
    retrieval is used via ``Tracer.trace()`` method.
    """ # retrieve tracing settings # attach the context to the request # Read and use propagated context from HTTP headers # store the request span in the request so that it can be used later
func
handler
args
kwargs