From 027eb45b1de86a2a8558978b57ac02753b7728fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 7 Apr 2025 13:32:35 +0200 Subject: [PATCH] Make requests instrumentation optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if basic otel dependencies are available, this instrumentor is a separate dependency which may be missing. Signed-off-by: Lubomír Sedlář (cherry picked from commit 004f357acb0c6907e7cd06a9e6cc6a547e67e070) --- pungi/otel.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pungi/otel.py b/pungi/otel.py index 8ada87f8..37512171 100644 --- a/pungi/otel.py +++ b/pungi/otel.py @@ -46,7 +46,6 @@ class OtelTracing: from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( OTLPSpanExporter, ) - from opentelemetry.instrumentation.requests import RequestsInstrumentor otel_endpoint = os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] provider = TracerProvider( @@ -65,7 +64,11 @@ class OtelTracing: if traceparent: self.set_context(traceparent) - RequestsInstrumentor().instrument() + try: + from opentelemetry.instrumentation.requests import RequestsInstrumentor + RequestsInstrumentor().instrument() + except ImportError: + pass @contextmanager def span(self, name, **attributes):