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

feat: add logger to context and logging erorr #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

toyamagu-2021
Copy link
Contributor

@toyamagu-2021 toyamagu-2021 commented Feb 25, 2024

Signed-off-by: toyamagu-2021 toyamagu2021@gmail.com

Motivation

  • Logging error when random-error occurred.
  • This may be useful when rollback with new errors for canary release.

Modification

  • Add zap logger to request context
  • Logging error

Verification

Sample logs:

$ ./bin/podinfo --random-error=true --level debug
{"level":"debug","ts":"2024-02-26T02:34:06.399+0900","caller":"http/logging.go:29","msg":"request started","proto":"HTTP/1.1","uri":"/","method":"GET","remote":"127.0.0.1:54902","user-agent":"curl/7.81.0"}
{"level":"error","ts":"2024-02-26T02:34:06.399+0900","caller":"http/http.go:22","msg":"random error occurred","proto":"HTTP/1.1","uri":"/","method":"GET","remote":"127.0.0.1:54902","user-agent":"curl/7.81.0","stacktrace":"github.com/stefanprodan/podinfo/pkg/api/http.randomErrorMiddleware.func1\n\t/home/toyamagu/github.com/toyamagu-2021/podinfo/pkg/api/http/http.go:22\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2136\ngithub.com/stefanprodan/podinfo/pkg/api/http.versionMiddleware.func1\n\t/home/toyamagu/github.com/toyamagu-2021/podinfo/pkg/api/http/http.go:36\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2136\ngithub.com/stefanprodan/podinfo/pkg/api/http.(*LoggingMiddleware).Handler-fm.(*LoggingMiddleware).Handler.func1\n\t/home/toyamagu/github.com/toyamagu-2021/podinfo/pkg/api/http/logging.go:30\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2136\ngo.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux.traceware.ServeHTTP\n\t/home/toyamagu/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux@v0.46.1/mux.go:180\ngithub.com/stefanprodan/podinfo/pkg/api/http.(*PrometheusMiddleware).Handler-fm.(*PrometheusMiddleware).Handler.func1\n\t/home/toyamagu/github.com/toyamagu-2021/podinfo/pkg/api/http/metrics.go:62\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2136\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\t/home/toyamagu/go/pkg/mod/github.com/gorilla/mux@v1.8.1/mux.go:212\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2938\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:2009"}

Signed-off-by: toyamagu-2021 <toyamagu2021@gmail.com>
@toyamagu-2021 toyamagu-2021 changed the title feat: add logger to context and logging eror feat: add logger to context and logging erorr Feb 25, 2024
@toyamagu-2021 toyamagu-2021 marked this pull request as ready for review February 25, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant