OpenTelemetry urllib3 Instrumentation

This library allows tracing HTTP requests made by the urllib3 library.

Usage

import urllib3
import urllib3.util
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor

def strip_query_params(url: str) -> str:
    return url.split("?")[0]

def span_name_callback(method: str, url: str, headers):
    return urllib3.util.Url(url).path

URLLib3Instrumentor().instrument(
    # Remove all query params from the URL attribute on the span.
    url_filter=strip_query_params,
    # Use the URL's path as the span name.
    span_name_or_callback=span_name_callback
)

http = urllib3.PoolManager()
response = http.request("GET", "https://www.example.org/")

API

class opentelemetry.instrumentation.urllib3.URLLib3Instrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor