Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e2e4e6d
Add posthog-rails gem for automatic Rails exception tracking
popcorn Oct 27, 2025
472aaa7
fix rubocop errors
popcorn Nov 7, 2025
f21f966
Merge upstream/main into popcorn/add-rails-activejob-automatic-error-…
johnnagro Jan 16, 2026
1ccd588
correct default URL
johnnagro Jan 17, 2026
805b79e
test mode example config which includes development
johnnagro Jan 17, 2026
78e4852
Add URLs to API key documentation in example config
johnnagro Jan 17, 2026
aca80a5
Comment out on_error callback in example config
johnnagro Jan 17, 2026
b41b3f2
Add docs explaining benefits of current_user_method config
johnnagro Jan 17, 2026
5226fc4
refactor: move rails_config to PostHog::Rails.config namespace
johnnagro Jan 17, 2026
5b75d22
feat(rails): Add user_id_method config and pk support for ID extraction
johnnagro Jan 17, 2026
e177372
rescue on individual entries
johnnagro Jan 17, 2026
ea81dd4
Separate Rails config from PostHog.init
johnnagro Jan 17, 2026
e127f14
remove LLM-y file
johnnagro Jan 17, 2026
58fe569
docs: clarify only ActiveJob is supported, other runners coming soon
johnnagro Jan 17, 2026
0e6aa55
Add Rails install generator for posthog:install command
johnnagro Jan 17, 2026
8c40bd0
Abort loading posthog-rails if Rails is not defined
johnnagro Jan 17, 2026
3b0d9ca
Add posthog_distinct_id DSL for ActiveJob distinct_id extraction
johnnagro Jan 17, 2026
ddb8242
docs: clarify user_id/distinct_id detection in Rails error reporter c…
johnnagro Jan 17, 2026
e50ad52
refactor(rails): use metaprogramming for client method delegation
johnnagro Jan 17, 2026
611ee39
Fix session ID extraction in exception capture middleware
johnnagro Jan 17, 2026
2331f35
fix(rails): safely serialize exception context to prevent stack overflow
johnnagro Jan 17, 2026
35d73ee
Fix duplicate exception capture for web requests
johnnagro Jan 17, 2026
ea6a803
feat(rails): make automatic error tracking opt-in by default
johnnagro Jan 27, 2026
96f9fdb
ensuring the example config we copy over maintains the new defaults
johnnagro Feb 3, 2026
b852289
fix: Fix posthog_distinct_id
rafaeelaudibert Feb 5, 2026
09c2f05
refactor: Small fixes
rafaeelaudibert Feb 5, 2026
9d4caf8
fix: Update and point default to us.i.posthog.com
rafaeelaudibert Feb 5, 2026
8c635fb
chore: Bump to v3.5.0
rafaeelaudibert Feb 5, 2026
09ef2d4
docs: Update release process
rafaeelaudibert Feb 5, 2026
6e8f946
refactor: Simplify rubocop rules
rafaeelaudibert Feb 5, 2026
9d3f8fb
chore: Improve release flow to use new approvals workflow
rafaeelaudibert Feb 5, 2026
059b44e
chore: Remove inherit call
rafaeelaudibert Feb 5, 2026
e97af4d
Merge branch 'main' into rails
rafaeelaudibert Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 150 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,91 @@
name: Publish Release
name: "Release"

on:
workflow_dispatch:
pull_request:
types: [closed]
branches: [main]

permissions:
contents: read

# Concurrency control: only one release process can run at a time
# This prevents race conditions if multiple PRs with 'release' label merge simultaneously
concurrency:
group: release
cancel-in-progress: false

jobs:
publish:
check-release-label:
name: Check for release label
runs-on: ubuntu-latest
# Run when PR with 'release' label is merged to main
if: |
github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release')
outputs:
should-release: ${{ steps.check.outputs.should-release }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main

- name: Check version is new
id: check
run: |
# Extract version from source
version=$(grep "VERSION = '" lib/posthog/version.rb | grep -o "'[0-9]\+\.[0-9]\+\.[0-9]\+'" | tr -d "'")
echo "version=$version" >> "$GITHUB_OUTPUT"

# Get currently published version from RubyGems
published=$(gem info posthog-ruby --remote 2>/dev/null | grep -o 'posthog-ruby ([0-9.]*' | grep -o '[0-9].*' || echo "none")

echo "Local version: $version"
echo "Published version: $published"

if [ "$version" = "$published" ]; then
echo "Version $version is already published, skipping release"
echo "should-release=false" >> "$GITHUB_OUTPUT"
else
echo "Ready to release version $version"
echo "should-release=true" >> "$GITHUB_OUTPUT"
fi

notify-approval-needed:
name: Notify Slack - Approval Needed
needs: check-release-label
if: needs.check-release-label.outputs.should-release == 'true'
uses: posthog/.github/.github/workflows/notify-approval-needed.yml@main
with:
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
slack_user_group_id: ${{ vars.GROUP_CLIENT_LIBRARIES_SLACK_GROUP_ID }}
secrets:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
posthog_project_api_key: ${{ secrets.POSTHOG_PROJECT_API_KEY }}

release:
name: Release and publish
needs: [check-release-label, notify-approval-needed]
runs-on: ubuntu-latest
if: always() && needs.check-release-label.outputs.should-release == 'true'
environment: "Release" # This will require an approval from a maintainer, they are notified in Slack above
permissions:
contents: read
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Notify Slack - Approved
if: needs.notify-approval-needed.outputs.slack_ts != ''
uses: posthog/.github/.github/actions/slack-thread-reply@main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: "✅ Release approved! Publishing v${{ needs.check-release-label.outputs.version }}..."
emoji_reaction: "white_check_mark"

- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
Expand All @@ -22,4 +96,73 @@ jobs:
bundler-cache: true
ruby-version: ruby

- uses: rubygems/release-gem@v1
- name: Configure trusted publishing credentials
uses: rubygems/configure-rubygems-credentials@v1.0.0

# Build and publish posthog-ruby first (posthog-rails depends on it)
- name: Build posthog-ruby
run: gem build posthog-ruby.gemspec

- name: Publish posthog-ruby
run: gem push posthog-ruby-*.gem

- name: Wait for posthog-ruby to be available
run: gem exec rubygems-await posthog-ruby-*.gem

# Build and publish posthog-rails
- name: Build posthog-rails
run: gem build posthog-rails/posthog-rails.gemspec

- name: Publish posthog-rails
run: gem push posthog-rails-*.gem

- name: Wait for posthog-rails to be available
run: gem exec rubygems-await posthog-rails-*.gem

# Create and push git tag
- name: Create git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ needs.check-release-label.outputs.version }}" -m "Release v${{ needs.check-release-label.outputs.version }}"
git push origin "v${{ needs.check-release-label.outputs.version }}"

