diff --git a/ext/opentelemetry-ext-http-requests/src/opentelemetry/ext/http_requests/__init__.py b/ext/opentelemetry-ext-http-requests/src/opentelemetry/ext/http_requests/__init__.py index 994968e1967..a117da5daa0 100644 --- a/ext/opentelemetry-ext-http-requests/src/opentelemetry/ext/http_requests/__init__.py +++ b/ext/opentelemetry-ext-http-requests/src/opentelemetry/ext/http_requests/__init__.py @@ -23,6 +23,7 @@ from requests.sessions import Session from opentelemetry import propagators +from opentelemetry.context import Context from opentelemetry.trace import SpanKind @@ -50,8 +51,8 @@ def enable(tracer): @functools.wraps(wrapped) def instrumented_request(self, method, url, *args, **kwargs): - # TODO: Check if we are in an exporter, cf. OpenCensus - # execution_context.is_exporter() + if Context.suppress_instrumentation: + return wrapped(self, method, url, *args, **kwargs) # See # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md#http-client diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 66122985c0c..2f42c19c393 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -18,6 +18,7 @@ import typing from enum import Enum +from opentelemetry.context import Context from opentelemetry.sdk import util from .. import Span, SpanProcessor @@ -72,11 +73,15 @@ def on_start(self, span: Span) -> None: pass def on_end(self, span: Span) -> None: + suppress_instrumentation = Context.suppress_instrumentation try: + Context.suppress_instrumentation = True self.span_exporter.export((span,)) # pylint: disable=broad-except except Exception as exc: logger.warning("Exception while exporting data: %s", exc) + finally: + Context.suppress_instrumentation = suppress_instrumentation def shutdown(self) -> None: self.span_exporter.shutdown() @@ -176,11 +181,15 @@ def export(self) -> bool: while idx < self.max_export_batch_size and self.queue: self.spans_list[idx] = self.queue.pop() idx += 1 + suppress_instrumentation = Context.suppress_instrumentation try: + Context.suppress_instrumentation = True self.span_exporter.export(self.spans_list[:idx]) # pylint: disable=broad-except except Exception: logger.exception("Exception while exporting data.") + finally: + Context.suppress_instrumentation = suppress_instrumentation # clean up list for index in range(idx):