Include the request ID in the request logs

This commit is contained in:
Dane Everitt
2021-01-16 12:07:31 -08:00
parent 2968ea3498
commit 464f26a2c9
2 changed files with 8 additions and 5 deletions

View File

@@ -152,8 +152,9 @@ func (re *RequestError) asFilesystemError() (int, string) {
func AttachRequestID() gin.HandlerFunc {
return func(c *gin.Context) {
id := uuid.New().String()
c.Header("X-Request-Id", id)
c.Set("request_id", id)
c.Set("logger", log.WithField("request_id", id))
c.Header("X-Request-Id", id)
c.Next()
}
}
@@ -311,4 +312,4 @@ func ExtractServer(c *gin.Context) *server.Server {
panic("middleware/middleware: cannot extract server: not present in request context")
}
return v.(*server.Server)
}
}