# Notify in case of a failure
- name: Send failure event to PostHog
if: ${{ failure() }}
uses: PostHog/posthog-github-action@v0.1
with:
posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}"
event: "posthog-ruby-github-release-workflow-failure"
properties: >-
{
"commitSha": "${{ github.sha }}",
"jobStatus": "${{ job.status }}",
"ref": "${{ github.ref }}",
"version": "v${{ needs.check-release-label.outputs.version }}"
}

- name: Notify Slack - Failed
if: ${{ failure() && needs.notify-approval-needed.outputs.slack_ts != '' }}
uses: posthog/.github/.github/actions/slack-thread-reply@main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: "❌ Failed to release `posthog-ruby@v${{ needs.check-release-label.outputs.version }}`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>"
emoji_reaction: "x"

notify-released:
name: Notify Slack - Released
needs: [check-release-label, notify-approval-needed, release]
runs-on: ubuntu-latest
if: always() && needs.release.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
steps:
- name: Notify Slack - Released
uses: posthog/.github/.github/actions/slack-thread-reply@main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: "🚀 posthog-ruby and posthog-rails v${{ needs.check-release-label.outputs.version }} released successfully!"
emoji_reaction: "rocket"
11 changes: 7 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
SuggestExtensions: false

Style/Documentation:
Enabled: false

Naming/FileName:
Exclude:
- "posthog-rails/lib/posthog-rails.rb"

# Modern Ruby 3.0+ specific cops
Style/HashTransformKeys:
Enabled: true
Expand Down Expand Up @@ -75,7 +77,8 @@ Metrics/MethodLength:
Metrics/ParameterLists:
Enabled: false

# Allow longer modules in spec files since they contain many test cases
# Ideally need to bring this down
Metrics/ModuleLength:
Max: 4055
Exclude:
- 'spec/**/*_spec.rb'
- "spec/**/*_spec.rb"
12 changes: 0 additions & 12 deletions .rubocop_todo.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 3.5.0 - 2026-02-05

1. feat: Add posthog-rails gem for automatic Rails exception tracking
- 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

## 3.4.0 - 2025-12-04

1. feat: Add ETag support for feature flag definitions polling ([#84](https://github.com/PostHog/posthog-ruby/pull/84))
Expand Down
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Specifically, the [Ruby integration](https://posthog.com/docs/integrations/ruby-
>
> All 2.x versions of the PostHog Ruby library are compatible with Ruby 2.0 and above if you need Ruby 2.0 support.

## Rails Integration

**Using Rails?** Check out [posthog-rails](posthog-rails/README.md) for automatic exception tracking, ActiveJob instrumentation, and Rails-specific features.

## Developing Locally

1. Install `asdf` to manage your Ruby version: `brew install asdf`
Expand All @@ -31,18 +35,22 @@ Specifically, the [Ruby integration](https://posthog.com/docs/integrations/ruby-

## How to release

1. Get access to RubyGems from @dmarticus, @daibhin or @mariusandra
2. Install [`gh`](https://cli.github.com/) and authenticate with `gh auth login`
3. Update `lib/posthog/version.rb` with the new version & add to `CHANGELOG.md` making sure to add the current date. Commit the changes:
Both `posthog-ruby` and `posthog-rails` are released together with the same version number.

1. Create a PR that:
- Updates `lib/posthog/version.rb` with the new version
- Updates `CHANGELOG.md` with the changes and current date

2. Add the `release` label to the PR

3. Merge the PR to `main`

```shell
VERSION=1.2.3 # Replace with the new version here
git commit -am "Version $VERSION"
git tag -a $VERSION -m "Version $VERSION"
git push && git push --tags
gh release create $VERSION --generate-notes --fail-on-no-commits
```
4. The release workflow will:
- Notify the Client Libraries team in Slack
- Wait for approval via the GitHub `Release` environment
- Publish both gems to RubyGems (via trusted publishing)
- Create and push a git tag

4. [Trigger](https://github.com/PostHog/posthog-ruby/actions) "Publish Release" GitHub Action
5. Approve the release in GitHub when prompted

5. Authenticate with your RubyGems account and approve the publish!
The workflow handles publishing both `posthog-ruby` and `posthog-rails` in the correct order (since `posthog-rails` depends on `posthog-ruby`).
4 changes: 2 additions & 2 deletions lib/posthog/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def logger
return @logger if @logger

base_logger =
if defined?(Rails)
Rails.logger
if defined?(::Rails)
::Rails.logger
else
logger = Logger.new $stdout
logger.progname = 'PostHog'
Expand Down
2 changes: 1 addition & 1 deletion lib/posthog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PostHog
VERSION = '3.4.0'
VERSION = '3.5.0'
end
Loading
Loading