Instrument Python in Production

Opinionated Python workflow for shipping Obtrace in FastAPI, Django, and worker-based services.

Instrument Python in Production

Use this workflow when your first serious rollout target is a Python service.

Best first targets

  • FastAPI APIs
  • Django backends
  • Celery workers

Sequence

  1. Install Python SDK
  2. Configure Authentication
  3. Add service, env, and version
  4. Validate one real request path
  5. Connect release metadata

Example bootstrap

import os
 
from fastapi import FastAPI
from obtrace_sdk import ObtraceClient, ObtraceConfig, SemanticMetrics
from obtrace_sdk.http import fastapi_middleware
 
client = ObtraceClient(
    ObtraceConfig(
        api_key=os.getenv("OBTRACE_API_KEY"),
        tenant_id=os.getenv("OBTRACE_TENANT_ID"),
        project_id=os.getenv("OBTRACE_PROJECT_ID"),
        app_id="checkout-api",
        service_name="checkout-api",
        service_version=os.getenv("OBTRACE_SERVICE_VERSION", "2026.03.10"),
        env=os.getenv("OBTRACE_ENV", "prod"),
    )
)
 
app = FastAPI()
app.middleware("http")(fastapi_middleware(client))
 
@app.get("/healthz")
async def healthz():
    client.log("info", "healthz.request")
    client.metric(SemanticMetrics.RUNTIME_CPU_UTILIZATION, 0.41)
    client.span("http.server GET /healthz", attrs={
        "http.method": "GET",
        "http.route": "/healthz",
        "cloud.region": os.getenv("AWS_REGION", "us-east-1"),
    })
    return {"ok": True}

What to validate

  • a real request emits both log and trace
  • service_name, env, and service_version are stable after restart
  • cloud.region is present when deployed across regions
  • exceptions are visible before expanding instrumentation to more workers

Done definition

  • One Python service emits diagnosable telemetry in production
  • Exceptions are tied to deploy context

On this page