Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry:capture more flaps error metadata #3677

Merged
merged 1 commit into from
Jun 28, 2024
Merged
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
33 changes: 33 additions & 0 deletions internal/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sentry
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"runtime/debug"
Expand All @@ -14,6 +15,7 @@ import (
"go.opentelemetry.io/otel/trace"

fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/internal/buildinfo"
)

Expand Down Expand Up @@ -84,6 +86,14 @@ func WithTraceID(ctx context.Context) CaptureOption {
}
}

func WithStatusCode(status int) CaptureOption {
return WithTag("status_code", fmt.Sprintf("%d", status))
}

func WithRequestID(requestID string) CaptureOption {
return WithTag("request_id", requestID)
}

func CaptureException(err error, opts ...CaptureOption) {
if !isInitialized() {
return
Expand Down Expand Up @@ -120,6 +130,29 @@ func CaptureExceptionWithAppInfo(ctx context.Context, err error, featureName str
)
return
}

var flapsErr *flaps.FlapsError

if errors.As(err, &flapsErr) {
CaptureException(
flapsErr,
WithTag("feature", featureName),
WithTag("app-platform-version", appCompact.PlatformVersion),
WithContexts(map[string]sentry.Context{
"app": map[string]interface{}{
"name": appCompact.Name,
},
"organization": map[string]interface{}{
"slug": appCompact.Organization.Slug,
},
}),
WithTraceID(ctx),
WithRequestID(flapsErr.FlyRequestId),
WithStatusCode(flapsErr.ResponseStatusCode),
)
return
}

CaptureException(
err,
WithTag("feature", featureName),
Expand Down
Loading