feat: request-ID based logging and structured JSON logging defaults #49
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lab/authz-bridge!49
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/48-request-id-logging"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #48
What
X-Request-Idheader, generating one when absent, sets it on the response, and carries it on the request context logger.requestIDkey, so every existinglogf.FromContext(ctx)line in the flows picks it up without call-site changes.zap.Options{Development: false}(JSON encoder, Info level, stacktraces on errors).--zap-develstill switches to the console development encoder.Key finding (verified live on the portable cluster)
The gateway (Envoy) forwards
allowedHeadersinto the ext_authz CheckRequest body (attributes.request.http.headers), not as gRPC metadata. The interceptor therefore reads the request ID from the CheckRequest's forwarded headers (x-request-id, then Envoy'sx-envoy-request-id), keeping gRPC metadata as a fallback for direct callers. A client-sentX-Request-Idis honored end-to-end and appears in the bridge's JSON log lines.Tests
TestRequestIDInterceptorCarriesTheIDOnTheLogger/TestRequestIDMiddlewareCarriesTheIDOnTheLogger: the honored (or generated) ID is carried on the handler's context logger.TestRequestIDInterceptorHonorsTheCheckRequestHeader: the ID from the CheckRequest's forwarded headers is honored (x-request-id, x-envoy-request-id, and header-over-metadata precedence).TestServerEchoesTheRequestID: end-to-end through the real listeners — the gRPC Check echoes the ID in the response metadata and the callback listener echoes it in the response header (honored and generated cases, both gRPC listeners).Live verification (portable cluster)
task deploy(skaffold) →https://httpbin-auth.portable.animeteamspeak.moe/getwithX-Request-Id: fixed-…+ a bad bearer → 401, and the bridge log line is JSON carrying"requestID":"fixed-…"./logoutwithX-Request-Id: cb-…→ 302, response echoesx-request-id: cb-…, and the log line carries"requestID":"cb-…".View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.