Fix HTTP instrumentation not being suppressed (#1116)

This commit is contained in:
Carol Abadeer
2022-06-20 13:16:51 -07:00
committed by GitHub
parent 62e0a31ff9
commit 6503cdf2fe
10 changed files with 66 additions and 32 deletions

View File

@ -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()