The TrustPort Beacon Python SDK provides ASGI & WSGI automatic trace propagation with SQLAlchemy query timing, Celery worker task telemetry, and zero async loop blocking.
Install via pip or poetry:
pip install trustport-beaconfrom fastapi import FastAPI, Request
from trustport_beacon import BeaconMiddleware, beacon_span
app = FastAPI(title="Sovereign AI Engine")
# Register ASGI Telemetry Middleware
app.add_middleware(
BeaconMiddleware,
ingest_url="http://localhost:8443", # Or UK-1 Sovereign Zone Endpoint
api_key="tp_live_9f8a3c4e12",
service_name="python-ml-service",
environment="production"
)
@app.get("/health")
async def health():
return {"status": "healthy"}
@app.post("/api/v1/predict")
async def predict(request: Request):
# Contextual child span for model inference
with beacon_span("ml.inference.bert_classifier") as span:
span.set_tag("model_version", "v2.4")
# Perform computation...
return {"label": "fintech_risk_low", "confidence": 0.98}Add 'trustport_beacon.django.BeaconMiddleware' to your Django MIDDLEWARE array.
Our engineers can help configure multi-process fork hooks.