Skip to content

feat(telemetry): observability spans + attrs (validation, DB-write, body-size, first-stream-event, Sentry) - #805

Open
sjawhar wants to merge 2 commits into
LuthienResearch:mainfrom
trajectory-labs-pbc:feat/telemetry-observability
Open

sjawhar wants to merge 2 commits into
LuthienResearch:mainfrom
trajectory-labs-pbc:feat/telemetry-observability

Conversation

@sjawhar

@sjawhar sjawhar commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What

Adds OpenTelemetry spans and span attributes across the proxy's hot paths so operators can see validation, DB-write, and streaming behaviour in traces.

All attributes are low-cardinality (sizes, counts, durations, status, booleans). No request/response content, credentials, or high-cardinality ids are recorded.

Changes

  • credential_manager: span around credential validation.
  • observability/emitter + request_log/recorder: DB-write spans with duration_ms and error status on failure.
  • request_log/recorder: request/response body-size attributes and a body_truncated flag.
  • pipeline/anthropic_processor: time-to-first-streamed-event attribute.
  • observability/sentry: opt-in Sentry init (no-op when DSN unset), with tests.

Testing

Unit tests cover each new span/attribute plus the disabled/no-op paths (emitter, recorder, anthropic_processor, credential_manager, sentry init). pytest green locally.

Notes

Content-free by construction — every span attribute is a size/count/duration/status/boolean. Safe to enable in any OTLP backend.

…ody-size, first-stream-event, Sentry)

Adds OpenTelemetry spans and span attributes across the proxy's hot paths so
operators can see validation, DB-write, and streaming behaviour in traces. All
attributes are low-cardinality (sizes, counts, durations, status, booleans) —
no request/response content, credentials, or high-cardinality ids are recorded.

- credential_manager: span around credential validation.
- observability/emitter + request_log/recorder: DB-write spans with
  duration_ms and error status on failure.
- request_log/recorder: request/response body-size attributes and a
  body_truncated flag.
- pipeline/anthropic_processor: time-to-first-streamed-event attribute.
- observability/sentry: opt-in Sentry init (no-op when DSN unset), with tests.

Tests cover each new span/attribute and the disabled/no-op paths.
@legion-implementer
legion-implementer Bot force-pushed the feat/telemetry-observability branch from 266add0 to b2a80f2 Compare July 8, 2026 22:55
…stdout event dump

- request_log.write span now record_exception on DatabaseWriteError (previously
  set ERROR status with no exception -> error=null in Datadog).
- Instrument asyncpg + psycopg (instrument_db, wired at startup) so slow DB
  queries surface as spans. API-call latency was already traced via
  anthropic.complete/anthropic.stream.
- Gate the observability emitter's full-payload stdout dump behind a new
  OBSERVABILITY_STDOUT_ENABLED setting (default true; set false in prod). The
  raw print() of full request/response payloads to stdout drove ~$450/mo of
  CloudWatch ingestion (/ecs/luthien-proxy ~910 GB/mo); events still persist to
  the DB and event publisher, so no observability is lost.
@legion-implementer
legion-implementer Bot force-pushed the feat/telemetry-observability branch from d496638 to 36a12b5 Compare July 19, 2026 16:22
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