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

gRPC interceptors #240

Open
rcmachado opened this issue Jun 3, 2020 · 9 comments · May be fixed by #312
Open

gRPC interceptors #240

rcmachado opened this issue Jun 3, 2020 · 9 comments · May be fixed by #312
Assignees

Comments

@rcmachado
Copy link

Summary

Provide gRPC interceptors to automatically capture errors and panics from servers and clients, both for unary and stream requests.

Motivation

gRPC is a high-performance, open source universal RPC framework originally developed by Google. It supports languages/platforms such as Python, Ruby, Kotlin and Go.

Go SDK already has some integrations with standard net/http package and some popular frameworks (like Gin, Martini and others).

Similar to other frameworks, having standard Sentry integration will make it easier for users to integrate Sentry with gRPC.

Additional Context

gRPC has the concept of interceptor (middleware), which could make it easier to implement an official Sentry integration. An interceptor is a function with a specific signature/type:

// Server interceptors (middlewares)
type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error)
type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error

// Client interceptors (middlewares)
type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error
type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)

Using an interceptor is also straightforward (pseudo-code):

// Sentry initialization
err := sentry.Init(sentry.ClientOptions{
	// Either set your DSN here or set the SENTRY_DSN environment variable.
	Dsn: "https://[email protected]/1307339",
	// Enable printing of SDK debug messages.
	// Useful when getting started or trying to figure something out.
	Debug: true,
})
if err != nil {
	log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(2 * time.Second)

// Initialize gRPC server
myServer := grpc.NewServer(
    grpc.StreamInterceptor(
        sentry.StreamServerInterceptor(),
    ),
    grpc.UnaryInterceptor(
        sentry.UnaryServerInterceptor(),
    ),
)
@shouichi shouichi linked a pull request Dec 18, 2020 that will close this issue
johnbellone added a commit to johnbellone/grpc-middleware-sentry that referenced this issue Jan 14, 2021
This project is based heavily on the [grpc-go-middleware libraries][1] and a [pull-request][2] from the [sentry-go
library][3].

[1]: https://github.com/grpc-ecosystem/go-grpc-middleware
[2]: getsentry/sentry-go#312
[3]: getsentry/sentry-go#240
@shouichi
Copy link

Hi, I opened a draft pull request for this feature. Could someone please take a look? Any feedback would be appreciated. #312

@prasad-marne
Copy link

Any updates on this. Should be very useful for anyone working with Grpc. Not sure why the PR is still in review

@pablodz
Copy link

pablodz commented Oct 3, 2021

Any update? x2 Still relevant

@Glyphack
Copy link

Glyphack commented Oct 10, 2022

Hi, I've been using a solution for myself by integrating the Grpc Erro and status package with Sentry. I'm open to contribute it here but not sure if this issue is still active or not.
I see an open PR which is not reviewed, is there any blocker?

@cleptric
Copy link
Member

cleptric commented Oct 30, 2022

@Glyphack We're slowly getting back to the Go SDK, and we'll take a look at adding integration for gRPC after #486 for sure

@cleptric cleptric linked a pull request Oct 30, 2022 that will close this issue
@github-actions
Copy link

github-actions bot commented Dec 7, 2022

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@itsamirhn
Copy link

Any Update?

@pablodz
Copy link

pablodz commented Sep 27, 2023

Any update? x3 Still relevant

@Glyphack
Copy link

Any update? x3 Still relevant

It'd be nice if you could just click the notifications to get updates, without posting a comment that emails everyone else uselessly. When there's nothing to add to the discussion there's no need to comment.

Anyway I have written this piece of code in the past based on Grpc status package:
https://github.com/Glyphack/koal/blob/master/server/pkg/sentrygrpc/sentrygrpc.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants