@@ -16,6 +16,24 @@ Installation
1616
1717 pip install opentelemetry-instrumentation-urllib3
1818
19+ Usage
20+ -----
21+ .. code-block :: python
22+
23+ import urllib3
24+ from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
25+
26+ def strip_query_params (url : str ) -> str :
27+ return url.split(" ?" )[0 ]
28+
29+ URLLib3Instrumentor().instrument(
30+ # Remove all query params from the URL attribute on the span.
31+ url_filter = strip_query_params,
32+ )
33+
34+ http = urllib3.PoolManager()
35+ response = http.request(" GET" , " https://www.example.org/" )
36+
1937 Configuration
2038-------------
2139
@@ -29,17 +47,31 @@ The hooks can be configured as follows:
2947
3048.. code :: python
3149
32- # `request` is an instance of urllib3.connectionpool.HTTPConnectionPool
33- def request_hook (span , request ):
50+ from typing import Any
51+
52+ from urllib3.connectionpool import HTTPConnectionPool
53+ from urllib3.response import HTTPResponse
54+
55+ from opentelemetry.instrumentation.urllib3 import RequestInfo, URLLib3Instrumentor
56+ from opentelemetry.trace import Span
57+
58+ def request_hook (
59+ span : Span,
60+ pool : HTTPConnectionPool,
61+ request_info : RequestInfo,
62+ ) -> Any:
3463 pass
3564
36- # `request` is an instance of urllib3.connectionpool.HTTPConnectionPool
37- # `response` is an instance of urllib3.response.HTTPResponse
38- def response_hook (span , request , response ):
65+ def response_hook (
66+ span : Span,
67+ pool : HTTPConnectionPool,
68+ response : HTTPResponse,
69+ ) -> Any:
3970 pass
4071
4172 URLLib3Instrumentor().instrument(
42- request_hook = request_hook, response_hook = response_hook
73+ request_hook = request_hook,
74+ response_hook = response_hook
4375 )
4476
4577 Exclude lists
0 commit comments