Skip to content

Commit

Permalink
Merge pull request #176 from authzed/requestid-header
Browse files Browse the repository at this point in the history
RequestID utilities
  • Loading branch information
alecmerdler authored Mar 20, 2024
2 parents 34b3fbd + 34b8159 commit 9622b72
Showing 1 changed file with 11 additions and 0 deletions.
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.
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)
}

0 comments on commit 9622b72

Please sign in to comment.