opentelemetry-instrumentation-requests 0.50b0__py3-none-any.whl → 0.52b0__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 +54 -37
- opentelemetry/instrumentation/requests/py.typed +0 -0
- opentelemetry/instrumentation/requests/version.py +1 -1
- {opentelemetry_instrumentation_requests-0.50b0.dist-info → opentelemetry_instrumentation_requests-0.52b0.dist-info}/METADATA +9 -6
- opentelemetry_instrumentation_requests-0.52b0.dist-info/RECORD +9 -0
- {opentelemetry_instrumentation_requests-0.50b0.dist-info → opentelemetry_instrumentation_requests-0.52b0.dist-info}/WHEEL +1 -1
- opentelemetry_instrumentation_requests-0.50b0.dist-info/RECORD +0 -8
- {opentelemetry_instrumentation_requests-0.50b0.dist-info → opentelemetry_instrumentation_requests-0.52b0.dist-info}/entry_points.txt +0 -0
- {opentelemetry_instrumentation_requests-0.50b0.dist-info → opentelemetry_instrumentation_requests-0.52b0.dist-info}/licenses/LICENSE +0 -0
@@ -41,20 +41,22 @@ The hooks can be configured as follows:
|
|
41
41
|
|
42
42
|
.. code:: python
|
43
43
|
|
44
|
+
import requests
|
45
|
+
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
46
|
+
|
44
47
|
# `request_obj` is an instance of requests.PreparedRequest
|
45
48
|
def request_hook(span, request_obj):
|
46
49
|
pass
|
47
50
|
|
48
51
|
# `request_obj` is an instance of requests.PreparedRequest
|
49
52
|
# `response` is an instance of requests.Response
|
50
|
-
def response_hook(span, request_obj, response)
|
53
|
+
def response_hook(span, request_obj, response):
|
51
54
|
pass
|
52
55
|
|
53
56
|
RequestsInstrumentor().instrument(
|
54
|
-
request_hook=request_hook, response_hook=response_hook
|
57
|
+
request_hook=request_hook, response_hook=response_hook
|
55
58
|
)
|
56
59
|
|
57
|
-
|
58
60
|
Exclude lists
|
59
61
|
*************
|
60
62
|
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_REQUESTS_EXCLUDED_URLS``
|
@@ -72,10 +74,12 @@ API
|
|
72
74
|
---
|
73
75
|
"""
|
74
76
|
|
77
|
+
from __future__ import annotations
|
78
|
+
|
75
79
|
import functools
|
76
80
|
import types
|
77
81
|
from timeit import default_timer
|
78
|
-
from typing import Callable, Collection, Optional
|
82
|
+
from typing import Any, Callable, Collection, Optional
|
79
83
|
from urllib.parse import urlparse
|
80
84
|
|
81
85
|
from requests.models import PreparedRequest, Response
|
@@ -87,7 +91,6 @@ from opentelemetry.instrumentation._semconv import (
|
|
87
91
|
_client_duration_attrs_old,
|
88
92
|
_filter_semconv_duration_attrs,
|
89
93
|
_get_schema_url,
|
90
|
-
_HTTPStabilityMode,
|
91
94
|
_OpenTelemetrySemanticConventionStability,
|
92
95
|
_OpenTelemetryStabilitySignalType,
|
93
96
|
_report_new,
|
@@ -98,14 +101,14 @@ from opentelemetry.instrumentation._semconv import (
|
|
98
101
|
_set_http_network_protocol_version,
|
99
102
|
_set_http_peer_port_client,
|
100
103
|
_set_http_scheme,
|
101
|
-
_set_http_status_code,
|
102
104
|
_set_http_url,
|
105
|
+
_set_status,
|
106
|
+
_StabilityMode,
|
103
107
|
)
|
104
108
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
105
109
|
from opentelemetry.instrumentation.requests.package import _instruments
|
106
110
|
from opentelemetry.instrumentation.requests.version import __version__
|
107
111
|
from opentelemetry.instrumentation.utils import (
|
108
|
-
http_status_to_status_code,
|
109
112
|
is_http_instrumentation_enabled,
|
110
113
|
suppress_http_instrumentation,
|
111
114
|
)
|
@@ -122,7 +125,6 @@ from opentelemetry.semconv.metrics.http_metrics import (
|
|
122
125
|
)
|
123
126
|
from opentelemetry.trace import SpanKind, Tracer, get_tracer
|
124
127
|
from opentelemetry.trace.span import Span
|
125
|
-
from opentelemetry.trace.status import StatusCode
|
126
128
|
from opentelemetry.util.http import (
|
127
129
|
ExcludeList,
|
128
130
|
get_excluded_urls,
|
@@ -138,6 +140,32 @@ _RequestHookT = Optional[Callable[[Span, PreparedRequest], None]]
|
|
138
140
|
_ResponseHookT = Optional[Callable[[Span, PreparedRequest, Response], None]]
|
139
141
|
|
140
142
|
|
143
|
+
def _set_http_status_code_attribute(
|
144
|
+
span,
|
145
|
+
status_code,
|
146
|
+
metric_attributes=None,
|
147
|
+
sem_conv_opt_in_mode=_StabilityMode.DEFAULT,
|
148
|
+
):
|
149
|
+
status_code_str = str(status_code)
|
150
|
+
try:
|
151
|
+
status_code = int(status_code)
|
152
|
+
except ValueError:
|
153
|
+
status_code = -1
|
154
|
+
if metric_attributes is None:
|
155
|
+
metric_attributes = {}
|
156
|
+
# When we have durations we should set metrics only once
|
157
|
+
# Also the decision to include status code on a histogram should
|
158
|
+
# not be dependent on tracing decisions.
|
159
|
+
_set_status(
|
160
|
+
span,
|
161
|
+
metric_attributes,
|
162
|
+
status_code,
|
163
|
+
status_code_str,
|
164
|
+
server_span=False,
|
165
|
+
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
|
166
|
+
)
|
167
|
+
|
168
|
+
|
141
169
|
# pylint: disable=unused-argument
|
142
170
|
# pylint: disable=R0915
|
143
171
|
def _instrument(
|
@@ -146,8 +174,8 @@ def _instrument(
|
|
146
174
|
duration_histogram_new: Histogram,
|
147
175
|
request_hook: _RequestHookT = None,
|
148
176
|
response_hook: _ResponseHookT = None,
|
149
|
-
excluded_urls: ExcludeList = None,
|
150
|
-
sem_conv_opt_in_mode:
|
177
|
+
excluded_urls: ExcludeList | None = None,
|
178
|
+
sem_conv_opt_in_mode: _StabilityMode = _StabilityMode.DEFAULT,
|
151
179
|
):
|
152
180
|
"""Enables tracing of all requests calls that go through
|
153
181
|
:code:`requests.session.Session.request` (this includes
|
@@ -164,7 +192,9 @@ def _instrument(
|
|
164
192
|
|
165
193
|
# pylint: disable-msg=too-many-locals,too-many-branches
|
166
194
|
@functools.wraps(wrapped_send)
|
167
|
-
def instrumented_send(
|
195
|
+
def instrumented_send(
|
196
|
+
self: Session, request: PreparedRequest, **kwargs: Any
|
197
|
+
):
|
168
198
|
if excluded_urls and excluded_urls.url_disabled(request.url):
|
169
199
|
return wrapped_send(self, request, **kwargs)
|
170
200
|
|
@@ -263,25 +293,12 @@ def _instrument(
|
|
263
293
|
|
264
294
|
if isinstance(result, Response):
|
265
295
|
span_attributes = {}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
_set_http_status_code(
|
273
|
-
metric_labels, result.status_code, sem_conv_opt_in_mode
|
274
|
-
)
|
275
|
-
status_code = http_status_to_status_code(
|
276
|
-
result.status_code
|
277
|
-
)
|
278
|
-
span.set_status(status_code)
|
279
|
-
if (
|
280
|
-
_report_new(sem_conv_opt_in_mode)
|
281
|
-
and status_code is StatusCode.ERROR
|
282
|
-
):
|
283
|
-
span_attributes[ERROR_TYPE] = str(result.status_code)
|
284
|
-
metric_labels[ERROR_TYPE] = str(result.status_code)
|
296
|
+
_set_http_status_code_attribute(
|
297
|
+
span,
|
298
|
+
result.status_code,
|
299
|
+
metric_labels,
|
300
|
+
sem_conv_opt_in_mode,
|
301
|
+
)
|
285
302
|
|
286
303
|
if result.raw is not None:
|
287
304
|
version = getattr(result.raw, "version", None)
|
@@ -312,7 +329,7 @@ def _instrument(
|
|
312
329
|
metric_labels,
|
313
330
|
_client_duration_attrs_old,
|
314
331
|
_client_duration_attrs_new,
|
315
|
-
|
332
|
+
_StabilityMode.DEFAULT,
|
316
333
|
)
|
317
334
|
duration_histogram_old.record(
|
318
335
|
max(round(elapsed_time * 1000), 0),
|
@@ -323,7 +340,7 @@ def _instrument(
|
|
323
340
|
metric_labels,
|
324
341
|
_client_duration_attrs_old,
|
325
342
|
_client_duration_attrs_new,
|
326
|
-
|
343
|
+
_StabilityMode.HTTP,
|
327
344
|
)
|
328
345
|
duration_histogram_new.record(
|
329
346
|
elapsed_time, attributes=duration_attrs_new
|
@@ -345,7 +362,7 @@ def _uninstrument():
|
|
345
362
|
_uninstrument_from(Session)
|
346
363
|
|
347
364
|
|
348
|
-
def _uninstrument_from(instr_root, restore_as_bound_func=False):
|
365
|
+
def _uninstrument_from(instr_root, restore_as_bound_func: bool = False):
|
349
366
|
for instr_func_name in ("request", "send"):
|
350
367
|
instr_func = getattr(instr_root, instr_func_name)
|
351
368
|
if not getattr(
|
@@ -361,7 +378,7 @@ def _uninstrument_from(instr_root, restore_as_bound_func=False):
|
|
361
378
|
setattr(instr_root, instr_func_name, original)
|
362
379
|
|
363
380
|
|
364
|
-
def get_default_span_name(method):
|
381
|
+
def get_default_span_name(method: str) -> str:
|
365
382
|
"""
|
366
383
|
Default implementation for name_callback, returns HTTP {method_name}.
|
367
384
|
https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name
|
@@ -385,7 +402,7 @@ class RequestsInstrumentor(BaseInstrumentor):
|
|
385
402
|
def instrumentation_dependencies(self) -> Collection[str]:
|
386
403
|
return _instruments
|
387
404
|
|
388
|
-
def _instrument(self, **kwargs):
|
405
|
+
def _instrument(self, **kwargs: Any):
|
389
406
|
"""Instruments requests module
|
390
407
|
|
391
408
|
Args:
|
@@ -443,10 +460,10 @@ class RequestsInstrumentor(BaseInstrumentor):
|
|
443
460
|
sem_conv_opt_in_mode=semconv_opt_in_mode,
|
444
461
|
)
|
445
462
|
|
446
|
-
def _uninstrument(self, **kwargs):
|
463
|
+
def _uninstrument(self, **kwargs: Any):
|
447
464
|
_uninstrument()
|
448
465
|
|
449
466
|
@staticmethod
|
450
|
-
def uninstrument_session(session):
|
467
|
+
def uninstrument_session(session: Session):
|
451
468
|
"""Disables instrumentation on the session object."""
|
452
469
|
_uninstrument_from(session, restore_as_bound_func=True)
|
File without changes
|
@@ -1,10 +1,12 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: opentelemetry-instrumentation-requests
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.52b0
|
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
|
+
Project-URL: Repository, https://github.com/open-telemetry/opentelemetry-python-contrib
|
6
7
|
Author-email: OpenTelemetry Authors <cncf-opentelemetry-contributors@lists.cncf.io>
|
7
|
-
License: Apache-2.0
|
8
|
+
License-Expression: Apache-2.0
|
9
|
+
License-File: LICENSE
|
8
10
|
Classifier: Development Status :: 4 - Beta
|
9
11
|
Classifier: Intended Audience :: Developers
|
10
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
@@ -15,11 +17,12 @@ Classifier: Programming Language :: Python :: 3.9
|
|
15
17
|
Classifier: Programming Language :: Python :: 3.10
|
16
18
|
Classifier: Programming Language :: Python :: 3.11
|
17
19
|
Classifier: Programming Language :: Python :: 3.12
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
18
21
|
Requires-Python: >=3.8
|
19
22
|
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.
|
23
|
+
Requires-Dist: opentelemetry-instrumentation==0.52b0
|
24
|
+
Requires-Dist: opentelemetry-semantic-conventions==0.52b0
|
25
|
+
Requires-Dist: opentelemetry-util-http==0.52b0
|
23
26
|
Provides-Extra: instruments
|
24
27
|
Requires-Dist: requests~=2.0; extra == 'instruments'
|
25
28
|
Description-Content-Type: text/x-rst
|
@@ -0,0 +1,9 @@
|
|
1
|
+
opentelemetry/instrumentation/requests/__init__.py,sha256=Cjqt-1i4X6MhTS6FHe9KoooI9rsaTFGvgXZ_RzFjv1w,16781
|
2
|
+
opentelemetry/instrumentation/requests/package.py,sha256=84lK70NyCoRefASXKjU5f4byJhf5qWDL6IdYjch-UTM,679
|
3
|
+
opentelemetry/instrumentation/requests/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
opentelemetry/instrumentation/requests/version.py,sha256=8ybzJrIcr5CRW9fxlL7vXcvj3IIncnVl6eHpEEIxEYk,608
|
5
|
+
opentelemetry_instrumentation_requests-0.52b0.dist-info/METADATA,sha256=iw_jfaZX8UwOmHzaNM9F7SqTvqJgwlqyIlDjIlaskxg,2670
|
6
|
+
opentelemetry_instrumentation_requests-0.52b0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
opentelemetry_instrumentation_requests-0.52b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
|
8
|
+
opentelemetry_instrumentation_requests-0.52b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
9
|
+
opentelemetry_instrumentation_requests-0.52b0.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
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=sBsbV8VQNTte60quPySrr3hMzVnRCO8AnGlwnGPP60o,608
|
4
|
-
opentelemetry_instrumentation_requests-0.50b0.dist-info/METADATA,sha256=R8x_4qInbkbmcBIY0q3RamYqJXs7YHvacnIMqUvfVYI,2498
|
5
|
-
opentelemetry_instrumentation_requests-0.50b0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
6
|
-
opentelemetry_instrumentation_requests-0.50b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
|
7
|
-
opentelemetry_instrumentation_requests-0.50b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
8
|
-
opentelemetry_instrumentation_requests-0.50b0.dist-info/RECORD,,
|
File without changes
|