[observability] Add CloudWatch dispatcher and propagate token metadata through async events#276
Open
[observability] Add CloudWatch dispatcher and propagate token metadata through async events#276
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds CloudWatch-backed observability plumbing to the Go-based LLM proxy so usage can be attributed to projects/tokens/users, and dispatched to a CloudWatch Logs backend.
Changes:
- Persist and surface token
metadata(DB → token validation → proxy request context → async events). - Extend observability event payloads with
ProjectID,TokenID, andTokenMetadata, and mapuser_idinto dispatcher payloads. - Add a
cloudwatchdispatcher backend plugin + CLI wiring.
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/schema.sql |
Adds metadata column to SQLite schema for tokens. |
internal/token/validate.go |
Introduces ValidateTokenData* APIs returning TokenData (incl. metadata). |
internal/token/manager.go |
Clones token metadata on creation to avoid shared map mutation. |
internal/token/cache.go |
Adds cached TokenData validation paths and clones metadata on reads. |
internal/server/server.go |
Accepts token metadata in management token-create request and returns it. |
internal/server/management_api_test.go |
Verifies token create persists metadata. |
internal/proxy/proxy.go |
Enriches observability events with project/token IDs + metadata; adds request-scoped event context. |
internal/proxy/interfaces.go |
Adds TokenDataValidator and new context keys for token record ID/metadata. |
internal/proxy/proxy_test.go |
Tests observability enrichment includes token metadata. |
internal/proxy/cache_hit_fastpath_test.go |
Updates cache-hit tests to use token-data-aware validator mock. |
internal/middleware/instrumentation.go |
Adds EventEnricher hook to enrich events before publish. |
internal/middleware/instrumentation_test.go |
Tests EventEnricher propagation into published events. |
internal/eventbus/eventbus.go |
Extends Event with ProjectID, TokenID, TokenMetadata. |
internal/dispatcher/transformer.go |
Emits token/project metadata into dispatcher payload; extracts user_id, usage/model for /v1/responses. |
internal/dispatcher/transformer_additional_test.go |
Tests usage + token metadata → dispatcher payload mapping. |
internal/dispatcher/plugins/registry.go |
Registers new cloudwatch backend. |
internal/dispatcher/plugins/cloudwatch.go |
Implements CloudWatch Logs backend writing sanitized JSON messages. |
internal/dispatcher/plugins/cloudwatch_test.go |
Tests payload sanitization and stream-creation-on-missing behavior. |
internal/database/models.go |
Adds Metadata field to DB token model. |
internal/database/token.go |
Stores/loads token metadata; marshals/unmarshals map↔JSON. |
internal/database/token_test.go |
Covers CRUD roundtrip including metadata column. |
internal/database/migrations/sql/postgres/00007_add_token_metadata.sql |
Adds Postgres migration for token metadata column. |
internal/database/migrations/sql/mysql/00001_initial_schema.sql |
Adds metadata column to MySQL initial schema (but not an upgrade migration). |
cmd/proxy/main.go |
Adds cloudwatch to dispatcher CLI help and wires env→config keys. |
go.mod / go.sum |
Adds AWS SDK v2 dependencies for CloudWatch Logs. |
internal/database/migrations/sql/mysql/00001_initial_schema.sql
Outdated
Show resolved
Hide resolved
Contributor
Author
|
Full review pass completed. Summary:
Validation:
Result:
|
…io transcriptions and add corresponding tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the observability plumbing needed to export richer llm-proxy usage events, centered on three concrete changes:
What Changed
metadatato token models and database accessorsdispatcher --service cloudwatchin the CLI/v1/responses, streamed responses, compressed responses, and richer usage extractionTesting
go test ./internal/dispatcher ./internal/eventtransformer ./internal/eventbusDocumentation
docs/guides/api-configuration.mdfor the expanded dispatcher configuration surfaceLatest Review Notes
Fresh review found two follow-up risks still worth checking before merge:
response.completed-only bodies/v1/completionsrequest/response shapes without upstream usage