zitadel/internal/api/grpc/server/middleware/sentry_interceptor.go
Christian Jakob b024cda4e5
feat: sentry integration (#1944)
* initial sentry variables and secrets

* feat: sentry monitoring

* fix typo

* feat(sentry version): sentry capability

* fix(sentry include): included sentry import 4 zitadel

* usage flag for sentry

* improve sentry flag

* merge main

* fix sentry config

* add sentry dsn to secret env vars

* fix test

* log sentry start

* add sentry grpc interceptor and recover

* add sentry http interceptor to asset api

* fix interceptor order

* try improve sentry recover

* fix i18n interception

* panic

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2021-07-05 10:58:58 +02:00

27 lines
715 B
Go

package middleware
import (
"context"
"github.com/getsentry/sentry-go"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"github.com/caos/zitadel/internal/api/grpc/errors"
)
func SentryHandler() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return sendErrToSentry(ctx, req, handler)
}
}
func sendErrToSentry(ctx context.Context, req interface{}, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
code, _, _, _ := errors.ExtractCaosError(err)
if code == codes.Unknown || code == codes.Internal {
sentry.CaptureException(err)
}
return resp, err
}