Skip to content

Commit

Permalink
Update util.go
Browse files Browse the repository at this point in the history
Enrich remote calls with request id and route.
  • Loading branch information
gabitba authored and felipejfc committed Sep 22, 2023
1 parent 0fdca8d commit 3689999
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ func GetContextFromRequest(req *protos.Request, serverID string) (context.Contex
if ctx == nil {
return nil, constants.ErrNoContextFound
}
ctx = CtxWithDefaultLogger(ctx, req.GetMsg().GetRoute(), "")

requestID := pcontext.GetFromPropagateCtx(ctx, constants.RequestIDKey)
if rID, ok := requestID.(string); !ok || (ok && rID == "") {
requestID = nuid.New().Next()
ctx = pcontext.AddToPropagateCtx(ctx, constants.RequestIDKey, requestID)
}

route := req.GetMsg().GetRoute()
ctx = pcontext.AddToPropagateCtx(ctx, constants.RouteKey, route)
ctx = CtxWithDefaultLogger(ctx, route, "")
return ctx, nil
}

0 comments on commit 3689999

Please sign in to comment.