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

appends request id over request id. #525

Open
xsteadfastx opened this issue Feb 23, 2023 · 0 comments
Open

appends request id over request id. #525

xsteadfastx opened this issue Feb 23, 2023 · 0 comments

Comments

@xsteadfastx
Copy link
Contributor

xsteadfastx commented Feb 23, 2023

im trying to get my head around a problem i discovered. this test code appends a uuid to the logger. shoouldnt it be a fresh log on each request? The context is fresh on every request.

func TestRequestID(t *testing.T) {
	t.Parallel()
	
	req, err := http.NewRequestWithContext(context.Background(), "GET", "/", nil)
	assert.NoError(err)

	rr := httptest.NewRecorder()

	handler := hlog.RequestIDHandler("uuid", "uuid")(
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			log := hlog.FromRequest(r)
			log.Info().Msg("hello from TestRequestID")
		}),
	)

	handler.ServeHTTP(rr, req)

	nr := httptest.NewRecorder()

	nReq, err := http.NewRequestWithContext(context.Background(), "GET", "/", nil)
	assert.NoError(err)

	handler.ServeHTTP(nr, nReq)

output:

=== RUN   TestRequestID
=== PAUSE TestRequestID
=== CONT  TestRequestID
{"level":"info","uuid":"cfrk4to330raq4t88jg0","time":"2023-02-23T11:39:51+01:00","message":"hello from TestRequestID"}
{"level":"info","uuid":"cfrk4to330raq4t88jg0","uuid":"cfrk4to330raq4t88jgg","time":"2023-02-23T11:39:51+01:00","message":"hello from TestRequestID"}
--- PASS: TestRequestID (0.00s)
PASS
ok      command-line-arguments  0.002s
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

1 participant