samber / slog-chi

🚨 Chi middleware for slog logger
https://pkg.go.dev/github.com/samber/slog-chi
MIT License
44 stars 6 forks source link

feat: custom request id key #8

Closed golonzovsky closed 4 months ago

golonzovsky commented 4 months ago

Current 'id' key for request id is very generic and often collides with existing ids.

This change introduces possibility to configure request id key in a non-breaking way.

slogchi.RequestIDKey = "request_id"

It is made in a same way as recently introduced customization for trace/span keys.

samber commented 4 months ago

The request id is encapsulated in request object. Can you explain in what case it would collide?

golonzovsky commented 4 months ago

ah, if id would be in request object - it will totally work for me even without customization 👍🏻

Current behavior adds request id into base attributes, not in request attributes https://github.com/samber/slog-chi/blob/main/middleware.go#L160

Let me know if I should change this PR to move request id from baseAttributes to requestAttributes to achieve intended behavior (but its a breaking change)?

samber commented 4 months ago

oops, you're right, i read the code too fast

let's merge!