opentelemetry-instrumentation-requests 0.44b0__tar.gz → 0.46b0__tar.gz
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-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/LICENSE +1 -1
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/PKG-INFO +5 -9
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/pyproject.toml +3 -8
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/src/opentelemetry/instrumentation/requests/__init__.py +45 -32
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/src/opentelemetry/instrumentation/requests/package.py +2 -0
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/src/opentelemetry/instrumentation/requests/version.py +1 -1
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/tests/test_requests_integration.py +3 -4
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/.gitignore +0 -0
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/README.rst +0 -0
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/tests/__init__.py +0 -0
- {opentelemetry_instrumentation_requests-0.44b0 → opentelemetry_instrumentation_requests-0.46b0}/tests/test_requests_ip_support.py +0 -0
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: opentelemetry-instrumentation-requests
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.46b0
|
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>
|
@@ -17,15 +17,11 @@ Classifier: Programming Language :: Python :: 3.10
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
18
18
|
Requires-Python: >=3.8
|
19
19
|
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.
|
20
|
+
Requires-Dist: opentelemetry-instrumentation==0.46b0
|
21
|
+
Requires-Dist: opentelemetry-semantic-conventions==0.46b0
|
22
|
+
Requires-Dist: opentelemetry-util-http==0.46b0
|
23
23
|
Provides-Extra: instruments
|
24
24
|
Requires-Dist: requests~=2.0; extra == 'instruments'
|
25
|
-
Provides-Extra: test
|
26
|
-
Requires-Dist: httpretty~=1.0; extra == 'test'
|
27
|
-
Requires-Dist: opentelemetry-instrumentation-requests[instruments]; extra == 'test'
|
28
|
-
Requires-Dist: opentelemetry-test-utils==0.44b0; extra == 'test'
|
29
25
|
Description-Content-Type: text/x-rst
|
30
26
|
|
31
27
|
OpenTelemetry Requests Instrumentation
|
@@ -25,20 +25,15 @@ classifiers = [
|
|
25
25
|
]
|
26
26
|
dependencies = [
|
27
27
|
"opentelemetry-api ~= 1.12",
|
28
|
-
"opentelemetry-instrumentation == 0.
|
29
|
-
"opentelemetry-semantic-conventions == 0.
|
30
|
-
"opentelemetry-util-http == 0.
|
28
|
+
"opentelemetry-instrumentation == 0.46b0",
|
29
|
+
"opentelemetry-semantic-conventions == 0.46b0",
|
30
|
+
"opentelemetry-util-http == 0.46b0",
|
31
31
|
]
|
32
32
|
|
33
33
|
[project.optional-dependencies]
|
34
34
|
instruments = [
|
35
35
|
"requests ~= 2.0",
|
36
36
|
]
|
37
|
-
test = [
|
38
|
-
"opentelemetry-instrumentation-requests[instruments]",
|
39
|
-
"httpretty ~= 1.0",
|
40
|
-
"opentelemetry-test-utils == 0.44b0",
|
41
|
-
]
|
42
37
|
|
43
38
|
[project.entry-points.opentelemetry_instrumentor]
|
44
39
|
requests = "opentelemetry.instrumentation.requests:RequestsInstrumentor"
|
@@ -63,18 +63,20 @@ from opentelemetry.instrumentation._semconv import (
|
|
63
63
|
_SPAN_ATTRIBUTES_ERROR_TYPE,
|
64
64
|
_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS,
|
65
65
|
_SPAN_ATTRIBUTES_NETWORK_PEER_PORT,
|
66
|
-
|
66
|
+
_client_duration_attrs_new,
|
67
|
+
_client_duration_attrs_old,
|
68
|
+
_filter_semconv_duration_attrs,
|
67
69
|
_get_schema_url,
|
70
|
+
_HTTPStabilityMode,
|
68
71
|
_OpenTelemetrySemanticConventionStability,
|
69
|
-
_OpenTelemetryStabilityMode,
|
70
72
|
_OpenTelemetryStabilitySignalType,
|
71
73
|
_report_new,
|
72
74
|
_report_old,
|
73
|
-
|
75
|
+
_set_http_host,
|
74
76
|
_set_http_method,
|
75
|
-
|
77
|
+
_set_http_net_peer_name_client,
|
76
78
|
_set_http_network_protocol_version,
|
77
|
-
|
79
|
+
_set_http_peer_port_client,
|
78
80
|
_set_http_scheme,
|
79
81
|
_set_http_status_code,
|
80
82
|
_set_http_url,
|
@@ -105,7 +107,7 @@ from opentelemetry.util.http.httplib import set_ip_on_next_http_connection
|
|
105
107
|
_excluded_urls_from_env = get_excluded_urls("REQUESTS")
|
106
108
|
|
107
109
|
_RequestHookT = Optional[Callable[[Span, PreparedRequest], None]]
|
108
|
-
_ResponseHookT = Optional[Callable[[Span, PreparedRequest], None]]
|
110
|
+
_ResponseHookT = Optional[Callable[[Span, PreparedRequest, Response], None]]
|
109
111
|
|
110
112
|
|
111
113
|
# pylint: disable=unused-argument
|
@@ -117,7 +119,7 @@ def _instrument(
|
|
117
119
|
request_hook: _RequestHookT = None,
|
118
120
|
response_hook: _ResponseHookT = None,
|
119
121
|
excluded_urls: ExcludeList = None,
|
120
|
-
sem_conv_opt_in_mode:
|
122
|
+
sem_conv_opt_in_mode: _HTTPStabilityMode = _HTTPStabilityMode.DEFAULT,
|
121
123
|
):
|
122
124
|
"""Enables tracing of all requests calls that go through
|
123
125
|
:code:`requests.session.Session.request` (this includes
|
@@ -170,38 +172,40 @@ def _instrument(
|
|
170
172
|
try:
|
171
173
|
parsed_url = urlparse(url)
|
172
174
|
if parsed_url.scheme:
|
173
|
-
|
174
|
-
|
175
|
-
|
175
|
+
if _report_old(sem_conv_opt_in_mode):
|
176
|
+
# TODO: Support opt-in for url.scheme in new semconv
|
177
|
+
_set_http_scheme(
|
178
|
+
metric_labels, parsed_url.scheme, sem_conv_opt_in_mode
|
179
|
+
)
|
176
180
|
if parsed_url.hostname:
|
177
|
-
|
181
|
+
_set_http_host(
|
178
182
|
metric_labels, parsed_url.hostname, sem_conv_opt_in_mode
|
179
183
|
)
|
180
|
-
|
184
|
+
_set_http_net_peer_name_client(
|
181
185
|
metric_labels, parsed_url.hostname, sem_conv_opt_in_mode
|
182
186
|
)
|
183
187
|
if _report_new(sem_conv_opt_in_mode):
|
184
|
-
|
188
|
+
_set_http_host(
|
185
189
|
span_attributes,
|
186
190
|
parsed_url.hostname,
|
187
191
|
sem_conv_opt_in_mode,
|
188
192
|
)
|
189
193
|
# Use semconv library when available
|
190
|
-
span_attributes[
|
191
|
-
|
192
|
-
|
194
|
+
span_attributes[_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS] = (
|
195
|
+
parsed_url.hostname
|
196
|
+
)
|
193
197
|
if parsed_url.port:
|
194
|
-
|
198
|
+
_set_http_peer_port_client(
|
195
199
|
metric_labels, parsed_url.port, sem_conv_opt_in_mode
|
196
200
|
)
|
197
201
|
if _report_new(sem_conv_opt_in_mode):
|
198
|
-
|
202
|
+
_set_http_peer_port_client(
|
199
203
|
span_attributes, parsed_url.port, sem_conv_opt_in_mode
|
200
204
|
)
|
201
205
|
# Use semconv library when available
|
202
|
-
span_attributes[
|
203
|
-
|
204
|
-
|
206
|
+
span_attributes[_SPAN_ATTRIBUTES_NETWORK_PEER_PORT] = (
|
207
|
+
parsed_url.port
|
208
|
+
)
|
205
209
|
except ValueError:
|
206
210
|
pass
|
207
211
|
|
@@ -225,9 +229,7 @@ def _instrument(
|
|
225
229
|
exception = exc
|
226
230
|
result = getattr(exc, "response", None)
|
227
231
|
finally:
|
228
|
-
elapsed_time = max(
|
229
|
-
round((default_timer() - start_time) * 1000), 0
|
230
|
-
)
|
232
|
+
elapsed_time = max(default_timer() - start_time, 0)
|
231
233
|
|
232
234
|
if isinstance(result, Response):
|
233
235
|
span_attributes = {}
|
@@ -284,16 +286,22 @@ def _instrument(
|
|
284
286
|
).__qualname__
|
285
287
|
|
286
288
|
if duration_histogram_old is not None:
|
287
|
-
duration_attrs_old =
|
288
|
-
metric_labels,
|
289
|
+
duration_attrs_old = _filter_semconv_duration_attrs(
|
290
|
+
metric_labels,
|
291
|
+
_client_duration_attrs_old,
|
292
|
+
_client_duration_attrs_new,
|
293
|
+
_HTTPStabilityMode.DEFAULT,
|
289
294
|
)
|
290
295
|
duration_histogram_old.record(
|
291
296
|
max(round(elapsed_time * 1000), 0),
|
292
297
|
attributes=duration_attrs_old,
|
293
298
|
)
|
294
299
|
if duration_histogram_new is not None:
|
295
|
-
duration_attrs_new =
|
296
|
-
metric_labels,
|
300
|
+
duration_attrs_new = _filter_semconv_duration_attrs(
|
301
|
+
metric_labels,
|
302
|
+
_client_duration_attrs_old,
|
303
|
+
_client_duration_attrs_new,
|
304
|
+
_HTTPStabilityMode.HTTP,
|
297
305
|
)
|
298
306
|
duration_histogram_new.record(
|
299
307
|
elapsed_time, attributes=duration_attrs_new
|
@@ -341,7 +349,10 @@ def get_default_span_name(method):
|
|
341
349
|
Returns:
|
342
350
|
span name
|
343
351
|
"""
|
344
|
-
|
352
|
+
method = sanitize_method(method.upper().strip())
|
353
|
+
if method == "_OTHER":
|
354
|
+
return "HTTP"
|
355
|
+
return method
|
345
356
|
|
346
357
|
|
347
358
|
class RequestsInstrumentor(BaseInstrumentor):
|
@@ -402,9 +413,11 @@ class RequestsInstrumentor(BaseInstrumentor):
|
|
402
413
|
duration_histogram_new,
|
403
414
|
request_hook=kwargs.get("request_hook"),
|
404
415
|
response_hook=kwargs.get("response_hook"),
|
405
|
-
excluded_urls=
|
406
|
-
|
407
|
-
|
416
|
+
excluded_urls=(
|
417
|
+
_excluded_urls_from_env
|
418
|
+
if excluded_urls is None
|
419
|
+
else parse_excluded_urls(excluded_urls)
|
420
|
+
),
|
408
421
|
sem_conv_opt_in_mode=semconv_opt_in_mode,
|
409
422
|
)
|
410
423
|
|
@@ -23,10 +23,10 @@ from requests.models import Response
|
|
23
23
|
import opentelemetry.instrumentation.requests
|
24
24
|
from opentelemetry import trace
|
25
25
|
from opentelemetry.instrumentation._semconv import (
|
26
|
-
_OTEL_SEMCONV_STABILITY_OPT_IN_KEY,
|
27
26
|
_SPAN_ATTRIBUTES_ERROR_TYPE,
|
28
27
|
_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS,
|
29
28
|
_SPAN_ATTRIBUTES_NETWORK_PEER_PORT,
|
29
|
+
OTEL_SEMCONV_STABILITY_OPT_IN,
|
30
30
|
_OpenTelemetrySemanticConventionStability,
|
31
31
|
)
|
32
32
|
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
@@ -88,7 +88,7 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|
88
88
|
"os.environ",
|
89
89
|
{
|
90
90
|
"OTEL_PYTHON_REQUESTS_EXCLUDED_URLS": "http://localhost/env_excluded_arg/123,env_excluded_noarg",
|
91
|
-
|
91
|
+
OTEL_SEMCONV_STABILITY_OPT_IN: sem_conv_mode,
|
92
92
|
},
|
93
93
|
)
|
94
94
|
|
@@ -524,7 +524,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|
524
524
|
self.perform_request(url_with_port)
|
525
525
|
|
526
526
|
span = self.assert_span()
|
527
|
-
print(span.attributes)
|
528
527
|
self.assertEqual(
|
529
528
|
span.attributes,
|
530
529
|
{
|
@@ -671,7 +670,7 @@ class TestRequestsIntergrationMetric(TestBase):
|
|
671
670
|
self.env_patch = mock.patch.dict(
|
672
671
|
"os.environ",
|
673
672
|
{
|
674
|
-
|
673
|
+
OTEL_SEMCONV_STABILITY_OPT_IN: sem_conv_mode,
|
675
674
|
},
|
676
675
|
)
|
677
676
|
self.env_patch.start()
|
File without changes
|
File without changes
|
File without changes
|