Skip to content

Commit

Permalink
Merge pull request #9 from pengyq/fix-metadata-miss
Browse files Browse the repository at this point in the history
fix metadata miss
  • Loading branch information
johnbellone authored Apr 10, 2023
2 parents 7bce946 + 2eeb917 commit f70b492
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions client_interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package grpc_sentry

import (
"context"
"google.golang.org/grpc/metadata"

"github.com/getsentry/sentry-go"
"google.golang.org/grpc/metadata"

"google.golang.org/grpc"
)
Expand All @@ -26,7 +26,12 @@ func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor {

span := sentry.StartSpan(ctx, "grpc.client")
ctx = span.Context()
md := metadata.Pairs("sentry-trace", span.ToSentryTrace())
md, ok := metadata.FromOutgoingContext(ctx)
if ok {
md.Append("sentry-trace", span.ToSentryTrace())
} else {
md = metadata.Pairs("sentry-trace", span.ToSentryTrace())
}
ctx = metadata.NewOutgoingContext(ctx, md)
defer span.Finish()

Expand Down Expand Up @@ -59,7 +64,12 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor {

span := sentry.StartSpan(ctx, "grpc.client")
ctx = span.Context()
md := metadata.Pairs("sentry-trace", span.ToSentryTrace())
md, ok := metadata.FromOutgoingContext(ctx)
if ok {
md.Append("sentry-trace", span.ToSentryTrace())
} else {
md = metadata.Pairs("sentry-trace", span.ToSentryTrace())
}
ctx = metadata.NewOutgoingContext(ctx, md)
defer span.Finish()

Expand Down

0 comments on commit f70b492

Please sign in to comment.