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

http: superfluous response.WriteHeader call #84

Open
nikolaydubina opened this issue Dec 10, 2024 · 3 comments
Open

http: superfluous response.WriteHeader call #84

nikolaydubina opened this issue Dec 10, 2024 · 3 comments

Comments

@nikolaydubina
Copy link

http: superfluous response.WriteHeader call from github.com/riandyrn/otelchi.getRRW.func2.1 (middleware.go:92)

started to get this recently

@ilhamsyahids
Copy link
Collaborator

Hi @nikolaydubina

Which version otelchi are you using it? and can you share how to replicate that?

@nikolaydubina
Copy link
Author

nikolaydubina commented Dec 13, 2024

version

github.com/riandyrn/otelchi v0.11.0

to replicate... I don't know.... we have large monorepo. probably something writes header, and then otelchi tries to write header again..

besides, how come otelchi is writing header of response? isn't it that monitoring libraries (control plane) are not supposed to modify data plane?

some hints on how to repro this:

  • this is very intermittent error, usually does not happen
  • this happens exclusively in traces where root as non-http request trace (which is expected, since log statement from http pkg is not using ctx for linking logs to traces)
  • this happens for ok and error status codes. no correlation
  • we always write w.WriteHeader first and then w.Write, do not use implicit header written from w.Write

our main.go shows that it is very early in the stack of middleware, pretty much root. requestID and realIP do not write body nor status code and never error. there are no other routers or middleware.

"github.com/go-chi/chi/v5"

...
func main() {
        ...
	r := chi.NewRouter()

	r.Use(middleware.RequestID)
	r.Use(middleware.RealIP)
	r.Use(otelchi.Middleware("server", otelchi.WithChiRoutes(r)))
        ...
}

@ilhamsyahids
Copy link
Collaborator

how come otelchi is writing header of response? isn't it that monitoring libraries (control plane) are not supposed to modify data plane?

Thanks for raising this concern! Actually, it isn’t modifying the response. As you can see here, it only captures the initial status code for span attribution purposes while propagating the original ResponseWriter untouched.

For reference, the official OpenTelemetry instrumentation otelmux uses a similar approach, as shown here.

We appreciate your report and will review this further.

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

2 participants