from opentelemetry import trace from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor from opentelemetry.instrumentation.redis import RedisInstrumentor def setup_telemetry(service_name: str): resource = Resource.create(attributes={SERVICE_NAME: service_name}) processor = BatchSpanProcessor(OTLPSpanExporter()) provider = TracerProvider(resource=resource) provider.add_span_processor(processor) trace.set_tracer_provider(provider) # Process-wide patches on the client classes, so they also cover clients # created at import time (gateway's _proxy_client, common.redis_client). HTTPXClientInstrumentor().instrument() RedisInstrumentor().instrument()