Skip to content

feat: support custom properties on exception events#180

Merged
marandaneto merged 3 commits into
mainfrom
feat/exception-custom-properties
Apr 17, 2026
Merged

feat: support custom properties on exception events#180
marandaneto merged 3 commits into
mainfrom
feat/exception-custom-properties

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab commented Apr 16, 2026

💡 Motivation and Context

Adds a Properties field to Exception, plus a SlogAttrsAsProperties helper and WithPropertiesFn option for the slog capture handler.

Closes #132

  • Custom properties on exceptions: Exception now has a Properties field for attaching arbitrary key/value metadata to a captured exception. Custom keys are flattened into the event's properties object alongside the built-in ones. Reserved keys ($lib, $lib_version, distinct_id, $exception_list, $exception_fingerprint, $geoip_disable, system context) are preserved — colliding custom keys are ignored.
  • slog custom properties: NewSlogCaptureHandler accepts a new WithPropertiesFn option that returns custom properties per slog.Record. A ready-made SlogAttrsAsProperties helper copies every slog attribute onto the event — the common case is a one-liner.
client.Enqueue(posthog.Exception{
    DistinctId: "user-123",
    Timestamp:  time.Now(),
    Properties: posthog.Properties{
        "environment": "production",
        "retry_count": 3,
    },
    ExceptionList: []posthog.ExceptionItem{
        {Type: "Payment failed", Value: "Card declined"},
    },
})

logger := slog.New(posthog.NewSlogCaptureHandler(baseHandler, client,
    posthog.WithPropertiesFn(posthog.SlogAttrsAsProperties),
))
logger.Error("Payment failed", "payment_id", "pay_123", "amount", 99.99)

💚 How did you test it?

Manually and with with tests.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added the release label to the PR
  • Added a version bump label: bump-patch, bump-minor, or bump-major

Adds a Properties field to Exception plus a SlogAttrsAsProperties helper
and WithPropertiesFn option for the slog capture handler. Custom keys
flatten into the wire properties object next to the built-in ones; typed
fields win on collision, so $lib / distinct_id / etc. can't be clobbered.
Non-breaking — ExceptionInApiProperties stays intact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jonathanlab jonathanlab requested a review from a team as a code owner April 16, 2026 12:21
@jonathanlab jonathanlab added release Add this label to trigger a release from a PR bump-minor Trigger a minor bump when merging this PR labels Apr 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

posthog-go Compliance Report

Date: 2026-04-17 07:24:34 UTC
Duration: 230ms

⚠️ Some Tests Failed

0/1 tests passed, 1 failed


Feature_Flags Tests

⚠️ 0/1 tests passed, 1 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 6ms

Failures

request_payload.request_with_person_properties_device_id

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

Comment thread CHANGELOG.md Outdated
@@ -1,3 +1,27 @@
### New Features
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanlab i think this will mess with the release steps

CHANGELOG_ENTRY=$(awk -v defText="see CHANGELOG.md" '/^## /{if (flag) exit; flag=1} flag && /^##$/{exit} flag; END{if (!flag) print defText}' CHANGELOG.md)
gh release create "v${NEW_VERSION}" --title "v${NEW_VERSION}" --notes "$CHANGELOG_ENTRY"

can you add this comment as part of the commit msg, pr description etc to avoid errors

@marandaneto marandaneto enabled auto-merge (squash) April 17, 2026 07:24
@marandaneto marandaneto merged commit a634409 into main Apr 17, 2026
14 checks passed
@marandaneto marandaneto deleted the feat/exception-custom-properties branch April 17, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bump-minor Trigger a minor bump when merging this PR release Add this label to trigger a release from a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom Properties in Exception

2 participants