Skip to content

Commit 577f7eb

Browse files
authored
Set request-Id in gRPC client (#1012)
1 parent d29264f commit 577f7eb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/pkg/cli/client/grpc_logger.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66

7+
"github.com/DefangLabs/defang/src/pkg"
78
"github.com/DefangLabs/defang/src/pkg/term"
89
"github.com/bufbuild/connect-go"
910
)
@@ -16,6 +17,10 @@ type grpcLogger struct {
1617

1718
func (g grpcLogger) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
1819
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
20+
// Add a request ID to the context
21+
requestId := pkg.RandomID()
22+
req.Header().Add("X-Request-Id", requestId)
23+
1924
// Get the request type name
2025
reqType := req.Spec().Procedure
2126

@@ -30,7 +35,7 @@ func (g grpcLogger) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
3035
payload = append(payload[:maxPayloadLength], []byte("…")...)
3136
}
3237

33-
term.Debug(g.prefix, reqType, string(payload))
38+
term.Debug(g.prefix, requestId, reqType, string(payload))
3439
return next(ctx, req)
3540
}
3641
}

0 commit comments

Comments
 (0)