Skip to content

Commit e2e4e6d

Browse files
committed
Add posthog-rails gem for automatic Rails exception tracking
This commit introduces the posthog-rails gem which provides automatic exception tracking for Rails applications, including: - Automatic capture of unhandled exceptions via Rails middleware - Automatic capture of rescued exceptions (configurable) - Automatic instrumentation of ActiveJob failures - Integration with Rails 7.0+ error reporter - Configurable exception exclusion list - User context capture from controllers Core library improvements: - Added comprehensive logging throughout exception capture flow - Added ExceptionCapture module for standardized exception parsing - Fixed field handling in Transport to strip internal-only fields (type, library, library_version, messageId) that are not part of PostHog's RawEvent struct - Fixed UUID field handling to avoid sending null values - Added capture_exception method to Client for explicit exception tracking The posthog-rails gem includes: - Railtie for automatic initialization and middleware insertion - Multiple middleware layers for capturing different exception types - ErrorSubscriber for Rails 7.0+ error reporter integration - ActiveJob extensions for job failure tracking - Comprehensive configuration options
1 parent 002c9db commit e2e4e6d

16 files changed

Lines changed: 1550 additions & 2 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## Unreleased
2+
3+
1. feat: Add posthog-rails gem for automatic Rails exception tracking
4+
- Automatic capture of unhandled exceptions via Rails middleware
5+
- Automatic capture of rescued exceptions (configurable)
6+
- Automatic instrumentation of ActiveJob failures
7+
- Integration with Rails 7.0+ error reporter
8+
- Configurable exception exclusion list
9+
- User context capture from controllers
10+
111
## 3.3.3 - 2025-10-22
212

313
1. fix: fallback to API for multi-condition flags with static cohorts ([#80](https://github.com/PostHog/posthog-ruby/pull/80))

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Specifically, the [Ruby integration](https://posthog.com/docs/integrations/ruby-
1111
>
1212
> All 2.x versions of the PostHog Ruby library are compatible with Ruby 2.0 and above if you need Ruby 2.0 support.
1313
14+
## Rails Integration
15+
16+
**Using Rails?** Check out [posthog-rails](posthog-rails/README.md) for automatic exception tracking, ActiveJob instrumentation, and Rails-specific features.
17+
1418
## Developing Locally
1519

1620
1. Install `asdf` to manage your Ruby version: `brew install asdf`

lib/posthog/logging.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def logger
4141
return @logger if @logger
4242

4343
base_logger =
44-
if defined?(Rails)
45-
Rails.logger
44+
if defined?(::Rails)
45+
::Rails.logger
4646
else
4747
logger = Logger.new $stdout
4848
logger.progname = 'PostHog'

0 commit comments

Comments
 (0)