opentelemetry-instrumentation-requests 0.43b0__py3-none-any.whl → 0.45b0__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.
@@ -58,10 +58,6 @@ from requests.models import PreparedRequest, Response
58
58
  from requests.sessions import Session
59
59
  from requests.structures import CaseInsensitiveDict
60
60
 
61
- from opentelemetry import context
62
-
63
- # FIXME: fix the importing of this private attribute when the location of the _SUPPRESS_HTTP_INSTRUMENTATION_KEY is defined.
64
- from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
65
61
  from opentelemetry.instrumentation._semconv import (
66
62
  _METRIC_ATTRIBUTES_CLIENT_DURATION_NAME,
67
63
  _SPAN_ATTRIBUTES_ERROR_TYPE,
@@ -87,8 +83,9 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
87
83
  from opentelemetry.instrumentation.requests.package import _instruments
88
84
  from opentelemetry.instrumentation.requests.version import __version__
89
85
  from opentelemetry.instrumentation.utils import (
90
- _SUPPRESS_INSTRUMENTATION_KEY,
91
86
  http_status_to_status_code,
87
+ is_http_instrumentation_enabled,
88
+ suppress_http_instrumentation,
92
89
  )
93
90
  from opentelemetry.metrics import Histogram, get_meter
94
91
  from opentelemetry.propagate import inject
@@ -108,7 +105,7 @@ from opentelemetry.util.http.httplib import set_ip_on_next_http_connection
108
105
  _excluded_urls_from_env = get_excluded_urls("REQUESTS")
109
106
 
110
107
  _RequestHookT = Optional[Callable[[Span, PreparedRequest], None]]
111
- _ResponseHookT = Optional[Callable[[Span, PreparedRequest], None]]
108
+ _ResponseHookT = Optional[Callable[[Span, PreparedRequest, Response], None]]
112
109
 
113
110
 
114
111
  # pylint: disable=unused-argument
@@ -149,9 +146,7 @@ def _instrument(
149
146
  )
150
147
  return request.headers
151
148
 
152
- if context.get_value(
153
- _SUPPRESS_INSTRUMENTATION_KEY
154
- ) or context.get_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY):
149
+ if not is_http_instrumentation_enabled():
155
150
  return wrapped_send(self, request, **kwargs)
156
151
 
157
152
  # See
@@ -220,20 +215,19 @@ def _instrument(
220
215
  headers = get_or_create_headers()
221
216
  inject(headers)
222
217
 
223
- token = context.attach(
224
- context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
225
- )
226
-
227
- start_time = default_timer()
228
-
229
- try:
230
- result = wrapped_send(self, request, **kwargs) # *** PROCEED
231
- except Exception as exc: # pylint: disable=W0703
232
- exception = exc
233
- result = getattr(exc, "response", None)
234
- finally:
235
- elapsed_time = max(default_timer() - start_time, 0)
236
- context.detach(token)
218
+ with suppress_http_instrumentation():
219
+ start_time = default_timer()
220
+ try:
221
+ result = wrapped_send(
222
+ self, request, **kwargs
223
+ ) # *** PROCEED
224
+ except Exception as exc: # pylint: disable=W0703
225
+ exception = exc
226
+ result = getattr(exc, "response", None)
227
+ finally:
228
+ elapsed_time = max(
229
+ round((default_timer() - start_time) * 1000), 0
230
+ )
237
231
 
238
232
  if isinstance(result, Response):
239
233
  span_attributes = {}
@@ -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.43b0"
15
+ __version__ = "0.45b0"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: opentelemetry-instrumentation-requests
3
- Version: 0.43b0
3
+ Version: 0.45b0
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>
@@ -11,22 +11,17 @@ Classifier: Intended Audience :: Developers
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Programming Language :: Python
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
- Requires-Python: >=3.7
18
+ Requires-Python: >=3.8
20
19
  Requires-Dist: opentelemetry-api~=1.12
21
- Requires-Dist: opentelemetry-instrumentation==0.43b0
22
- Requires-Dist: opentelemetry-semantic-conventions==0.43b0
23
- Requires-Dist: opentelemetry-util-http==0.43b0
20
+ Requires-Dist: opentelemetry-instrumentation==0.45b0
21
+ Requires-Dist: opentelemetry-semantic-conventions==0.45b0
22
+ Requires-Dist: opentelemetry-util-http==0.45b0
24
23
  Provides-Extra: instruments
25
24
  Requires-Dist: requests~=2.0; extra == 'instruments'
26
- Provides-Extra: test
27
- Requires-Dist: httpretty~=1.0; extra == 'test'
28
- Requires-Dist: opentelemetry-instrumentation-requests[instruments]; extra == 'test'
29
- Requires-Dist: opentelemetry-test-utils==0.43b0; extra == 'test'
30
25
  Description-Content-Type: text/x-rst
31
26
 
32
27
  OpenTelemetry Requests Instrumentation
@@ -0,0 +1,8 @@
1
+ opentelemetry/instrumentation/requests/__init__.py,sha256=bHMyUOO5x7CW8Tlrs34RB4SuM0BZC6bKMogCufkEB10,15466
2
+ opentelemetry/instrumentation/requests/package.py,sha256=ULOZ8NBcPPzs-WzXMXwwoMJcc2GmNARO-nzRR1gEAMU,648
3
+ opentelemetry/instrumentation/requests/version.py,sha256=HyCKkZGb11xsSYPWI9CHcfWAYU5IqDVTDpTmCwMvfu0,608
4
+ opentelemetry_instrumentation_requests-0.45b0.dist-info/METADATA,sha256=QTXSZBRHuxiJnWXIGn3lmzA8j2Ka8tw7hGYCd6TaAUI,2480
5
+ opentelemetry_instrumentation_requests-0.45b0.dist-info/WHEEL,sha256=uNdcs2TADwSd5pVaP0Z_kcjcvvTUklh2S7bxZMF8Uj0,87
6
+ opentelemetry_instrumentation_requests-0.45b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
7
+ opentelemetry_instrumentation_requests-0.45b0.dist-info/licenses/LICENSE,sha256=h8jwqxShIeVkc8vOo9ynxGYW16f4fVPxLhZKZs0H5U8,11350
8
+ opentelemetry_instrumentation_requests-0.45b0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.17.1
2
+ Generator: hatchling 1.22.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,8 +0,0 @@
1
- opentelemetry/instrumentation/requests/__init__.py,sha256=9J7x4UrQMKchCzjtMfF8Tece4Zlz78vBABuyyaNt0Uc,15714
2
- opentelemetry/instrumentation/requests/package.py,sha256=ULOZ8NBcPPzs-WzXMXwwoMJcc2GmNARO-nzRR1gEAMU,648
3
- opentelemetry/instrumentation/requests/version.py,sha256=jfcIUyuDoM4wISRi0ztCwV0F1WM36SO4vTtcSU3ZXLg,608
4
- opentelemetry_instrumentation_requests-0.43b0.dist-info/METADATA,sha256=9KQCgoX0eTymACzXiBd-3nr3ZvzGIRbz2AlpmvvJ6G4,2747
5
- opentelemetry_instrumentation_requests-0.43b0.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
6
- opentelemetry_instrumentation_requests-0.43b0.dist-info/entry_points.txt,sha256=w_cFVp9h9IXzWm2YeBaOEUANSn9iuUlNAl0QC3PDf94,100
7
- opentelemetry_instrumentation_requests-0.43b0.dist-info/licenses/LICENSE,sha256=h8jwqxShIeVkc8vOo9ynxGYW16f4fVPxLhZKZs0H5U8,11350
8
- opentelemetry_instrumentation_requests-0.43b0.dist-info/RECORD,,