posthog-go icon indicating copy to clipboard operation
posthog-go copied to clipboard

feat: add support for custom properties in error tracking

Open jonathanlab opened this issue 1 month ago • 0 comments

Closes #132

Exceptions now support custom properties. Technically backwards compatible since NewDefaultException can be called w/o properties, but since we drop ExceptionInApiProperties it's a breaking change. Also added slog support.

client.Enqueue(posthog.NewDefaultException(
    time.Now(),
    "user-123",
    "Error title",
    "Description",
    posthog.NewProperties().
        Set("environment", "production").
        Set("retry_count", 3),
))

// Slog
logger := slog.New(posthog.NewSlogCaptureHandler(baseHandler, client,
    posthog.WithPropertiesFn(func(ctx context.Context, r slog.Record) posthog.Properties {
        props := posthog.NewProperties()
        r.Attrs(func(a slog.Attr) bool {
            props.Set(a.Key, a.Value.Any())
            return true
        })
        return props
    }),
))
logger.Error("Payment failed", "payment_id", "pay_123", "amount", 99.99)

jonathanlab avatar Nov 17 '25 15:11 jonathanlab