opentelemetry.ext.asgi package¶
Module contents¶
The opentelemetry-ext-asgi package provides an ASGI middleware that can be used on any ASGI framework (such as Django-channels / Quart) to track requests timing through OpenTelemetry.
-
opentelemetry.ext.asgi.
get_header_from_scope
(scope, header_name)[source]¶ Retrieve a HTTP header value from the ASGI scope.
- Return type
List
[str
]- Returns
A list with a single string with the header value if it exists, else an empty list.
-
opentelemetry.ext.asgi.
collect_request_attributes
(scope)[source]¶ Collects HTTP request attributes from the ASGI scope and returns a dictionary to be used as span creation attributes.
-
opentelemetry.ext.asgi.
set_status_code
(span, status_code)[source]¶ Adds HTTP response attributes to span using the status_code argument.
-
opentelemetry.ext.asgi.
get_default_span_name
(scope)[source]¶ Default implementation for name_callback
-
class
opentelemetry.ext.asgi.
OpenTelemetryMiddleware
(app, name_callback=None)[source]¶ Bases:
object
The ASGI application middleware.
This class is an ASGI middleware that starts and annotates spans for any requests it is invoked with.
- Parameters
app – The ASGI application callable to forward requests to.
name_callback – Callback which calculates a generic span name for an incoming HTTP request based on the ASGI scope. Optional: Defaults to get_default_span_name.