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

chore(logger): update logger from context after middleware execution #52

Merged

Conversation

landerss1
Copy link
Contributor

After middleware execution, the logger should be updated to reflect any changes to the context having been made in the middlewares. For example, if I have a tracing middleware that executes the following code, these attributes do not end up in the log:

l := zerolog.Ctx(c.Request.Context())
l.UpdateContext(func(c zerolog.Context) zerolog.Context {
	return c.Str("trace_id", span.SpanContext().TraceID().String()).
		Str("span_id", span.SpanContext().SpanID().String())
})

To make it work, we need to update the context after middlewares have executed.

@appleboy appleboy merged commit 7ece7df into gin-contrib:master Jul 9, 2023
@appleboy
Copy link
Member

appleboy commented Jul 9, 2023

@landerss1 Please help to write some unit testing.

@appleboy
Copy link
Member

appleboy commented Jul 9, 2023

@landerss1 Please create another PR. I have reverted this PR.

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.

2 participants