Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
handler.go initial commit Sep 8, 2016


xrequestid is an grpc interceptor which receives request id from metadata and set the request id to context. If request is is not found in metadata, generate a random request id by


import (

func main() {
	uIntOpt := grpc.UnaryInterceptor(xrequestid.UnaryServerInterceptor())
	sIntOpt := grpc.StreamInterceptor(xrequestid.StreamServerInterceptor())
	grpc.NewServer(uIntOpt, sIntOpt)

func foo(ctx context.Context) {
	requestID := xrequestid.FromContext(ctx)
	fmt.printf("requestID :%s", requestID)

Chaining Request ID

If request id is passed by metadata, the request id is used as is by default. xrequestid.ChainRequestID() is an option to chain multiple request ids by generating new request id for each request and concatenating it to original request ids.

func main() {
	uInt := xrequestid.UnaryServerInterceptor(xrequestid.ChainRequestID()))
	sInt := xrequestid.StreamServerInterceptor(xrequestid.ChainRequestID()))

Validating Request ID

It is important to validate request id in order to protect from abusing X-Request-ID. You can define own validator for request id, and set by xrequestid.RequestIDValidator().

func customRequestIDValidator(requestID string) bool {
	if len(requestID) < 4 {
		return false
	return true

func main() {
	uInt := xrequestid.UnaryServerInterceptor(
	sInt := xrequestid.StreamServerInterceptor(
You can’t perform that action at this time.