A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/tornado/tornado.html below:

Website Navigation


OpenTelemetry Tornado Instrumentation — OpenTelemetry Python Contrib documentation

OpenTelemetry Tornado Instrumentation

This library uses OpenTelemetry to track web requests in Tornado applications.

Usage
import tornado.web
from opentelemetry.instrumentation.tornado import TornadoInstrumentor

# apply tornado instrumentation
TornadoInstrumentor().instrument()

class Handler(tornado.web.RequestHandler):
    def get(self):
        self.set_status(200)

app = tornado.web.Application([(r"/", Handler)])
app.listen(8080)
tornado.ioloop.IOLoop.current().start()
Configuration

The following environment variables are supported as configuration options:

A comma separated list of paths that should not be automatically traced. For example, if this is set to

export OTEL_PYTHON_TORNADO_EXCLUDED_URLS='/healthz,/ping'

Then any requests made to /healthz and /ping will not be automatically traced.

Request attributes

To extract certain attributes from Tornado’s request object and use them as span attributes, set the environment variable OTEL_PYTHON_TORNADO_TRACED_REQUEST_ATTRS to a comma delimited list of request attribute names.

For example,

export OTEL_PYTHON_TORNADO_TRACED_REQUEST_ATTRS='uri,query'

will extract path_info and content_type attributes from every traced request and add them as span attributes.

Request/Response hooks

Tornado instrumentation supports extending tracing behaviour with the help of hooks. Its instrument() method accepts three optional functions that get called back with the created span and some other contextual information. Example:

from opentelemetry.instrumentation.tornado import TornadoInstrumentor

# will be called for each incoming request to Tornado
# web server. `handler` is an instance of
# `tornado.web.RequestHandler`.
def server_request_hook(span, handler):
    pass

# will be called just before sending out a request with
# `tornado.httpclient.AsyncHTTPClient.fetch`.
# `request` is an instance of ``tornado.httpclient.HTTPRequest`.
def client_request_hook(span, request):
    pass

# will be called after a outgoing request made with
# `tornado.httpclient.AsyncHTTPClient.fetch` finishes.
# `response`` is an instance of ``Future[tornado.httpclient.HTTPResponse]`.
def client_response_hook(span, future):
    pass

# apply tornado instrumentation with hooks
TornadoInstrumentor().instrument(
    server_request_hook=server_request_hook,
    client_request_hook=client_request_hook,
    client_response_hook=client_response_hook,
)
Capture HTTP request and response headers

You can configure the agent to capture predefined HTTP headers as span attributes, according to the semantic convention.

API
class opentelemetry.instrumentation.tornado.TornadoInstrumentor(*args, **kwargs)[source]

Bases: BaseInstrumentor

patched_handlers = []
original_handler_new = None
instrumentation_dependencies()[source]

Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or pyproject.toml.

For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection[str]

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.

opentelemetry.instrumentation.tornado.patch_handler_class(tracer, server_histograms, cls, request_hook=None)[source]
opentelemetry.instrumentation.tornado.unpatch_handler_class(cls)[source]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4