Skip to content

Use captureException SDK methods in error tracking examples#152

Merged
gewenyu99 merged 2 commits into
mainfrom
posthog-code/use-capture-exception-in-examples
May 27, 2026
Merged

Use captureException SDK methods in error tracking examples#152
gewenyu99 merged 2 commits into
mainfrom
posthog-code/use-capture-exception-in-examples

Conversation

@gewenyu99
Copy link
Copy Markdown
Collaborator

@gewenyu99 gewenyu99 commented May 27, 2026

Summary

Manoel flagged in Slack that some of our examples were capturing $exception events through the generic capture method with hand-built property bags. This PR switches each example to the SDK's first-class exception capture API so PostHog receives proper exception metadata (correct $exception_list shape, fingerprinting, etc).

Changes per example

  • Angular (posthog-js): use posthog.captureException(error)
  • Expo & React Native (posthog-react-native@4): use posthog.captureException(error, additionalProperties)
  • Ruby (posthog-ruby): use posthog.capture_exception(e, distinct_id); bump Gemfile to ~> 3.3 (first 3.x to ship capture_exception)
  • Laravel (posthog-php): delegate PostHogService::captureException to PostHog::captureException. The previous wrapper built properties without the $ prefix (exception_type, exception_message, ...) so PostHog never parsed them as exception fields. Bumps composer.json to ^4.2 and updates composer.lock to 4.2.0 (first 4.x with PostHog::captureException).
  • Updated each example README snippet to match.

Test plan

  • ng build succeeds for the Angular example with the new code
  • tsc --noEmit -p . on Expo example reports no new errors (only pre-existing unrelated errors)
  • tsc --noEmit -p . on React Native example reports no new errors in ProfileScreen.tsx
  • Run Laravel + Ruby examples end-to-end against a real PostHog project (requires PHP/Ruby toolchains — not available in this sandbox; needs manual smoke test)
  • Confirm $exception events show up in PostHog Error Tracking with parsed stack frames

Tested these locally to make sure they work
Screenshot 2026-05-27 at 12 09 27 PM


Created with PostHog Code

Several examples were emitting `$exception` events through the generic
`capture` method with hand-built property bags. Switch each example to
the SDK's first-class exception capture API so PostHog receives proper
exception metadata (correct `$exception_list` shape, fingerprinting,
etc).

- Angular, Expo, React Native: use `posthog.captureException(error, ...)`
- Ruby: use `posthog.capture_exception(e, distinct_id)`, bump Gemfile to
  `~> 3.3` (first version with `capture_exception`)
- Laravel: delegate `PostHogService::captureException` to
  `PostHog::captureException` (the previous wrapper was building props
  without the `$` prefix so PostHog never parsed them as exception
  fields); bump composer to `^4.2` and update lock to 4.2.0
- Update each example README snippet to match

Generated-By: PostHog Code
Task-Id: 6c6bee2c-5a44-44bd-8654-79904e690605
@gewenyu99 gewenyu99 requested review from a team May 27, 2026 16:09
@gewenyu99 gewenyu99 marked this pull request as ready for review May 27, 2026 16:09
@marandaneto marandaneto requested review from a team, ablaszkiewicz, cat-ph and hpouillot May 27, 2026 16:35
@marandaneto
Copy link
Copy Markdown
Member

i think @PostHog/team-error-tracking would know better

Copy link
Copy Markdown

@hpouillot hpouillot left a comment

Choose a reason for hiding this comment

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

Nice !

Comment thread basics/expo/app/profile.tsx Outdated
},
],
posthog.captureException(error, {
$exception_source: 'react-native',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

$exception_source is not processed at ingestion, we only recognize $exception_fingerprint (for custom grouping) or $exception_level

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

++ I was about to comment this, I think we should get rid of those $exception_source - it's "legacy", we have a plural version now that gets computed from the frames, i.e.:

https://github.com/PostHog/posthog/blob/e9e1014e0952afdd17eb7211acc90b90eefc8061/rust/cymbal/src/fingerprinting/grouping_rules.rs#L158-L161

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll remove this for now. I don't think this should be as a part of the basic integration skill anyway.

Per review feedback: `$exception_source` is not processed at ingestion
(only `$exception_fingerprint` and `$exception_level` are). Sources are
computed from stack frames now. Remove it from the Expo and React Native
profile screens and from the React Native README snippet.

Generated-By: PostHog Code
Task-Id: 6c6bee2c-5a44-44bd-8654-79904e690605
@gewenyu99 gewenyu99 merged commit f17398d into main May 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants