chore: use posthog's default exception reporting

Andrey Nering created

We had a manual handling since now, but since then PostHog added official
support via their SDK. This should give us stack traces!

Change summary

internal/event/event.go | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)

Detailed changes

internal/event/event.go 🔗

@@ -7,6 +7,7 @@ import (
 	"path/filepath"
 	"reflect"
 	"runtime"
+	"time"
 
 	"github.com/charmbracelet/crush/internal/version"
 	"github.com/posthog/posthog-go"
@@ -85,19 +86,16 @@ func Error(err any, props ...any) {
 	if client == nil {
 		return
 	}
-	// The PostHog Go client does not yet support sending exceptions.
-	// We're mimicking the behavior by sending the minimal info required
-	// for PostHog to recognize this as an exception event.
-	props = append(
-		[]any{
-			"$exception_list",
-			[]map[string]string{
-				{"type": reflect.TypeOf(err).String(), "value": fmt.Sprintf("%v", err)},
-			},
-		},
-		props...,
-	)
-	send("$exception", props...)
+	posthogErr := client.Enqueue(posthog.NewDefaultException(
+		time.Now(),
+		distinctId,
+		reflect.TypeOf(err).String(),
+		fmt.Sprintf("%v", err),
+	))
+	if err != nil {
+		slog.Error("Failed to enqueue PostHog error", "err", err, "props", props, "posthogErr", posthogErr)
+		return
+	}
 }
 
 func Flush() {