Log request id #121
reindert-vetter
started this conversation in
Ideas
Replies: 1 comment 9 replies
-
I was thinking about adding the request-id not only to the log messages but also to http responses. That way each part that has access to the request or the response can access the id. This also allows client-sided javascript to work Well, adding the request-id to request and response is really easy from my point of view. Here an example implementation with a middleware: package middleware
import (
"github.com/confetti-framework/contract/inter"
"github.com/google/uuid"
)
type RequestID struct{}
const requestHeaderIDName = "x-request-id"
func (_ RequestID) Handle(request inter.Request, next inter.Next) inter.Response {
var reqID string
// allow other systems like a reverse proxy to set the request-id
if reqID = request.Headers().Get(requestHeaderIDName); reqID == "" {
reqID = uuid.New().String()
request.Headers().Set(requestHeaderIDName, reqID)
}
resp := next(request)
resp.GetHeaders().Set(requestHeaderIDName, reqID)
return resp
} My problem is that I have no clue how to access the request-id inside the logging facade (foundation -> logger_adapter.go). I think that this would be the correct spot to add the request-id globally to all log messages. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Log request-id
Response with request-id header
Originally posted by @KinyaElGrande in #105 (comment)
Beta Was this translation helpful? Give feedback.
All reactions