opentelemetry.ext.wsgi package

Module contents

The opentelemetry-ext-wsgi package provides a WSGI middleware that can be used on any WSGI framework (such as Django / Flask) to track requests timing through OpenTelemetry.

opentelemetry.ext.wsgi.get_header_from_environ(environ, header_name)[source]

Retrieve a HTTP header value from the PEP3333-conforming WSGI environ.

Return type

List[str]

Returns

A list with a single string with the header value if it exists, else an empty list.

opentelemetry.ext.wsgi.setifnotnone(dic, key, value)[source]
opentelemetry.ext.wsgi.http_status_to_canonical_code(code, allow_redirect=True)[source]
opentelemetry.ext.wsgi.collect_request_attributes(environ)[source]

Collects HTTP request attributes from the PEP3333-conforming WSGI environ and returns a dictionary to be used as span creation attributes.

opentelemetry.ext.wsgi.add_response_attributes(span, start_response_status, response_headers)[source]

Adds HTTP response attributes to span using the arguments passed to a PEP3333-conforming start_response callable.

opentelemetry.ext.wsgi.get_default_span_name(environ)[source]

Calculates a (generic) span name for an incoming HTTP request based on the PEP3333 conforming WSGI environ.

class opentelemetry.ext.wsgi.OpenTelemetryMiddleware(wsgi)[source]

Bases: object

The WSGI application middleware.

This class is a PEP 3333 conforming WSGI middleware that starts and annotates spans for any requests it is invoked with.

Parameters

wsgi – The WSGI application callable to forward requests to.