Ruby error tracking installation
- 1
Install PostHog Ruby SDK
RequiredAdd the
posthog-rubygem to your Gemfile:TerminalIn your app, import the
posthog-rubylibrary and set your project API key and host. You can find these in the project settings page in PostHog.RubyNote: We do not recommend hardcoding API keys. Setting it as an environment variable is preferred.
Verify PostHog is initialized
CheckpointConfirm you can capture events with PostHogBefore proceeding, call
posthog.capture(...)to make sure you can capture events.- 2
Manually capture exceptions
RequiredNote: The Ruby SDK currently only supports manual exception capture. Automatic exception capture is not yet available.
To capture exceptions in your Ruby application, use the
capture_exceptionmethod:RubyThe
capture_exceptionmethod accepts the following parameters:Parameter Type Description exceptionExceptionThe exception object to capture (required) distinct_idStringThe distinct ID of the user (optional) propertiesHashAdditional properties to attach to the exception event (optional)

