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> (cherry picked from commit 004f357acb0c6907e7cd06a9e6cc6a547e67e070)
This commit is contained in:
parent
7bcf9df307
commit
027eb45b1d
@ -46,7 +46,6 @@ class OtelTracing:
|
|||||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
||||||
OTLPSpanExporter,
|
OTLPSpanExporter,
|
||||||
)
|
)
|
||||||
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
|
||||||
|
|
||||||
otel_endpoint = os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"]
|
otel_endpoint = os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"]
|
||||||
provider = TracerProvider(
|
provider = TracerProvider(
|
||||||
@ -65,7 +64,11 @@ class OtelTracing:
|
|||||||
if traceparent:
|
if traceparent:
|
||||||
self.set_context(traceparent)
|
self.set_context(traceparent)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
||||||
RequestsInstrumentor().instrument()
|
RequestsInstrumentor().instrument()
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def span(self, name, **attributes):
|
def span(self, name, **attributes):
|
||||||
|
Loading…
Reference in New Issue
Block a user