Add JSONL access logging - #269
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an optional JSON Lines (JSONL) access log for the proxy, recording both client-facing requests and individual upstream HTTP exchanges with a shared request ID for correlation, while omitting URL credentials, query strings, and fragments from logged URLs/paths.
Changes:
- Add
access_log.pathconfig +PROXY_ACCESS_LOG_PATHenv var +-access-logflag wiring, plus documentation and examples. - Introduce
internal/accesslogJSONL logger + request-id context helpers. - Add upstream
http.RoundTripperwrapper and server middleware hooks to emit request/upstream access log entries, with tests.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new -access-log flag, env var, and config file stanza. |
| internal/server/server.go | Opens/closes the access log and wraps the upstream transport to emit upstream exchange records. |
| internal/server/middleware.go | Stores request IDs using accesslog context helpers and writes per-request JSONL entries. |
| internal/server/middleware_test.go | Adds coverage ensuring request logging writes a JSONL record with query omitted from path. |
| internal/httpclient/access_log.go | Adds a RoundTripper wrapper that logs upstream exchanges (status/error) with sanitized URLs. |
| internal/httpclient/access_log_test.go | Tests upstream access log records for status and error redaction behavior. |
| internal/config/config.go | Adds AccessLog config struct and env var loading for PROXY_ACCESS_LOG_PATH. |
| internal/config/config_test.go | Adds tests for default-disabled access log and config/env loading of the path. |
| internal/accesslog/accesslog.go | Implements a mutex-protected JSONL file logger + URL redaction + request-id context helpers. |
| internal/accesslog/accesslog_test.go | Adds tests for JSONL logging, request id retrieval, and URL sanitization. |
| docs/configuration.md | Adds detailed access log documentation (fields, examples, behavior). |
| config.example.yaml | Adds example access_log configuration. |
| cmd/proxy/main.go | Adds -access-log flag parsing and usage/help text updates. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+152
to
+156
| var activityLog *accesslog.Logger | ||
| if cfg.AccessLog.Path != "" { | ||
| activityLog, err = accesslog.Open(cfg.AccessLog.Path) | ||
| if err != nil { | ||
| _ = store.Close() |
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.
Adds an optional JSONL access log configured with
access_log.path,PROXY_ACCESS_LOG_PATH, or-access-log.Each client request and upstream HTTP exchange is written as a separate record with a shared request ID. This preserves upstream status codes across retries and OCI authentication exchanges. URL credentials, query strings, and fragments are omitted.
Configuration examples and field documentation are included.