@@ -16,6 +16,24 @@ Installation
16
16
17
17
pip install opentelemetry-instrumentation-urllib3
18
18
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
+
19
37
Configuration
20
38
-------------
21
39
@@ -29,17 +47,31 @@ The hooks can be configured as follows:
29
47
30
48
.. code :: python
31
49
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:
34
63
pass
35
64
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:
39
70
pass
40
71
41
72
URLLib3Instrumentor().instrument(
42
- request_hook = request_hook, response_hook = response_hook
73
+ request_hook = request_hook,
74
+ response_hook = response_hook,
43
75
)
44
76
45
77
Exclude lists
0 commit comments