Files
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>tempo-gh-bot[bot] <[email protected]>
76c906eb5f Bump github.com/opentracing-contrib/go-grpc from 0.0.0-20210225150812-73cb765af46e to 0.1.0 (#4511)
* Bump github.com/opentracing-contrib/go-grpc

Bumps [github.com/opentracing-contrib/go-grpc](https://github.com/opentracing-contrib/go-grpc) from 0.0.0-20210225150812-73cb765af46e to 0.1.0.
- [Release notes](https://github.com/opentracing-contrib/go-grpc/releases)
- [Commits](https://github.com/opentracing-contrib/go-grpc/commits/v0.1.0)

---
updated-dependencies:
- dependency-name: github.com/opentracing-contrib/go-grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update serverless gomod

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: tempo-gh-bot[bot] <[email protected]>
2025-01-15 17:11:44 -06:00

70 lines
1.7 KiB
Go

package otgrpc
import (
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// A Class is a set of types of outcomes (including errors) that will often
// be handled in the same way.
type Class string
const (
Unknown Class = "0xx"
// Success represents outcomes that achieved the desired results.
Success Class = "2xx"
// ClientError represents errors that were the client's fault.
ClientError Class = "4xx"
// ServerError represents errors that were the server's fault.
ServerError Class = "5xx"
)
// ErrorClass returns the class of the given error.
func ErrorClass(err error) Class {
if s, ok := status.FromError(err); ok {
switch s.Code() {
// Success or "success"
case codes.OK, codes.Canceled:
return Success
// Client errors
case codes.InvalidArgument, codes.NotFound, codes.AlreadyExists,
codes.PermissionDenied, codes.Unauthenticated, codes.FailedPrecondition,
codes.OutOfRange:
return ClientError
// Server errors
case codes.DeadlineExceeded, codes.ResourceExhausted, codes.Aborted,
codes.Unimplemented, codes.Internal, codes.Unavailable, codes.DataLoss:
return ServerError
// Not sure
case codes.Unknown:
fallthrough
default:
return Unknown
}
}
return Unknown
}
// SetSpanTags sets one or more tags on the given span according to the
// error.
func SetSpanTags(span opentracing.Span, err error, client bool) {
c := ErrorClass(err)
code := codes.Unknown
if s, ok := status.FromError(err); ok {
code = s.Code()
}
span.SetTag("response_code", code)
span.SetTag("response_class", c)
if err == nil {
return
}
if c != Success && (client || c == ServerError) {
ext.Error.Set(span, true)
}
}