Skip to content

Commit 314d9f1

Browse files
authored
feat: add request ID to Tail/Subscribe calls (#1388)
* feat: add request ID to Tail/Subscribe calls * chore: use canonical header names
1 parent 5e940b8 commit 314d9f1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/pkg/auth/interceptor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/bufbuild/connect-go"
88
)
99

10-
const XDefangOrgID = "x-defang-orgid"
10+
const XDefangOrgID = "X-Defang-Orgid"
1111

1212
type authInterceptor struct {
1313
authorization string
@@ -20,8 +20,8 @@ func NewAuthInterceptor(token, orgID string) connect.Interceptor {
2020

2121
func (a *authInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
2222
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
23-
req.Header().Set("authorization", a.authorization)
24-
req.Header().Set("content-type", "application/grpc") // same as the gRPC client
23+
req.Header().Set("Authorization", a.authorization)
24+
req.Header().Set("Content-Type", "application/grpc") // same as the gRPC client
2525
req.Header().Set(XDefangOrgID, a.orgID)
2626
return next(ctx, req)
2727
}
@@ -30,8 +30,8 @@ func (a *authInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
3030
func (a *authInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc {
3131
return func(ctx context.Context, spec connect.Spec) connect.StreamingClientConn {
3232
conn := next(ctx, spec)
33-
conn.RequestHeader().Set("authorization", a.authorization)
34-
conn.RequestHeader().Set("content-type", "application/grpc") // same as the gRPC client
33+
conn.RequestHeader().Set("Authorization", a.authorization)
34+
conn.RequestHeader().Set("Content-Type", "application/grpc") // same as the gRPC client
3535
conn.RequestHeader().Set(XDefangOrgID, a.orgID)
3636
return conn
3737
}

src/pkg/cli/client/grpc_logger.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,20 @@ func (g grpcLogger) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
4040
}
4141
}
4242

43-
func (grpcLogger) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc {
44-
return next
43+
func (g grpcLogger) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc {
44+
return func(ctx context.Context, spec connect.Spec) connect.StreamingClientConn {
45+
conn := next(ctx, spec)
46+
47+
// Add a request ID to the context
48+
requestId := pkg.RandomID()
49+
conn.RequestHeader().Add("X-Request-Id", requestId)
50+
51+
// Get the request type name
52+
reqType := spec.Procedure
53+
54+
term.Debug(g.prefix, requestId, reqType, "streaming connection established")
55+
return conn
56+
}
4557
}
4658

4759
func (grpcLogger) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc {

0 commit comments

Comments
 (0)