OpenTelemetry aiohttp server Integration

pypi

This library allows tracing HTTP requests made by the aiohttp server library.

Installation

pip install opentelemetry-instrumentation-aiohttp-server
opentelemetry.instrumentation.aiohttp_server.get_default_span_details(request)[source]

Default implementation for get_default_span_details :type request: Request :param request: the request object itself.

Return type:

Tuple[str, dict]

Returns:

a tuple of the span name, and any attributes to attach to the span.

opentelemetry.instrumentation.aiohttp_server.collect_request_attributes(request)[source]

Collects HTTP request attributes from the ASGI scope and returns a dictionary to be used as span creation attributes.

Return type:

Dict

opentelemetry.instrumentation.aiohttp_server.set_status_code(span, status_code)[source]

Adds HTTP response attributes to span using the status_code argument.

Return type:

None

class opentelemetry.instrumentation.aiohttp_server.AiohttpGetter[source]

Bases: Getter

Extract current trace from headers

get(carrier, key)[source]

Getter implementation to retrieve an HTTP header value from the ASGI scope.

Parameters:
  • carrier – ASGI scope object

  • key (str) – header name in scope

Return type:

Optional[List]

Returns:

A list of all header values matching the key, or None if the key does not match any header.

keys(carrier)[source]

Function that can retrieve all the keys in a carrier object.

Parameters:

carrier (Dict) – An object which contains values that are used to construct a Context.

Return type:

List

Returns:

list of keys from the carrier.

async opentelemetry.instrumentation.aiohttp_server.middleware(request, handler)[source]

Middleware for aiohttp implementing tracing logic

class opentelemetry.instrumentation.aiohttp_server.AioHttpServerInstrumentor(*args, **kwargs)[source]

Bases: BaseInstrumentor

An instrumentor for aiohttp.web.Application

See BaseInstrumentor

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:

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.