on main help sign in
chore: use posthog's default exception reporting
1aea259Andrey Nering
internal/event/event.go+11−13
@@ -7,6 +7,7 @@ import (
7 "path/filepath"
7 "path/filepath"
8 "reflect"
8 "reflect"
9 "runtime"
9 "runtime"
10+ "time"
10
11
11 "github.com/charmbracelet/crush/internal/version"
12 "github.com/charmbracelet/crush/internal/version"
12 "github.com/posthog/posthog-go"
13 "github.com/posthog/posthog-go"
@@ -85,19 +86,16 @@ func Error(err any, props ...any) {
85 if client == nil {
86 if client == nil {
86 return
87 return
87 }
88 }
88− // The PostHog Go client does not yet support sending exceptions.
89+ posthogErr := client.Enqueue(posthog.NewDefaultException(
89− // We're mimicking the behavior by sending the minimal info required
90+ time.Now(),
90− // for PostHog to recognize this as an exception event.
91+ distinctId,
91− props = append(
92− []any{
93− "$exception_list",
94− []map[string]string{
95− {"type": reflect.TypeOf(err).String(), "value": fmt.Sprintf("%v", err)},
92+ reflect.TypeOf(err).String(),
96− },
93+ fmt.Sprintf("%v", err),
97− },
98− props...,
99− )
94+ ))
100− send("$exception", props...)
95+ if err != nil {
96+ slog.Error("Failed to enqueue PostHog error", "err", err, "props", props, "posthogErr", posthogErr)
97+ return
98+ }
101}
99}
102
100
103func Flush() {
101func Flush() {