opentelemetry-instrumentation-requests 0.46b0__py3-none-any.whl → 0.48b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opentelemetry/instrumentation/requests/__init__.py +51 -29
- opentelemetry/instrumentation/requests/version.py +1 -1
- {opentelemetry_instrumentation_requests-0.46b0.dist-info → opentelemetry_instrumentation_requests-0.48b0.dist-info}/METADATA +5 -4
- opentelemetry_instrumentation_requests-0.48b0.dist-info/RECORD +8 -0
- {opentelemetry_instrumentation_requests-0.46b0.dist-info → opentelemetry_instrumentation_requests-0.48b0.dist-info}/WHEEL +1 -1
- opentelemetry_instrumentation_requests-0.46b0.dist-info/RECORD +0 -8
- {opentelemetry_instrumentation_requests-0.46b0.dist-info → opentelemetry_instrumentation_requests-0.48b0.dist-info}/entry_points.txt +0 -0
- {opentelemetry_instrumentation_requests-0.46b0.dist-info → opentelemetry_instrumentation_requests-0.48b0.dist-info}/licenses/LICENSE +0 -0
@@ -31,6 +31,30 @@ Usage
|
|
31
31
|
Configuration
|
32
32
|
-------------
|
33
33
|
|
34
|
+
Request/Response hooks
|
35
|
+
**********************
|
36
|
+
|
37
|
+
The requests instrumentation supports extending tracing behavior with the help of
|
38
|
+
request and response hooks. These are functions that are called back by the instrumentation
|
39
|
+
right after a Span is created for a request and right before the span is finished processing a response respectively.
|
40
|
+
The hooks can be configured as follows:
|
41
|
+
|
42
|
+
.. code:: python
|
43
|
+
|
44
|
+
# `request_obj` is an instance of requests.PreparedRequest
|
45
|
+
def request_hook(span, request_obj):
|
46
|
+
pass
|
47
|
+
|
48
|
+
# `request_obj` is an instance of requests.PreparedRequest
|
49
|
+
# `response` is an instance of requests.Response
|
50
|
+
def response_hook(span, request_obj, response)
|
51
|
+
pass
|
52
|
+
|
53
|
+
RequestsInstrumentor().instrument(
|
54
|
+
request_hook=request_hook, response_hook=response_hook)
|
55
|
+
)
|
56
|
+
|
57
|
+
|
34
58
|
Exclude lists
|
35
59
|
*************
|
36
60
|
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_REQUESTS_EXCLUDED_URLS``
|
@@ -59,10 +83,6 @@ from requests.sessions import Session
|
|
59
83
|
from requests.structures import CaseInsensitiveDict
|
60
84
|
|
61
85
|
from opentelemetry.instrumentation._semconv import (
|
62
|
-
_METRIC_ATTRIBUTES_CLIENT_DURATION_NAME,
|
63
|
-
_SPAN_ATTRIBUTES_ERROR_TYPE,
|
64
|
-
_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS,
|
65
|
-
_SPAN_ATTRIBUTES_NETWORK_PEER_PORT,
|
66
86
|
_client_duration_attrs_new,
|
67
87
|
_client_duration_attrs_old,
|
68
88
|
_filter_semconv_duration_attrs,
|
@@ -72,7 +92,7 @@ from opentelemetry.instrumentation._semconv import (
|
|
72
92
|
_OpenTelemetryStabilitySignalType,
|
73
93
|
_report_new,
|
74
94
|
_report_old,
|
75
|
-
|
95
|
+
_set_http_host_client,
|
76
96
|
_set_http_method,
|
77
97
|
_set_http_net_peer_name_client,
|
78
98
|
_set_http_network_protocol_version,
|
@@ -91,7 +111,15 @@ from opentelemetry.instrumentation.utils import (
|
|
91
111
|
)
|
92
112
|
from opentelemetry.metrics import Histogram, get_meter
|
93
113
|
from opentelemetry.propagate import inject
|
114
|
+
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
|
115
|
+
from opentelemetry.semconv.attributes.network_attributes import (
|
116
|
+
NETWORK_PEER_ADDRESS,
|
117
|
+
NETWORK_PEER_PORT,
|
118
|
+
)
|
94
119
|
from opentelemetry.semconv.metrics import MetricInstruments
|
120
|
+
from opentelemetry.semconv.metrics.http_metrics import (
|
121
|
+
HTTP_CLIENT_REQUEST_DURATION,
|
122
|
+
)
|
95
123
|
from opentelemetry.trace import SpanKind, Tracer, get_tracer
|
96
124
|
from opentelemetry.trace.span import Span
|
97
125
|
from opentelemetry.trace.status import StatusCode
|
@@ -160,13 +188,19 @@ def _instrument(
|
|
160
188
|
|
161
189
|
span_attributes = {}
|
162
190
|
_set_http_method(
|
163
|
-
span_attributes,
|
191
|
+
span_attributes,
|
192
|
+
method,
|
193
|
+
sanitize_method(method),
|
194
|
+
sem_conv_opt_in_mode,
|
164
195
|
)
|
165
196
|
_set_http_url(span_attributes, url, sem_conv_opt_in_mode)
|
166
197
|
|
167
198
|
metric_labels = {}
|
168
199
|
_set_http_method(
|
169
|
-
metric_labels,
|
200
|
+
metric_labels,
|
201
|
+
method,
|
202
|
+
sanitize_method(method),
|
203
|
+
sem_conv_opt_in_mode,
|
170
204
|
)
|
171
205
|
|
172
206
|
try:
|
@@ -178,22 +212,20 @@ def _instrument(
|
|
178
212
|
metric_labels, parsed_url.scheme, sem_conv_opt_in_mode
|
179
213
|
)
|
180
214
|
if parsed_url.hostname:
|
181
|
-
|
215
|
+
_set_http_host_client(
|
182
216
|
metric_labels, parsed_url.hostname, sem_conv_opt_in_mode
|
183
217
|
)
|
184
218
|
_set_http_net_peer_name_client(
|
185
219
|
metric_labels, parsed_url.hostname, sem_conv_opt_in_mode
|
186
220
|
)
|
187
221
|
if _report_new(sem_conv_opt_in_mode):
|
188
|
-
|
222
|
+
_set_http_host_client(
|
189
223
|
span_attributes,
|
190
224
|
parsed_url.hostname,
|
191
225
|
sem_conv_opt_in_mode,
|
192
226
|
)
|
193
227
|
# Use semconv library when available
|
194
|
-
span_attributes[
|
195
|
-
parsed_url.hostname
|
196
|
-
)
|
228
|
+
span_attributes[NETWORK_PEER_ADDRESS] = parsed_url.hostname
|
197
229
|
if parsed_url.port:
|
198
230
|
_set_http_peer_port_client(
|
199
231
|
metric_labels, parsed_url.port, sem_conv_opt_in_mode
|
@@ -203,9 +235,7 @@ def _instrument(
|
|
203
235
|
span_attributes, parsed_url.port, sem_conv_opt_in_mode
|
204
236
|
)
|
205
237
|
# Use semconv library when available
|
206
|
-
span_attributes[
|
207
|
-
parsed_url.port
|
208
|
-
)
|
238
|
+
span_attributes[NETWORK_PEER_PORT] = parsed_url.port
|
209
239
|
except ValueError:
|
210
240
|
pass
|
211
241
|
|
@@ -250,12 +280,8 @@ def _instrument(
|
|
250
280
|
_report_new(sem_conv_opt_in_mode)
|
251
281
|
and status_code is StatusCode.ERROR
|
252
282
|
):
|
253
|
-
span_attributes[
|
254
|
-
|
255
|
-
)
|
256
|
-
metric_labels[_SPAN_ATTRIBUTES_ERROR_TYPE] = str(
|
257
|
-
result.status_code
|
258
|
-
)
|
283
|
+
span_attributes[ERROR_TYPE] = str(result.status_code)
|
284
|
+
metric_labels[ERROR_TYPE] = str(result.status_code)
|
259
285
|
|
260
286
|
if result.raw is not None:
|
261
287
|
version = getattr(result.raw, "version", None)
|
@@ -278,12 +304,8 @@ def _instrument(
|
|
278
304
|
response_hook(span, request, result)
|
279
305
|
|
280
306
|
if exception is not None and _report_new(sem_conv_opt_in_mode):
|
281
|
-
span.set_attribute(
|
282
|
-
|
283
|
-
)
|
284
|
-
metric_labels[_SPAN_ATTRIBUTES_ERROR_TYPE] = type(
|
285
|
-
exception
|
286
|
-
).__qualname__
|
307
|
+
span.set_attribute(ERROR_TYPE, type(exception).__qualname__)
|
308
|
+
metric_labels[ERROR_TYPE] = type(exception).__qualname__
|
287
309
|
|
288
310
|
if duration_histogram_old is not None:
|
289
311
|
duration_attrs_old = _filter_semconv_duration_attrs(
|
@@ -349,7 +371,7 @@ def get_default_span_name(method):
|
|
349
371
|
Returns:
|
350
372
|
span name
|
351
373
|
"""
|
352
|
-
method = sanitize_method(method.
|
374
|
+
method = sanitize_method(method.strip())
|
353
375
|
if method == "_OTHER":
|
354
376
|
return "HTTP"
|
355
377
|
return method
|
@@ -403,7 +425,7 @@ class RequestsInstrumentor(BaseInstrumentor):
|
|
403
425
|
duration_histogram_new = None
|
404
426
|
if _report_new(semconv_opt_in_mode):
|
405
427
|
duration_histogram_new = meter.create_histogram(
|
406
|
-
name=
|
428
|
+
name=HTTP_CLIENT_REQUEST_DURATION,
|
407
429
|
unit="s",
|
408
430
|
description="Duration of HTTP client requests.",
|
409
431
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: opentelemetry-instrumentation-requests
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.48b0
|
4
4
|
Summary: OpenTelemetry requests instrumentation
|
5
5
|
Project-URL: Homepage, https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
|
6
6
|
Author-email: OpenTelemetry Authors <cncf-opentelemetry-contributors@lists.cncf.io>
|
@@ -15,11 +15,12 @@ Classifier: Programming Language :: Python :: 3.8
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.9
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
19
|
Requires-Python: >=3.8
|
19
20
|
Requires-Dist: opentelemetry-api~=1.12
|
20
|
-
Requires-Dist: opentelemetry-instrumentation==0.
|
21
|
-
Requires-Dist: opentelemetry-semantic-conventions==0.
|
22
|
-
Requires-Dist: opentelemetry-util-http==0.
|
21
|
+
Requires-Dist: opentelemetry-instrumentation==0.48b0
|
22
|
+
Requires-Dist: opentelemetry-semantic-conventions==0.48b0
|
23
|
+
Requires-Dist: opentelemetry-util-http==0.48b0
|
23
24
|
Provides-Extra: instruments
|
24
25
|
Requires-Dist: requests~=2.0; extra == 'instruments'
|
25
26
|
Description-Content-Type: text/x-rst
|
@@ -0,0 +1,8 @@
|
|
1
|
+
opentelemetry/instrumentation/requests/__init__.py,sha256=GGN5ykITzJitPTZJX76PjBUvLxNWXjUx9Ap7UNaV7mM,16623
|
2
|
+
opentelemetry/instrumentation/requests/package.py,sha256=84lK70NyCoRefASXKjU5f4byJhf5qWDL6IdYjch-UTM,679
|
3
|
+
opentelemetry/instrumentation/requests/version.py,sha256=wOX_9uGRBIlLks98mTGJZnnmD1Zez4rGVQNmP23fWEc,608
|
4
|
+
opentelemetry_instrumentation_requests-0.48b0.dist-info/METADATA,sha256=sK117iHYPi22WNMUiJm23pMv7ewyys8pSsznu4v7ioQ,2531
|
5
|
+
opentelemetry_instrumentation_requests-0.48b0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
6
|
+
opentelemetry_instrumentation_requests-0.48b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
|
7
|
+
opentelemetry_instrumentation_requests-0.48b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
8
|
+
opentelemetry_instrumentation_requests-0.48b0.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
opentelemetry/instrumentation/requests/__init__.py,sha256=vOwOPFyTC_QVJyCxdbjgImFmSXaUuQear832eOQgobw,15971
|
2
|
-
opentelemetry/instrumentation/requests/package.py,sha256=84lK70NyCoRefASXKjU5f4byJhf5qWDL6IdYjch-UTM,679
|
3
|
-
opentelemetry/instrumentation/requests/version.py,sha256=asa7q2ly73330-K1Q7vujpvZk7hfhasEZUzSFDPu1N8,608
|
4
|
-
opentelemetry_instrumentation_requests-0.46b0.dist-info/METADATA,sha256=RXSlzKIEUw5rHboRnl0SktLiQJQrzC8KOhtJmjUuIok,2480
|
5
|
-
opentelemetry_instrumentation_requests-0.46b0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
6
|
-
opentelemetry_instrumentation_requests-0.46b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
|
7
|
-
opentelemetry_instrumentation_requests-0.46b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
8
|
-
opentelemetry_instrumentation_requests-0.46b0.dist-info/RECORD,,
|
File without changes
|