feat(sdk): emit one access line per request from requestLogMiddleware#128
Merged
Conversation
requestLogMiddleware attached a per-request logger but never emitted, so a module's Logcat stayed empty unless the module called ms.Log itself. Emit one structured "request" line per request (method, path, status, duration_ms) from the already-tagged per-request logger, so the platform Logcat shows traffic out of the box for every module. Path only — a query string can carry OAuth state/tokens, which must never land in logs. statusRecorder captures the status (default 200) and forwards Flush so wrapping never silently disables an SSE handler. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
The module log pipeline (SDK structured logging → dev shipper → dispatch ring → platform Logcat) is fully wired, but a module's Logcat stays empty unless the module explicitly calls
ms.Log(ctx).requestLogMiddlewareonly attaches a pre-tagged per-request logger to the context — it never emits a line itself. oauth-core (and any module without hand-rolled logging) therefore produces nothing, so the Logcat shows nothing even after real traffic.Fix
Emit one structured access line per request from
requestLogMiddleware, using the per-request logger it already builds (so the line carriesmodule_id/request_id/app_id/user_id/app_role):Now every module's traffic appears in the Logcat out of the box, no per-module logging code required.
state/code/tokens ride the query in OAuth flows and must never land in logs.statusRecordercaptures the status (defaults to 200, matching net/http) and forwardsFlushso wrapping never silently disables an SSE handler.app_idis the trustedauth.Getvalue, never a request field.Verification
go test ./internal/core/✓ (newTestRequestLogMiddleware_EmitsAccessLineasserts the line emits with the handler's status and thatstate=secretis not leaked)Rollout
Local dev resolves the SDK via the
replacedirective, so merging + pulling the SDK checkout + a runner recreate is enough for oauth-core to start emitting. Published consumers pinned to a version tag would pick this up on the next SDK release.🤖 Generated with Claude Code