Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass around contexts in as sentry intends #4

Merged
merged 3 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ log/
server.crt
server.key
server.pub
.idea/
17 changes: 17 additions & 0 deletions client_interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grpc_sentry

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

"github.com/getsentry/sentry-go"

Expand All @@ -23,6 +24,14 @@ func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor {
ctx = sentry.SetHubOnContext(ctx, hub)
}

span := sentry.StartSpan(ctx, "grpc.client")
ctx = span.Context()
md := metadata.Pairs("sentry-trace", span.ToSentryTrace())
ctx = metadata.NewOutgoingContext(ctx, md)
defer span.Finish()

hub.Scope().SetTransaction(method)

err := invoker(ctx, method, req, reply, cc, callOpts...)

if err != nil && o.ReportOn(err) {
Expand All @@ -48,6 +57,14 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor {
ctx = sentry.SetHubOnContext(ctx, hub)
}

span := sentry.StartSpan(ctx, "grpc.client")
ctx = span.Context()
md := metadata.Pairs("sentry-trace", span.ToSentryTrace())
ctx = metadata.NewOutgoingContext(ctx, md)
defer span.Finish()

hub.Scope().SetTransaction(method)

clientStream, err := streamer(ctx, desc, cc, method, callOpts...)

if err != nil && o.ReportOn(err) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/johnbellone/grpc-middleware-sentry
go 1.15

require (
github.com/getsentry/sentry-go v0.9.0
github.com/getsentry/sentry-go v0.11.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
google.golang.org/grpc v1.35.0
)
Loading