-
Notifications
You must be signed in to change notification settings - Fork 247
feat: Add grpc integration support #938
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
Open
ribice
wants to merge
45
commits into
master
Choose a base branch
from
grpc-interceptor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
123c121
initial grpc work
ribice 0712d4c
initial grpc work
ribice cc9547c
add grpc integration
ribice a904dfd
update grpc dependencies
ribice 2f3c7c5
Update grpc example structure
ribice 77a6c95
fix tests
ribice 16ee674
add span origin
ribice 2f47b43
downgrade grpc dependency version
ribice 8c75a66
update changelog
ribice dda5723
Merge branch 'master' into grpc-interceptor
ribice 92c1a30
Merge remote-tracking branch 'origin/master' into grpc-interceptor
giortzisg b88a00c
Merge branch 'master' into grpc-interceptor
giortzisg 3582c47
Merge branch 'master' into grpc-interceptor
giortzisg c7616c7
chore: remove operation name option from server
giortzisg 2142591
chore: improve test coverage
giortzisg 8b79e6e
remove error capture
giortzisg 0ae4e61
remove error capture from server
giortzisg 9e51213
update client examples
giortzisg 6b3eefb
update README
giortzisg 8404fc4
update go and sdk version
giortzisg 1d90a1e
fix rpc span attributes
giortzisg f8a41d9
Merge remote-tracking branch 'origin/master' into grpc-interceptor
giortzisg 0933046
mod tidy
giortzisg 7912c13
bump google.golang.org/grpc to latest
giortzisg 8007d7f
fix tests
giortzisg 9cc7d0d
revert logrus README change and change timeout
giortzisg ec00d57
go mod tidy
giortzisg 1bc0682
update README and example
giortzisg dbdad59
add span origin & handle empty stream case
giortzisg 7e5b061
fix span attributes
giortzisg b0de8ae
simplify tests
giortzisg d9ccd34
misc fixes
giortzisg 8844c99
fix trace continuation
giortzisg 6e55ff4
filter grpc sensitive metadata
giortzisg 81528b4
fix(grpc): Use 2s default timeout consistent with other integrations
cursoragent c17453f
add default flush timeout
giortzisg aeae8b2
fix import cycle
giortzisg 718d221
fix examples
giortzisg 48d2795
remove SetDefaults test
giortzisg b7de787
extend client tests
giortzisg 43d773b
add MergeBaggage helper
giortzisg e19e1ad
ref client & server
giortzisg 5e7b9c9
fix: MergeBaggage keeps sentry baggage when incoming is malformed
giortzisg 970151e
fix(grpc): Flush events when WaitForDelivery is true
cursoragent 4e9ad6b
Merge branch 'master' into grpc-interceptor
giortzisg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "log" | ||
| "time" | ||
|
|
||
| "grpcdemo/cmd/server/examplepb" | ||
|
|
||
| "github.com/getsentry/sentry-go" | ||
| sentrygrpc "github.com/getsentry/sentry-go/grpc" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
| "google.golang.org/grpc/metadata" | ||
| ) | ||
|
|
||
| const grpcServerAddress = "localhost:50051" | ||
|
|
||
| func main() { | ||
| // Initialize Sentry | ||
| err := sentry.Init(sentry.ClientOptions{ | ||
| Dsn: "", | ||
| TracesSampleRate: 1.0, | ||
| }) | ||
| if err != nil { | ||
| log.Fatalf("sentry.Init: %s", err) | ||
| } | ||
| defer sentry.Flush(2 * time.Second) | ||
|
|
||
| // Create a connection to the gRPC server with Sentry interceptors | ||
| conn, err := grpc.NewClient( | ||
| grpcServerAddress, | ||
| grpc.WithTransportCredentials(insecure.NewCredentials()), // Use TLS in production | ||
| grpc.WithUnaryInterceptor(sentrygrpc.UnaryClientInterceptor()), | ||
| grpc.WithStreamInterceptor(sentrygrpc.StreamClientInterceptor()), | ||
| ) | ||
| if err != nil { | ||
| log.Fatalf("Failed to connect to gRPC server: %s", err) | ||
| } | ||
| defer conn.Close() | ||
|
|
||
| // Create a client for the ExampleService | ||
| client := examplepb.NewExampleServiceClient(conn) | ||
|
|
||
| // Perform Unary call | ||
| fmt.Println("Performing Unary Call:") | ||
| unaryExample(client) | ||
|
|
||
| // Perform Streaming call | ||
| fmt.Println("\nPerforming Streaming Call:") | ||
| streamExample(client) | ||
| } | ||
|
|
||
| func unaryExample(client examplepb.ExampleServiceClient) { | ||
| ctx := context.Background() | ||
|
|
||
| // Add metadata to the context | ||
| ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs( | ||
| "custom-header", "value", | ||
| )) | ||
|
|
||
| req := &examplepb.ExampleRequest{ | ||
| Message: "Hello, server!", // Change to "error" to simulate an error | ||
| } | ||
|
|
||
| res, err := client.UnaryExample(ctx, req) | ||
| if err != nil { | ||
| fmt.Printf("Unary Call Error: %v\n", err) | ||
| sentry.CaptureException(err) | ||
| return | ||
| } | ||
|
|
||
| fmt.Printf("Unary Response: %s\n", res.Message) | ||
| } | ||
|
|
||
| func streamExample(client examplepb.ExampleServiceClient) { | ||
| ctx := context.Background() | ||
|
|
||
| // Add metadata to the context | ||
| ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs( | ||
| "streaming-header", "stream-value", | ||
| )) | ||
|
|
||
| stream, err := client.StreamExample(ctx) | ||
| if err != nil { | ||
| fmt.Printf("Failed to establish stream: %v\n", err) | ||
| sentry.CaptureException(err) | ||
| return | ||
| } | ||
|
|
||
| // Send multiple messages in the stream | ||
| messages := []string{"Message 1", "Message 2", "error", "Message 4"} | ||
| for _, msg := range messages { | ||
| err := stream.Send(&examplepb.ExampleRequest{Message: msg}) | ||
| if err != nil { | ||
| fmt.Printf("Stream Send Error: %v\n", err) | ||
| sentry.CaptureException(err) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Close the stream for sending | ||
| stream.CloseSend() | ||
|
|
||
| // Receive responses from the server | ||
| for { | ||
| res, err := stream.Recv() | ||
| if err != nil { | ||
| if err != io.EOF { | ||
| fmt.Printf("Stream Recv Error: %v\n", err) | ||
| sentry.CaptureException(err) | ||
| } | ||
| break | ||
| } | ||
| fmt.Printf("Stream Response: %s\n", res.Message) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package main; | ||
|
|
||
| option go_package = "github.com/your-username/your-repo/examplepb;examplepb"; | ||
|
|
||
| // ExampleService defines the gRPC service. | ||
| service ExampleService { | ||
| rpc UnaryExample(ExampleRequest) returns (ExampleResponse); | ||
| rpc StreamExample(stream ExampleRequest) returns (stream ExampleResponse); | ||
| } | ||
|
|
||
| // ExampleRequest is the request message. | ||
| message ExampleRequest { | ||
| string message = 1; | ||
| } | ||
|
|
||
| // ExampleResponse is the response message. | ||
| message ExampleResponse { | ||
| string message = 1; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.