opentelemetry-instrumentation-requests 0.43b0__tar.gz → 0.45b0__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.
@@ -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
@@ -8,7 +8,7 @@ dynamic = ["version"]
8
8
  description = "OpenTelemetry requests instrumentation"
9
9
  readme = "README.rst"
10
10
  license = "Apache-2.0"
11
- requires-python = ">=3.7"
11
+ requires-python = ">=3.8"
12
12
  authors = [
13
13
  { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
14
14
  ]
@@ -18,7 +18,6 @@ classifiers = [
18
18
  "License :: OSI Approved :: Apache Software License",
19
19
  "Programming Language :: Python",
20
20
  "Programming Language :: Python :: 3",
21
- "Programming Language :: Python :: 3.7",
22
21
  "Programming Language :: Python :: 3.8",
23
22
  "Programming Language :: Python :: 3.9",
24
23
  "Programming Language :: Python :: 3.10",
@@ -26,20 +25,15 @@ classifiers = [
26
25
  ]
27
26
  dependencies = [
28
27
  "opentelemetry-api ~= 1.12",
29
- "opentelemetry-instrumentation == 0.43b0",
30
- "opentelemetry-semantic-conventions == 0.43b0",
31
- "opentelemetry-util-http == 0.43b0",
28
+ "opentelemetry-instrumentation == 0.45b0",
29
+ "opentelemetry-semantic-conventions == 0.45b0",
30
+ "opentelemetry-util-http == 0.45b0",
32
31
  ]
33
32
 
34
33
  [project.optional-dependencies]
35
34
  instruments = [
36
35
  "requests ~= 2.0",
37
36
  ]
38
- test = [
39
- "opentelemetry-instrumentation-requests[instruments]",
40
- "httpretty ~= 1.0",
41
- "opentelemetry-test-utils == 0.43b0",
42
- ]
43
37
 
44
38
  [project.entry-points.opentelemetry_instrumentor]
45
39
  requests = "opentelemetry.instrumentation.requests:RequestsInstrumentor"
@@ -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"
@@ -21,10 +21,7 @@ from requests.adapters import BaseAdapter
21
21
  from requests.models import Response
22
22
 
23
23
  import opentelemetry.instrumentation.requests
24
- from opentelemetry import context, trace
25
-
26
- # FIXME: fix the importing of this private attribute when the location of the _SUPPRESS_HTTP_INSTRUMENTATION_KEY is defined.
27
- from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
24
+ from opentelemetry import trace
28
25
  from opentelemetry.instrumentation._semconv import (
29
26
  _OTEL_SEMCONV_STABILITY_OPT_IN_KEY,
30
27
  _SPAN_ATTRIBUTES_ERROR_TYPE,
@@ -33,7 +30,10 @@ from opentelemetry.instrumentation._semconv import (
33
30
  _OpenTelemetrySemanticConventionStability,
34
31
  )
35
32
  from opentelemetry.instrumentation.requests import RequestsInstrumentor
36
- from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
33
+ from opentelemetry.instrumentation.utils import (
34
+ suppress_http_instrumentation,
35
+ suppress_instrumentation,
36
+ )
37
37
  from opentelemetry.propagate import get_global_textmap, set_global_textmap
38
38
  from opentelemetry.sdk import resources
39
39
  from opentelemetry.semconv.trace import SpanAttributes
@@ -397,26 +397,16 @@ class RequestsIntegrationTestBase(abc.ABC):
397
397
  self.assert_span()
398
398
 
399
399
  def test_suppress_instrumentation(self):
400
- token = context.attach(
401
- context.set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)
402
- )
403
- try:
400
+ with suppress_instrumentation():
404
401
  result = self.perform_request(self.URL)
405
402
  self.assertEqual(result.text, "Hello!")
406
- finally:
407
- context.detach(token)
408
403
 
409
404
  self.assert_span(num_spans=0)
410
405
 
411
406
  def test_suppress_http_instrumentation(self):
412
- token = context.attach(
413
- context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
414
- )
415
- try:
407
+ with suppress_http_instrumentation():
416
408
  result = self.perform_request(self.URL)
417
409
  self.assertEqual(result.text, "Hello!")
418
- finally:
419
- context.detach(token)
420
410
 
421
411
  self.assert_span(num_spans=0)
422
412