Make requests instrumentation optional

Even if basic otel dependencies are available, this instrumentor is a
separate dependency which may be missing.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2025-04-07 13:32:35 +02:00
parent 5731cce190
commit 004f357acb

View file

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