opentelemetry-instrumentation-urllib3

OpenTelemetry urllib3 instrumentation

58 个版本 Python >=3.10
安装
pip install opentelemetry-instrumentation-urllib3
poetry add opentelemetry-instrumentation-urllib3
pipenv install opentelemetry-instrumentation-urllib3
conda install opentelemetry-instrumentation-urllib3
描述

OpenTelemetry urllib3 Instrumentation

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-urllib3.svg :target: https://pypi.org/project/opentelemetry-instrumentation-urllib3/

This library allows tracing HTTP requests made by the urllib3 <https://urllib3.readthedocs.io/>_ library.

Installation

::

 pip install opentelemetry-instrumentation-urllib3

Usage

.. code-block:: python

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:

.. code:: python

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

  • OpenTelemetry urllib3 Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/urllib3/urllib3.html>_
  • OpenTelemetry Project <https://opentelemetry.io/>_
  • OpenTelemetry Python Examples <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples>_
版本列表
0.63b1 2026-05-21
0.63b0 2026-05-19
0.62b1 2026-04-24
0.62b0 2026-04-09
0.61b0 2026-03-04
0.60b1 2025-12-11
0.60b0 2025-12-03
0.59b0 2025-10-16
0.58b0 2025-09-11
0.57b0 2025-07-29
0.56b0 2025-07-11
0.55b1 2025-06-10
0.55b0 2025-06-04
0.54b1 2025-05-16
0.54b0 2025-05-09
0.53b1 2025-04-15
0.53b0 2025-04-10
0.52b1 2025-03-20
0.52b0 2025-03-12
0.51b0 2025-02-04
0.50b0 2024-12-11
0.49b2 2024-11-18
0.49b1 2024-11-08
0.49b0 2024-11-05
0.48b0 2024-08-28
0.47b0 2024-07-25
0.46b0 2024-05-31
0.45b0 2024-03-28
0.44b0 2024-02-23
0.43b0 2023-12-19
0.42b0 2023-11-08
0.41b0 2023-09-11
0.40b0 2023-07-13
0.39b0 2023-05-19
0.38b0 2023-03-22
0.37b0 2023-02-17
0.36b0 2022-12-09
0.35b0 2022-11-03
0.34b0 2022-09-27
0.33b0 2022-08-09
0.32b0 2022-07-04
0.31b0 2022-05-17
0.30b1 2022-04-21
0.30b0 2022-04-18
0.29b0 2022-03-11
0.28b1 2022-01-31
0.28b0 2022-01-26
0.27b0 2021-12-17
0.26b1 2021-11-11
0.25b2 2021-10-19
0.25b1 2021-10-18
0.25b0 2021-10-13
0.24b0 2021-08-26
0.23b2 2021-07-28
0.23b0 2021-07-21
0.22b0 2021-06-02
0.21b0 2021-05-12
0.20b0 2021-04-20