sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

gRPC interceptors

Open rcmachado opened this issue 4 years ago • 9 comments

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(),
    ),
)
  • https://grpc.io/: website for the official gRPC implementation
  • grpc-ecosystem/go-grpc-middleware: middlewares for auth, logging and more that could be used as examples/references.

rcmachado avatar Jun 03 '20 13:06 rcmachado

Hi, I opened a draft pull request for this feature. Could someone please take a look? Any feedback would be appreciated. https://github.com/getsentry/sentry-go/pull/312

shouichi avatar Jan 18 '21 03:01 shouichi

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

prasad-marne avatar Aug 20 '21 05:08 prasad-marne

Any update? x2 Still relevant

pablodz avatar Oct 03 '21 03:10 pablodz

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?

Glyphack avatar Oct 10 '22 06:10 Glyphack

@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 avatar Oct 30 '22 21:10 cleptric

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 🥀

github-actions[bot] avatar Dec 07 '22 09:12 github-actions[bot]

Any Update?

itsamirhn avatar Sep 20 '23 06:09 itsamirhn

Any update? x3 Still relevant

pablodz avatar Sep 27 '23 18:09 pablodz

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

Glyphack avatar Sep 27 '23 19:09 Glyphack