opentelemetry-instrumentation-requests 0.45b0__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.
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: opentelemetry-instrumentation-requests
3
- Version: 0.45b0
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,9 +17,9 @@ 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.45b0
21
- Requires-Dist: opentelemetry-semantic-conventions==0.45b0
22
- Requires-Dist: opentelemetry-util-http==0.45b0
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
25
  Description-Content-Type: text/x-rst
@@ -25,9 +25,9 @@ classifiers = [
25
25
  ]
26
26
  dependencies = [
27
27
  "opentelemetry-api ~= 1.12",
28
- "opentelemetry-instrumentation == 0.45b0",
29
- "opentelemetry-semantic-conventions == 0.45b0",
30
- "opentelemetry-util-http == 0.45b0",
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]
@@ -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,
@@ -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.45b0"
15
+ __version__ = "0.46b0"
@@ -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
- _OTEL_SEMCONV_STABILITY_OPT_IN_KEY: sem_conv_mode,
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
- _OTEL_SEMCONV_STABILITY_OPT_IN_KEY: sem_conv_mode,
673
+ OTEL_SEMCONV_STABILITY_OPT_IN: sem_conv_mode,
675
674
  },
676
675
  )
677
676
  self.env_patch.start()