Skip to content

feat: add health checks, end-to-end correlation, and worker telemetry - #4

Open
gustmrg wants to merge 3 commits into
mainfrom
feat/observability-health-checks
Open

gustmrg wants to merge 3 commits into
mainfrom
feat/observability-health-checks

Conversation

@gustmrg

@gustmrg gustmrg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Block C — Observability, End-to-End Correlation & Health Checks across the API, TypeScript worker, and queue documentation.

Changes

1. API Health Checks & Correlation Propagation (apps/api)

  • RabbitMQ health tracking: Added thread-safe singleton IRabbitHealthState / RabbitHealthState updated by RabbitJobService on connection/channel open, shutdown, disconnect, and service stop (IsConnected, LastConnectedAt, LastError).
  • Health endpoints: Registered ASP.NET Core Health Checks (sqlite and rabbitmq tagged "ready") and mapped:
    • GET /health/live — runs no external checks; always returns 200 with {"status":"healthy"}.
    • GET /health/ready — runs "ready" checks; returns 200 when healthy or 503 when any dependency is unhealthy, with structured JSON {"status":"...","checks":{...}}.
  • Correlation middleware & persistence:
    • Added CorrelationIdMiddleware reading X-Correlation-Id (accepting 1–64 chars matching [A-Za-z0-9._:-], otherwise generating a UUID), setting HttpContext.TraceIdentifier, echoing X-Correlation-Id on responses, and opening a CorrelationId logging scope.
    • Added nullable CorrelationId (MaxLength(64)) to TranscriptionJob and RefinementJob with EF Core migration AddJobCorrelationId.
    • Captured HttpContext.TraceIdentifier in CreateRecording, RetryTranscription, and CreateRefinement.
    • Propagated correlation_id through JobMessage, JobOutbox, AMQP BasicProperties.CorrelationId, JobResult, and structured logs (CorrelationId, JobId, Kind, Status) in RabbitJobService and JobDispatch.Apply.
  • Tests: Added ObservabilityTests covering /health/live, /health/ready (200 & 503), X-Correlation-Id validation/generation, and end-to-end correlation flow from HTTP to JobOutbox, AMQP publish properties, and JobDispatch.Apply logs. Also added SqliteConnection.ClearAllPools() in StorageKeyMigrationTests.Dispose for reliable Windows cleanup.

2. Worker Correlation & Structured Telemetry (apps/worker-ts)

  • Updated JobMessage and JobResult with backward-compatible optional correlation_id?: string (validating non-empty <= 64 chars when present, and tolerating omitted/null values).
  • Updated rabbit-worker.ts to extract correlation_id from payload or fallback to AMQP delivery.properties.correlationId, create a job-scoped child logger (correlation_id, job_id, job_kind, redelivered), emit structured JSON logs (Job started, Job completed, Job requeued after transient failure, Job failed with duration_ms and retryable), and echo correlation_id on both JobResult and AMQP correlationId publish properties.
  • Updated worker.ts so processJob preserves correlation_id on completed transcription and refinement results.
  • Added unit tests in rabbit-worker.test.ts and worker.test.ts (and fixed Windows junction handling in storage.test.ts).

3. Docker Compose & Documentation (docs/JOB-QUEUE.md)

  • Inspected apps/api/Dockerfile: mcr.microsoft.com/dotnet/aspnet:10.0 does not ship with curl or wget, so no broken in-container HTTP healthcheck command was added to docker-compose.yml.
  • Updated docs/JOB-QUEUE.md to document optional correlation_id / AMQP correlationId propagation, structured worker telemetry, and /health/live + /health/ready endpoints.

End-to-End Observability Flow

HTTP Request (X-Correlation-Id or generated UUID)
  -> CorrelationIdMiddleware (HttpContext.TraceIdentifier + Response X-Correlation-Id + Logger scope)
  -> CreateRecording / RetryTranscription / CreateRefinement (persists job.CorrelationId)
  -> JobDispatch.Prepare (writes correlation_id into JobOutbox payload)
  -> RabbitJobService (publishes with BasicProperties.CorrelationId + structured logs)
  -> worker-ts (extracts correlation_id, child logger telemetry with duration_ms, publishes JobResult + AMQP correlationId)
  -> RabbitJobService + JobDispatch.Apply (structured logs with CorrelationId, JobId, Kind, Status)

Verification

  • dotnet test apps/api/Echo.slnx — 21/21 passed (including all migration tests and new observability tests).
  • pnpm --dir apps/worker-ts install --frozen-lockfile && typecheck && lint && test && build — all passed (43/43 tests).

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