mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 02:52:18 +08:00
Fix HTTP instrumentation not being suppressed (#1116)
This commit is contained in:
@ -24,6 +24,9 @@ import httpretty
|
||||
|
||||
import opentelemetry.instrumentation.urllib # pylint: disable=no-name-in-module,import-error
|
||||
from opentelemetry import context, trace
|
||||
|
||||
# FIXME: fix the importing of this private attribute when the location of the _SUPPRESS_HTTP_INSTRUMENTATION_KEY is defined.
|
||||
from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
|
||||
from opentelemetry.instrumentation.urllib import ( # pylint: disable=no-name-in-module,import-error
|
||||
URLLibInstrumentor,
|
||||
)
|
||||
@ -188,6 +191,18 @@ class RequestsIntegrationTestBase(abc.ABC):
|
||||
|
||||
self.assert_span(num_spans=0)
|
||||
|
||||
def test_suppress_http_instrumentation(self):
|
||||
token = context.attach(
|
||||
context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
|
||||
)
|
||||
try:
|
||||
result = self.perform_request(self.URL)
|
||||
self.assertEqual(result.read(), b"Hello!")
|
||||
finally:
|
||||
context.detach(token)
|
||||
|
||||
self.assert_span(num_spans=0)
|
||||
|
||||
def test_not_recording(self):
|
||||
with mock.patch("opentelemetry.trace.INVALID_SPAN") as mock_span:
|
||||
URLLibInstrumentor().uninstrument()
|
||||
|
Reference in New Issue
Block a user