python.missing_tracing
Observability
Low
Detects code without distributed tracing instrumentation, making it difficult to understand request flow and identify bottlenecks.
Why It Matters
Section titled “Why It Matters”Without distributed tracing:
- Blind spots in production — Can’t see where time is spent
- Slow debugging — No visibility into service interactions
- Performance mysteries — Can’t identify slow dependencies
- Incident response delays — Finding root cause takes longer
Example
Section titled “Example”# ❌ Before (no tracing)async def process_order(order_id: str): order = await fetch_order(order_id) payment = await charge_payment(order) await send_notification(order) return order# ✅ After (with OpenTelemetry tracing)from opentelemetry import trace
tracer = trace.get_tracer(__name__)
async def process_order(order_id: str): with tracer.start_as_current_span("process_order") as span: span.set_attribute("order_id", order_id)
with tracer.start_as_current_span("fetch_order"): order = await fetch_order(order_id)
with tracer.start_as_current_span("charge_payment"): payment = await charge_payment(order)
with tracer.start_as_current_span("send_notification"): await send_notification(order)
return orderWhat Unfault Detects
Section titled “What Unfault Detects”- HTTP handlers without tracing spans
- External service calls without child spans
- Database operations without timing spans
- Async task creation without trace context propagation
Auto-Fix
Section titled “Auto-Fix”Unfault generates patches that add OpenTelemetry instrumentation:
from opentelemetry import tracefrom opentelemetry.instrumentation.fastapi import FastAPIInstrumentorfrom opentelemetry.instrumentation.requests import RequestsInstrumentor
# Auto-instrument frameworksFastAPIInstrumentor.instrument_app(app)RequestsInstrumentor().instrument()
tracer = trace.get_tracer(__name__)OpenTelemetry Setup
Section titled “OpenTelemetry Setup”from opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
# Configure providerprovider = TracerProvider()processor = BatchSpanProcessor(OTLPSpanExporter())provider.add_span_processor(processor)trace.set_tracer_provider(provider)