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 Custom Attributes does not work #4

Open
mybigman opened this issue Aug 10, 2024 · 2 comments
Open

Add Custom Attributes does not work #4

mybigman opened this issue Aug 10, 2024 · 2 comments

Comments

@mybigman
Copy link

Has no effect at all.

Looking at it its creating a new request however the middleware doesn't see that request.

@samber
Copy link
Owner

samber commented Aug 11, 2024

Can you make a short demo of the issue please ?

It works in the example provided in the repository.

@alessio-perugini
Copy link

alessio-perugini commented Aug 29, 2024

@samber I'm having the same problem. I discovered that it depends on the order of some middleware I use. Below you can find a minimal example that reproduces the problem:

package main

import (
	"net/http"

	"log/slog"

	sloghttp "github.com/samber/slog-http"
	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

func main() {
	mux := http.NewServeMux()

	mux.Handle("/foobar/42", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		sloghttp.AddCustomAttributes(r, slog.String("foo", "bar"))
		w.Write([]byte("Hello, World!"))
	}))

	handler := otelhttp.NewMiddleware("asd")(mux)
	handler = sloghttp.New(slog.Default().WithGroup("http"))(handler)

	http.ListenAndServe(":4242", handler)
}

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

No branches or pull requests

3 participants