diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index bd14c504e6..3a0f13e4ef 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -56,14 +56,16 @@ from requests.sessions import Session from requests.structures import CaseInsensitiveDict -from opentelemetry import context +from opentelemetry import context, trace from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.requests.package import _instruments from opentelemetry.instrumentation.requests.version import __version__ from opentelemetry.instrumentation.utils import ( _SUPPRESS_INSTRUMENTATION_KEY, + #_SUPPRESS_HTTP_INSTRUMENTATION_KEY, http_status_to_status_code, ) +from opentelemetry.context import (_SUPPRESS_HTTP_INSTRUMENTATION_KEY) from opentelemetry.propagate import inject from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, get_tracer @@ -77,8 +79,8 @@ # A key to a context variable to avoid creating duplicate spans when instrumenting # both, Session.request and Session.send, since Session.request calls into Session.send -_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key( - "suppress_http_instrumentation" +_REQUESTS_INSTRUMENTATION_KEY = context.create_key( + "requests_instrumentation" ) _excluded_urls_from_env = get_excluded_urls("REQUESTS") @@ -176,7 +178,7 @@ def _instrumented_requests_call( inject(headers) token = context.attach( - context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True) + context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True) ) try: result = call_wrapped() # *** PROCEED @@ -185,7 +187,7 @@ def _instrumented_requests_call( result = getattr(exc, "response", None) finally: context.detach(token) - + if isinstance(result, Response): if span.is_recording(): span.set_attribute( diff --git a/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py b/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py index ef04b7d0c2..d75449e46b 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py @@ -77,9 +77,12 @@ def response_hook(span, request, response): from opentelemetry.instrumentation.urllib3.version import __version__ from opentelemetry.instrumentation.utils import ( _SUPPRESS_INSTRUMENTATION_KEY, + # _SUPPRESS_HTTP_INSTRUMENTATION_KEY, http_status_to_status_code, unwrap, ) +from opentelemetry.context import (_SUPPRESS_HTTP_INSTRUMENTATION_KEY) + from opentelemetry.propagate import inject from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import Span, SpanKind, get_tracer @@ -88,8 +91,8 @@ def response_hook(span, request, response): # A key to a context variable to avoid creating duplicate spans when instrumenting # both, Session.request and Session.send, since Session.request calls into Session.send -_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key( - "suppress_http_instrumentation" +_URLLIB3_INSTRUMENTATION_KEY = context.create_key( + "urllib3_instrumentation" ) _UrlFilterT = typing.Optional[typing.Callable[[str], str]] @@ -144,7 +147,7 @@ def _instrument(self, **kwargs): response_hook=kwargs.get("response_hook"), url_filter=kwargs.get("url_filter"), ) - + def _uninstrument(self, **kwargs): _uninstrument()