opentelemetry-instrumentation-urllib3 0.61b0


pip install opentelemetry-instrumentation-urllib3

  Latest version

Released: Mar 04, 2026


Meta
Author: OpenTelemetry Authors
Requires Python: >=3.9

Classifiers

Development Status
  • 4 - Beta

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

pypi

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

Installation

pip install opentelemetry-instrumentation-urllib3

Usage

import urllib3
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor

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

URLLib3Instrumentor().instrument(
    # Remove all query params from the URL attribute on the span.
    url_filter=strip_query_params,
)

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

Configuration

Request/Response hooks

The urllib3 instrumentation supports extending tracing behavior with the help of request and response hooks. These are functions that are called back by the instrumentation right after a Span is created for a request and right before the span is finished processing a response respectively. The hooks can be configured as follows:

from typing import Any

from urllib3.connectionpool import HTTPConnectionPool
from urllib3.response import HTTPResponse

from opentelemetry.instrumentation.urllib3 import RequestInfo, URLLib3Instrumentor
from opentelemetry.trace import Span

def request_hook(
    span: Span,
    pool: HTTPConnectionPool,
    request_info: RequestInfo,
) -> Any:
    pass

def response_hook(
    span: Span,
    pool: HTTPConnectionPool,
    response: HTTPResponse,
) -> Any:
    pass

URLLib3Instrumentor().instrument(
    request_hook=request_hook,
    response_hook=response_hook,
)

Exclude lists

To exclude certain URLs from being tracked, set the environment variable OTEL_PYTHON_URLLIB3_EXCLUDED_URLS (or OTEL_PYTHON_EXCLUDED_URLS as fallback) with comma delimited regexes representing which URLs to exclude.

For example,

export OTEL_PYTHON_URLLIB3_EXCLUDED_URLS="client/.*/info,healthcheck"

will exclude requests such as https://site/client/123/info and https://site/xyz/healthcheck.

References

0.61b0 Mar 04, 2026
0.60b1 Dec 11, 2025
0.60b0 Dec 03, 2025
0.59b0 Oct 16, 2025
0.58b0 Sep 11, 2025
0.57b0 Jul 29, 2025
0.56b0 Jul 11, 2025
0.55b1 Jun 10, 2025
0.55b0 Jun 04, 2025
0.54b1 May 16, 2025
0.54b0 May 09, 2025
0.53b1 Apr 15, 2025
0.53b0 Apr 10, 2025
0.52b1 Mar 20, 2025
0.52b0 Mar 12, 2025
0.51b0 Feb 04, 2025
0.50b0 Dec 11, 2024
0.49b2 Nov 18, 2024
0.49b1 Nov 08, 2024
0.49b0 Nov 05, 2024
0.48b0 Aug 28, 2024
0.47b0 Jul 25, 2024
0.46b0 May 31, 2024
0.45b0 Mar 28, 2024
0.44b0 Feb 23, 2024
0.43b0 Dec 19, 2023
0.42b0 Nov 08, 2023
0.41b0 Sep 11, 2023
0.40b0 Jul 13, 2023
0.39b0 May 19, 2023
0.38b0 Mar 22, 2023
0.37b0 Feb 17, 2023
0.36b0 Dec 09, 2022
0.35b0 Nov 03, 2022
0.34b0 Sep 27, 2022
0.33b0 Aug 09, 2022
0.32b0 Jul 04, 2022
0.31b0 May 17, 2022
0.30b1 Apr 21, 2022
0.30b0 Apr 18, 2022
0.29b0 Mar 11, 2022
0.28b1 Jan 31, 2022
0.28b0 Jan 26, 2022
0.27b0 Dec 17, 2021
0.26b1 Nov 11, 2021
0.25b2 Oct 19, 2021
0.25b1 Oct 18, 2021
0.25b0 Oct 13, 2021
0.24b0 Aug 26, 2021
0.23b2 Jul 28, 2021
0.23b0 Jul 21, 2021
0.22b0 Jun 02, 2021
0.21b0 May 12, 2021
0.20b0 Apr 20, 2021
Extras:
Dependencies:
opentelemetry-api (~=1.12)
opentelemetry-instrumentation (==0.61b0)
opentelemetry-semantic-conventions (==0.61b0)
opentelemetry-util-http (==0.61b0)
wrapt (<2.0.0,>=1.0.0)