Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to http server log middleware #500

Merged
merged 1 commit into from
Nov 12, 2023

Commits on Nov 12, 2023

  1. Add context to http server log middleware

    Currently the HTTP logging middleware adds the requst ID to its context fields
    twice and further ignores any other context values in the logger.
    
        info	http/server.go:2122	[200] GET /status	{"requestId": "73efeeb4-af33-46b5-b31b-6dbd21efa245", "req": {"id":"73efeeb4-af33-46b5-b31b-6dbd21efa245","url":"/status?service=test-service","method":"GET","path":"/status","headers":{"Accept-Encoding":"gzip","Authorization":"Bearer test","User-Agent":"Go-http-client/1.1","X-Cli-Version":"7fce8c29f7bbc1e38d683713aca5fa42c43215a8","X-Request-Id":"73efeeb4-af33-46b5-b31b-6dbd21efa245"}}, "res": {"statusCode":200}, "responseTime": 3}
    
    This change removes the excessive request ID fields and uses a context logger,
    which automatically has the request ID available. This simplifies the middleware
    a bit but also allows for other context values to be propagated in the logging
    context, eg. subject when OAuth2.0 support is added.
    
        info	http/server.go:2122	[404] GET /policies	{"requestId": "b8ac36e3-f72c-4146-b43b-d61b02fb92f0", "req": {"url":"/policies?service=test","method":"GET","path":"/policies","headers":{"Accept-Encoding":"gzip","Authorization":"Bearer test","User-Agent":"Go-http-client/1.1","X-Caller-Email":"bso@lunar.app","X-Cli-Version":"96e2ef7d006e6b0e44aca10515cecd2821cc8123","X-Request-Id":"b8ac36e3-f72c-4146-b43b-d61b02fb92f0"}}, "res": {"statusCode":404}, "responseTime": 0}
    Crevil committed Nov 12, 2023
    Configuration menu
    Copy the full SHA
    ca453d1 View commit details
    Browse the repository at this point in the history