Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func handleCommand(f func(context.Context, *console.Client, *cobra.Command, []st

var exitError error
defer func() {
spanEnder(exitError, trace.WithStackTrace(false))
if spanEnder(exitError, trace.WithStackTrace(false)) && exitError != nil {
sentry.CaptureException(exitError)
}
tele.Shutdown(cmd.Context())
}()

Expand Down
7 changes: 4 additions & 3 deletions internal/telemetry/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ContextWithTracer(parent context.Context, tracer Tracer) context.Context {
}

// SpanCloser gets an error and options and ends the span its attached to
type SpanCloser func(error, ...otrace.SpanEndOption)
type SpanCloser func(error, ...otrace.SpanEndOption) bool

// StartSpanFromContext starts the span from a given context with the given options, and returns a new context with span attached, as well as a closer fn.
// Returned SpanCloser should be called when done with span. To catch panics, it should be used under a defer.
Expand All @@ -49,14 +49,15 @@ func StartSpanFromContext(ctx context.Context, spanName string, opts ...otrace.S
Message: spanName,
})

return ktx, func(err error, opts ...otrace.SpanEndOption) {
return ktx, func(err error, opts ...otrace.SpanEndOption) bool {
sentry.AddBreadcrumb(&sentry.Breadcrumb{
Type: "default",
Category: "ended",
Message: spanName,
})
RecordError(span, err)
ret := RecordError(span, err)
span.End(opts...)
return ret
}
}

Expand Down
12 changes: 5 additions & 7 deletions internal/telemetry/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"strings"

"github.com/getsentry/sentry-go"
"github.com/jackc/pgconn"
"github.com/lib/pq"
"go.opentelemetry.io/otel/codes"
Expand All @@ -15,21 +14,20 @@ import (
"google.golang.org/grpc/status"
)

// RecordError should be called on a span to mark it as errored. By default error values are not recorded, unless the debug flag is set.
func RecordError(span trace.Span, err error, opts ...trace.EventOption) {
// RecordError should be called on a span to mark it as errored. Returns true if err was recorded.
func RecordError(span trace.Span, err error, opts ...trace.EventOption) bool {
if err == nil {
return
return false
}

if cls := classifyError(err); cls != errNoClass {
span.SetStatus(codes.Error, string(cls))
return
return false
}

sentry.CaptureException(err)

span.RecordError(err, opts...)
span.SetStatus(codes.Error, err.Error())
return true
}

type errClass string
Expand Down