-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
AddCustomAttributes does not work when using some middlewares #9
Comments
hi @codybuell Did you check the middleware chain order? slogchi -> ExampleMiddleware -> handler is different than ExampleMiddleware -> slogchi -> handler
|
Hi @samber, yeah here's what I'm seeing:
So does router := chi.NewRouter
router.Use(middleware.Timeout(60 * time.Second)) // <-- this guy uses next.ServeHTTP(w, r.WithContext(ctx))
router.Use(slogchi.New(logger))
router.Route("/api", func(router chi.Router) {
router.Use(ExampleMiddleware)
router.Get("/version", Version)
})
router.Get("/other", Other) // don't want the ExampleMiddleware slogchi appears to be using the |
Linking samber/slog-http#4 |
I've got a handler that is adding some custom attributes to be logged with
slogchi.AddCustomAttributes()
. This works as expected for most routes however if I use a middleware that adds something to the request context the custom attributes are no longer showing on the log. An example middleware that breaks it:If I modify the middleware to update the request in place the custom attributes are logged.
Is there a way to get custom attributes to work with the first approach? Some chi middlewares like
middleware.Timeout()
user.WithContext(ctx)
and it would be great if they were compatible. Thanks for this project!The text was updated successfully, but these errors were encountered: