@@ -40,12 +40,16 @@ func (o *ServerOptions) setDefaults() {
4040
4141func recoverWithSentry (ctx context.Context , hub * sentry.Hub , o ServerOptions , onRecover func ()) {
4242 if r := recover (); r != nil {
43- hub .RecoverWithContext (ctx , r )
43+ eventID := hub .RecoverWithContext (ctx , r )
4444
4545 if onRecover != nil {
4646 onRecover ()
4747 }
4848
49+ if eventID != nil && o .WaitForDelivery {
50+ hub .Flush (o .Timeout )
51+ }
52+
4953 if o .Repanic {
5054 panic (r )
5155 }
@@ -120,12 +124,7 @@ func UnaryServerInterceptor(opts ServerOptions) grpc.UnaryServerInterceptor {
120124
121125 return func (ctx context.Context , req any , info * grpc.UnaryServerInfo , handler grpc.UnaryHandler ) (resp any , err error ) {
122126 ctx , hub , transaction := startServerTransaction (ctx , info .FullMethod )
123- defer func () {
124- transaction .Finish ()
125- if opts .WaitForDelivery {
126- hub .Flush (opts .Timeout )
127- }
128- }()
127+ defer transaction .Finish ()
129128
130129 defer recoverWithSentry (ctx , hub , opts , func () {
131130 err = status .Error (codes .Internal , internalServerErrorMessage )
@@ -144,12 +143,7 @@ func StreamServerInterceptor(opts ServerOptions) grpc.StreamServerInterceptor {
144143 opts .setDefaults ()
145144 return func (srv any , ss grpc.ServerStream , info * grpc.StreamServerInfo , handler grpc.StreamHandler ) (err error ) {
146145 ctx , hub , transaction := startServerTransaction (ss .Context (), info .FullMethod )
147- defer func () {
148- transaction .Finish ()
149- if opts .WaitForDelivery {
150- hub .Flush (opts .Timeout )
151- }
152- }()
146+ defer transaction .Finish ()
153147
154148 stream := wrapServerStream (ss , ctx )
155149
0 commit comments