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

pass X-Request-ID from upstream #4026

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion context/http.go
Expand Up @@ -62,6 +62,16 @@ func RemoteIP(r *http.Request) string {
return addr
}

// getXRequestID get X-Request-ID from HTTP header
// or generate an UUID if not found in header
func getXRequestID(r *http.Request) string {
rid := r.Header.Get("X-Request-ID")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a source for the specification of X-Request-ID field? Is it defined in the OCI spec?

if rid != "" {
return rid
}
return uuid.Generate().String()
}

// WithRequest places the request on the context. The context of the request
// is assigned a unique id, available at "http.request.id". The request itself
// is available at "http.request". Other common attributes are available under
Expand All @@ -78,7 +88,7 @@ func WithRequest(ctx context.Context, r *http.Request) context.Context {
return &httpRequestContext{
Context: ctx,
startedAt: time.Now(),
id: uuid.Generate().String(),
id: getXRequestID(r),
r: r,
}
}
Expand Down