Skip to content

Commit

Permalink
check ctxStore in intcp
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Jan 3, 2024
1 parent ce7467d commit 97106f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/grpc/direct/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (g Greeter) SayHello(ctx context.Context, request *helloworld.HelloRequest)
return nil, status.Error(codes.Unavailable, "error")
}
egrpc.CtxStoreSet(ctx, "x-biz-guid", "123")
egrpc.CtxStoreSet(ctx, "x-biz-uid", "100")
// header := metadata.Pairs("x-header-key", "val")
// err := grpc.SendHeader(context, header)
// if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions server/egrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ func (c *Container) defaultUnaryServerInterceptor() grpc.UnaryServerInterceptor

skv, skvOk := ctx.Value(ctxStoreStruct{}).(*ctxStore)
for _, key := range loggerKeys {
if v, ok := skv.kvs[key]; skvOk && ok {
fields = append(fields, elog.Any(strings.ToLower(key), v))
if skvOk {
if v, ok := skv.kvs[key]; ok {
fields = append(fields, elog.Any(strings.ToLower(key), v))
}
}
if value := tools.ContextValue(ctx, key); value != "" {
fields = append(fields, elog.FieldCustomKeyValue(strings.ToLower(key), value))
Expand Down

0 comments on commit 97106f7

Please sign in to comment.