Skip to content

Commit 5905853

Browse files
committed
Fix HTTP instrumentation not being suppressed
1 parent 10659f8 commit 5905853

File tree

2 files changed

+13
-8
lines changed
  • instrumentation
    • opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests
    • opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3

2 files changed

+13
-8
lines changed

instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@
5656
from requests.sessions import Session
5757
from requests.structures import CaseInsensitiveDict
5858

59-
from opentelemetry import context
59+
from opentelemetry import context, trace
6060
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6161
from opentelemetry.instrumentation.requests.package import _instruments
6262
from opentelemetry.instrumentation.requests.version import __version__
6363
from opentelemetry.instrumentation.utils import (
6464
_SUPPRESS_INSTRUMENTATION_KEY,
65+
#_SUPPRESS_HTTP_INSTRUMENTATION_KEY,
6566
http_status_to_status_code,
6667
)
68+
from opentelemetry.context import (_SUPPRESS_HTTP_INSTRUMENTATION_KEY)
6769
from opentelemetry.propagate import inject
6870
from opentelemetry.semconv.trace import SpanAttributes
6971
from opentelemetry.trace import SpanKind, get_tracer
@@ -77,8 +79,8 @@
7779

7880
# A key to a context variable to avoid creating duplicate spans when instrumenting
7981
# both, Session.request and Session.send, since Session.request calls into Session.send
80-
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key(
81-
"suppress_http_instrumentation"
82+
_REQUESTS_INSTRUMENTATION_KEY = context.create_key(
83+
"requests_instrumentation"
8284
)
8385

8486
_excluded_urls_from_env = get_excluded_urls("REQUESTS")
@@ -176,7 +178,7 @@ def _instrumented_requests_call(
176178
inject(headers)
177179

178180
token = context.attach(
179-
context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
181+
context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
180182
)
181183
try:
182184
result = call_wrapped() # *** PROCEED
@@ -185,7 +187,7 @@ def _instrumented_requests_call(
185187
result = getattr(exc, "response", None)
186188
finally:
187189
context.detach(token)
188-
190+
189191
if isinstance(result, Response):
190192
if span.is_recording():
191193
span.set_attribute(

instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ def response_hook(span, request, response):
7777
from opentelemetry.instrumentation.urllib3.version import __version__
7878
from opentelemetry.instrumentation.utils import (
7979
_SUPPRESS_INSTRUMENTATION_KEY,
80+
# _SUPPRESS_HTTP_INSTRUMENTATION_KEY,
8081
http_status_to_status_code,
8182
unwrap,
8283
)
84+
from opentelemetry.context import (_SUPPRESS_HTTP_INSTRUMENTATION_KEY)
85+
8386
from opentelemetry.propagate import inject
8487
from opentelemetry.semconv.trace import SpanAttributes
8588
from opentelemetry.trace import Span, SpanKind, get_tracer
@@ -88,8 +91,8 @@ def response_hook(span, request, response):
8891

8992
# A key to a context variable to avoid creating duplicate spans when instrumenting
9093
# both, Session.request and Session.send, since Session.request calls into Session.send
91-
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key(
92-
"suppress_http_instrumentation"
94+
_URLLIB3_INSTRUMENTATION_KEY = context.create_key(
95+
"urllib3_instrumentation"
9396
)
9497

9598
_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
@@ -144,7 +147,7 @@ def _instrument(self, **kwargs):
144147
response_hook=kwargs.get("response_hook"),
145148
url_filter=kwargs.get("url_filter"),
146149
)
147-
150+
148151
def _uninstrument(self, **kwargs):
149152
_uninstrument()
150153

0 commit comments

Comments
 (0)