Skip to content

feat(python/cerebrium): OTel auto-instrumentation example → Last9#198

Open
prathamesh-sonpatki wants to merge 1 commit into
mainfrom
feat/cerebrium-otel-autoinstrument
Open

feat(python/cerebrium): OTel auto-instrumentation example → Last9#198
prathamesh-sonpatki wants to merge 1 commit into
mainfrom
feat/cerebrium-otel-autoinstrument

Conversation

@prathamesh-sonpatki
Copy link
Copy Markdown
Member

Summary

A FastAPI app running on Cerebrium with zero OpenTelemetry code in source. All instrumentation comes from opentelemetry-instrument running in the Cerebrium entrypoint. Spans ship to Last9 over OTLP/HTTP.

Originated from a customer thread where Cerebrium → Last9 integration kept failing. We documented the metrics path (Cerebrium dashboard → Custom OTLP) in last9/last9.io#581; this PR adds the traces side.

Key bits

  • [cerebrium.runtime.custom].entrypoint = ["opentelemetry-instrument", "uvicorn", "main:app", ...] — Cerebrium honors the array verbatim, so OTel's auto-instrumentation launcher gets first-class control of process startup.
  • shell_commands = ["opentelemetry-bootstrap --action=install"] runs at build to pull every matching instrumentor for the libs in the pip deps.
  • opentelemetry-distro >=0.51b0 + opentelemetry-semantic-conventions >=0.51b0 pinned together. Without this, pip resolves a newer exporter-otlp-proto-common that imports semconv._incubating against an older semconv wheel, and sitecustomize crashes at startup with ModuleNotFoundError. Hit this trap during verification.

Verification

Deployed end-to-end to Cerebrium project last9 and confirmed trace ingestion in Last9 (otlp-aps1 cluster):

  • service.name = otel-autoinstrument-last9
  • telemetry.auto.version = 0.63b1 ← confirms auto-instrumentation, not SDK code
  • ScopeName = opentelemetry.instrumentation.fastapi ← FastAPI instrumentor firing
  • Trace tree intact: parent POST /predict SERVER span + child http receive / http send INTERNAL spans, all under one TraceId
  • Health-probe traffic visible too: GET /ready spans every second from Cerebrium's kube-probe

Sample TraceId: 0000000000000000804b1b6f2fae3993.

Test plan

  • Cerebrium build succeeds with the pinned versions
  • No ModuleNotFoundError at startup
  • POST /predict spans land in Last9 with FastAPI scope
  • Reviewer: verify the README walkthrough on a fresh Cerebrium project

🤖 Generated with Claude Code

Deploy a FastAPI app on Cerebrium with zero OTel code — opentelemetry-instrument
runs in the entrypoint and auto-patches FastAPI, requests, and httpx at startup.
Spans ship to Last9 over OTLP/HTTP.

Key bits:
- [cerebrium.runtime.custom].entrypoint prepends opentelemetry-instrument before
  uvicorn — Cerebrium honors the array so the auto-instrumentation launcher gets
  first-class control of process startup.
- opentelemetry-bootstrap runs in shell_commands at build to pull every matching
  instrumentor for the libraries in the pip deps.
- Pinned opentelemetry-distro/semantic-conventions >=0.51b0 to avoid a version
  skew where the newer exporter-otlp-proto-common imports semconv._incubating
  against an older semconv wheel and fails at sitecustomize import time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant