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

RequestID utilities #176

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/requestmeta/requestmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ const (
// the New Enemy Problem. This is only used with the CockroachDB datastore,
// and only if user-provided request overlap is enabled.
RequestOverlapKey RequestMetadataHeaderKey = "io.spicedb.requestoverlapkey"

// RequestIDKey, if specified in a request header, will propagate the given string value
// through SpiceDB for the lifetime of the request. This can be used to correlate logs
// and traces with a specific request.
//
// TODO(alecmerdler): This is duplicated in SpiceDB source; we should be importing it from here.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this seems like the wrong place for this TODO since it needs to change in a different project

RequestIDKey RequestMetadataHeaderKey = "x-request-id"
)

// AddRequestHeaders returns a new context with the given values as request headers.
Expand All @@ -54,3 +61,7 @@ func SetRequestHeaders(ctx context.Context, values map[RequestMetadataHeaderKey]
func WithOverlapKey(ctx context.Context, key string) context.Context {
return metadata.AppendToOutgoingContext(ctx, string(RequestOverlapKey), key)
}

func WithRequestID(ctx context.Context, requestID string) context.Context {
return metadata.AppendToOutgoingContext(ctx, string(RequestIDKey), requestID)
}
Loading