Added middleware for processing request_id grpc and http requests (#6805)

This commit is contained in:
Aleksey Kosov
2025-05-21 17:57:39 +03:00
committed by GitHub
parent 140b7a7402
commit 5182d46e22
6 changed files with 88 additions and 21 deletions

20
weed/util/request_id.go Normal file
View File

@@ -0,0 +1,20 @@
package util
import "context"
const (
RequestIdHttpHeader = "X-Request-ID"
RequestIDKey = "x-request-id"
)
func GetRequestID(ctx context.Context) string {
if ctx == nil {
return ""
}
id, _ := ctx.Value(RequestIDKey).(string)
return id
}
func WithRequestID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, RequestIDKey, id)
}