opentelemetry-instrumentation-requests 0.51b0__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.
@@ -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``
@@ -99,15 +101,14 @@ from opentelemetry.instrumentation._semconv import (
99
101
  _set_http_network_protocol_version,
100
102
  _set_http_peer_port_client,
101
103
  _set_http_scheme,
102
- _set_http_status_code,
103
104
  _set_http_url,
105
+ _set_status,
104
106
  _StabilityMode,
105
107
  )
106
108
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
107
109
  from opentelemetry.instrumentation.requests.package import _instruments
108
110
  from opentelemetry.instrumentation.requests.version import __version__
109
111
  from opentelemetry.instrumentation.utils import (
110
- http_status_to_status_code,
111
112
  is_http_instrumentation_enabled,
112
113
  suppress_http_instrumentation,
113
114
  )
@@ -124,7 +125,6 @@ from opentelemetry.semconv.metrics.http_metrics import (
124
125
  )
125
126
  from opentelemetry.trace import SpanKind, Tracer, get_tracer
126
127
  from opentelemetry.trace.span import Span
127
- from opentelemetry.trace.status import StatusCode
128
128
  from opentelemetry.util.http import (
129
129
  ExcludeList,
130
130
  get_excluded_urls,
@@ -140,6 +140,32 @@ _RequestHookT = Optional[Callable[[Span, PreparedRequest], None]]
140
140
  _ResponseHookT = Optional[Callable[[Span, PreparedRequest, Response], None]]
141
141
 
142
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
+
143
169
  # pylint: disable=unused-argument
144
170
  # pylint: disable=R0915
145
171
  def _instrument(
@@ -267,25 +293,12 @@ def _instrument(
267
293
 
268
294
  if isinstance(result, Response):
269
295
  span_attributes = {}
270
- if span.is_recording():
271
- _set_http_status_code(
272
- span_attributes,
273
- result.status_code,
274
- sem_conv_opt_in_mode,
275
- )
276
- _set_http_status_code(
277
- metric_labels, result.status_code, sem_conv_opt_in_mode
278
- )
279
- status_code = http_status_to_status_code(
280
- result.status_code
281
- )
282
- span.set_status(status_code)
283
- if (
284
- _report_new(sem_conv_opt_in_mode)
285
- and status_code is StatusCode.ERROR
286
- ):
287
- span_attributes[ERROR_TYPE] = str(result.status_code)
288
- 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
+ )
289
302
 
290
303
  if result.raw is not None:
291
304
  version = getattr(result.raw, "version", None)
@@ -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.51b0"
15
+ __version__ = "0.52b0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opentelemetry-instrumentation-requests
3
- Version: 0.51b0
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
6
  Project-URL: Repository, https://github.com/open-telemetry/opentelemetry-python-contrib
@@ -20,9 +20,9 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3.13
21
21
  Requires-Python: >=3.8
22
22
  Requires-Dist: opentelemetry-api~=1.12
23
- Requires-Dist: opentelemetry-instrumentation==0.51b0
24
- Requires-Dist: opentelemetry-semantic-conventions==0.51b0
25
- Requires-Dist: opentelemetry-util-http==0.51b0
23
+ Requires-Dist: opentelemetry-instrumentation==0.52b0
24
+ Requires-Dist: opentelemetry-semantic-conventions==0.52b0
25
+ Requires-Dist: opentelemetry-util-http==0.52b0
26
26
  Provides-Extra: instruments
27
27
  Requires-Dist: requests~=2.0; extra == 'instruments'
28
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,9 +0,0 @@
1
- opentelemetry/instrumentation/requests/__init__.py,sha256=24iS_STwslzfaCXzZlQYJrbiF4MHvHUsb8oafsB2UFU,16735
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=xU54GoF0aIm8WYGdGIfcg45s1dMdG2m5bpBCICAKNEo,608
5
- opentelemetry_instrumentation_requests-0.51b0.dist-info/METADATA,sha256=dZlBI5uIujBpPOy20SHZ1RIofSLqmOoOvbQiUO4z0Hs,2670
6
- opentelemetry_instrumentation_requests-0.51b0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- opentelemetry_instrumentation_requests-0.51b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
8
- opentelemetry_instrumentation_requests-0.51b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
9
- opentelemetry_instrumentation_requests-0.51b0.dist-info/RECORD,,