Skip to content

Commit

Permalink
Merge pull request #6 from myouju/master
Browse files Browse the repository at this point in the history
Assign gRPC status to SpanStatus
  • Loading branch information
johnbellone authored Jan 17, 2022
2 parents 7a2a96d + 921e0eb commit 7bce946
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion server_interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package grpc_sentry
import (
"context"
"encoding/hex"
"regexp"

"github.com/getsentry/sentry-go"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_tags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"regexp"
"google.golang.org/grpc/status"

"google.golang.org/grpc"
)
Expand Down Expand Up @@ -57,6 +60,7 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {

hub.CaptureException(err)
}
span.Status = toSpanStatus(status.Code(err))

return resp, err
}
Expand Down Expand Up @@ -96,6 +100,7 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {

hub.CaptureException(err)
}
span.Status = toSpanStatus(status.Code(err))

return err
}
Expand Down Expand Up @@ -144,3 +149,44 @@ func updateFromSentryTrace(s *sentry.Span, header []byte) {
}
}
}

func toSpanStatus(code codes.Code) sentry.SpanStatus {
switch code {
case codes.OK:
return sentry.SpanStatusOK
case codes.Canceled:
return sentry.SpanStatusCanceled
case codes.Unknown:
return sentry.SpanStatusUnknown
case codes.InvalidArgument:
return sentry.SpanStatusInvalidArgument
case codes.DeadlineExceeded:
return sentry.SpanStatusDeadlineExceeded
case codes.NotFound:
return sentry.SpanStatusNotFound
case codes.AlreadyExists:
return sentry.SpanStatusAlreadyExists
case codes.PermissionDenied:
return sentry.SpanStatusPermissionDenied
case codes.ResourceExhausted:
return sentry.SpanStatusResourceExhausted
case codes.FailedPrecondition:
return sentry.SpanStatusFailedPrecondition
case codes.Aborted:
return sentry.SpanStatusAborted
case codes.OutOfRange:
return sentry.SpanStatusOutOfRange
case codes.Unimplemented:
return sentry.SpanStatusUnimplemented
case codes.Internal:
return sentry.SpanStatusInternalError
case codes.Unavailable:
return sentry.SpanStatusUnavailable
case codes.DataLoss:
return sentry.SpanStatusDataLoss
case codes.Unauthenticated:
return sentry.SpanStatusUnauthenticated
default:
return sentry.SpanStatusUndefined
}
}

0 comments on commit 7bce946

Please sign in to comment.