Skip to content

fix: accept kwargs in capture_exception so $exception_fingerprint is preserved#139

Draft
posthog[bot] wants to merge 1 commit intomainfrom
posthog-code/capture-exception-kwargs
Draft

fix: accept kwargs in capture_exception so $exception_fingerprint is preserved#139
posthog[bot] wants to merge 1 commit intomainfrom
posthog-code/capture-exception-kwargs

Conversation

@posthog
Copy link
Copy Markdown

@posthog posthog Bot commented Apr 30, 2026

Summary

PostHog::Client#capture_exception used a positional-only signature, while the rest of the SDK (e.g. capture(attrs)) takes a kwargs Hash. When users naturally followed the kwargs convention:

PostHog.capture_exception(e, distinct_id: current_user.id, properties: { '$exception_fingerprint' => 'CustomGroup' })

…Ruby coerced {distinct_id:, properties:} into the second positional parameter, so:

  • distinct_id became a Hash (truthy, so the ||= SecureRandom.uuid fallback didn't fire)
  • additional_properties stayed {} and the merge silently dropped every custom property — including $exception_fingerprint, breaking documented Error Tracking custom grouping.

Fix

capture_exception now accepts both forms:

  • Positional (existing): capture_exception(e, 'user-123', { 'foo' => 'bar' })
  • Kwargs (new): capture_exception(e, distinct_id: 'user-123', properties: { 'foo' => 'bar' })

Internal callers in posthog-rails (active_job.rb, error_subscriber.rb, capture_exceptions.rb) all use the positional form and are unaffected.

The posthog-rails README example is updated to the kwargs form, with $exception_fingerprint shown explicitly.

Test plan

  • CI: existing positional spec still passes
  • CI: new kwargs spec covering $exception_fingerprint passes
  • Manual: call PostHog.capture_exception(e, distinct_id: 'u', properties: { '$exception_fingerprint' => 'g' }) and confirm the property reaches the backend
  • Confirm no regression in posthog-rails auto-capture (still uses positional form)

Created with PostHog Code

…preserved

The positional-only signature silently dropped custom properties when users
called capture_exception with the kwargs convention used elsewhere in the SDK
(distinct_id:, properties:). This broke documented Error Tracking features
like custom exception grouping via $exception_fingerprint.

Now accepts both forms; existing positional callers are unaffected.

Generated-By: PostHog Code
Task-Id: 6a34588b-65e0-4139-80eb-913a2d82829a
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants