opentelemetry-instrumentation-requests 0.44b0__py3-none-any.whl → 0.46b0__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.
@@ -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
- _filter_duration_attrs,
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
- _set_http_hostname,
75
+ _set_http_host,
74
76
  _set_http_method,
75
- _set_http_net_peer_name,
77
+ _set_http_net_peer_name_client,
76
78
  _set_http_network_protocol_version,
77
- _set_http_port,
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: _OpenTelemetryStabilityMode = _OpenTelemetryStabilityMode.DEFAULT,
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
- _set_http_scheme(
174
- metric_labels, parsed_url.scheme, sem_conv_opt_in_mode
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
- _set_http_hostname(
181
+ _set_http_host(
178
182
  metric_labels, parsed_url.hostname, sem_conv_opt_in_mode
179
183
  )
180
- _set_http_net_peer_name(
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
- _set_http_hostname(
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
- _SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS
192
- ] = parsed_url.hostname
194
+ span_attributes[_SPAN_ATTRIBUTES_NETWORK_PEER_ADDRESS] = (
195
+ parsed_url.hostname
196
+ )
193
197
  if parsed_url.port:
194
- _set_http_port(
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
- _set_http_port(
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
- _SPAN_ATTRIBUTES_NETWORK_PEER_PORT
204
- ] = parsed_url.port
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 = _filter_duration_attrs(
288
- metric_labels, _OpenTelemetryStabilityMode.DEFAULT
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 = _filter_duration_attrs(
296
- metric_labels, _OpenTelemetryStabilityMode.HTTP
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
- return sanitize_method(method.upper().strip())
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=_excluded_urls_from_env
406
- if excluded_urls is None
407
- else parse_excluded_urls(excluded_urls),
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
 
@@ -16,3 +16,5 @@
16
16
  _instruments = ("requests ~= 2.0",)
17
17
 
18
18
  _supports_metrics = True
19
+
20
+ _semconv_status = "migration"
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "0.44b0"
15
+ __version__ = "0.46b0"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: opentelemetry-instrumentation-requests
3
- Version: 0.44b0
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.44b0
21
- Requires-Dist: opentelemetry-semantic-conventions==0.44b0
22
- Requires-Dist: opentelemetry-util-http==0.44b0
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
@@ -0,0 +1,8 @@
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.21.1
2
+ Generator: hatchling 1.24.2
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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 The OpenTelemetry Authors
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,8 +0,0 @@
1
- opentelemetry/instrumentation/requests/__init__.py,sha256=vmDR7ZNkLllcah4voyniYXoYToN1EaYDKaGt5ltVdV8,15456
2
- opentelemetry/instrumentation/requests/package.py,sha256=ULOZ8NBcPPzs-WzXMXwwoMJcc2GmNARO-nzRR1gEAMU,648
3
- opentelemetry/instrumentation/requests/version.py,sha256=19mImFBLq6Vm8J2PHjFLnLCfNeBJuW5hSl2zbot4J5I,608
4
- opentelemetry_instrumentation_requests-0.44b0.dist-info/METADATA,sha256=SCnGJzgCf6Y_eeRqLYE3sFrGkwHV4Oz4Z0YayZQ1oi8,2697
5
- opentelemetry_instrumentation_requests-0.44b0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
6
- opentelemetry_instrumentation_requests-0.44b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
7
- opentelemetry_instrumentation_requests-0.44b0.dist-info/licenses/LICENSE,sha256=h8jwqxShIeVkc8vOo9ynxGYW16f4fVPxLhZKZs0H5U8,11350
8
- opentelemetry_instrumentation_requests-0.44b0.dist-info/RECORD,,