Files
LedgerLine/common/telemetry.py
T
Movses AslanyanandClaude Opus 5.5 14938ab36b Propagate traces over HTTP and add Redis spans
setup_telemetry now instruments httpx and redis process-wide. Both patch
the client classes, so clients created at import time (gateway's
_proxy_client, common.redis_client) are covered too. httpx CLIENT spans
inject traceparent, so the downstream FastAPI SERVER spans join the
caller's trace. gateway and fraud get setup_telemetry, the FastAPI span,
and the OTLP auth header. All seven services now export traces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 11:28:03 +03:30

21 lines
965 B
Python

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()