Skip to content

fix(rails): dedupe ActiveJob exception captures#218

Open
marandaneto wants to merge 1 commit into
mainfrom
fix/active-job-error-dedupe
Open

fix(rails): dedupe ActiveJob exception captures#218
marandaneto wants to merge 1 commit into
mainfrom
fix/active-job-error-dedupe

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Fixes #217.

When both Rails exception auto-capture and ActiveJob instrumentation are enabled, a failing job can be captured once by ActiveJobExtensions and again when Rails reports the same re-raised exception through Rails.error with source application.active_support.

This PR marks exceptions successfully captured by the ActiveJob integration and has the Rails error subscriber skip only those already-captured exceptions. Unmarked application.active_support reports continue to be captured normally.

💚 How did you test it?

  • BUNDLE_PATH=/Users/marandaneto/Github/posthog-ruby/vendor/bundle bundle exec rspec --format doc spec/posthog/rails/exception_mechanism_spec.rb
  • BUNDLE_PATH=/Users/marandaneto/Github/posthog-ruby/vendor/bundle bundle exec rubocop posthog-rails/lib/posthog/rails.rb posthog-rails/lib/posthog/rails/active_job.rb posthog-rails/lib/posthog/rails/error_subscriber.rb spec/posthog/rails/exception_mechanism_spec.rb

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with pi. I chose an exception-level marker instead of skipping all application.active_support reports so unrelated Rails error reports are not suppressed. The tests cover the duplicate ActiveJob path and confirm unmarked ActiveSupport reports still pass through the Rails error subscriber.

@marandaneto marandaneto self-assigned this Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-05 07:21:46 UTC
Duration: 98568ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 109ms
Format Validation.Event Has Uuid 107ms
Format Validation.Event Has Lib Properties 109ms
Format Validation.Distinct Id Is String 107ms
Format Validation.Token Is Present 107ms
Format Validation.Custom Properties Preserved 107ms
Format Validation.Event Has Timestamp 108ms
Retry Behavior.Retries On 503 5314ms
Retry Behavior.Does Not Retry On 400 2109ms
Retry Behavior.Does Not Retry On 401 2109ms
Retry Behavior.Respects Retry After Header 8116ms
Retry Behavior.Implements Backoff 15722ms
Retry Behavior.Retries On 500 5213ms
Retry Behavior.Retries On 502 5212ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15717ms
Deduplication.Generates Unique Uuids 111ms
Deduplication.Preserves Uuid On Retry 5213ms
Deduplication.Preserves Uuid And Timestamp On Retry 10319ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5215ms
Deduplication.No Duplicate Events In Batch 111ms
Deduplication.Different Events Have Different Uuids 107ms
Compression.Sends Gzip When Enabled 107ms
Batch Format.Uses Proper Batch Structure 107ms
Batch Format.Flush With No Events Sends Nothing 4ms
Batch Format.Multiple Events Batched Together 110ms
Error Handling.Does Not Retry On 403 2109ms
Error Handling.Does Not Retry On 413 2108ms
Error Handling.Retries On 408 5212ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 109ms
Request Payload.Flags Request Uses V2 Query Param 109ms
Request Payload.Flags Request Hits Flags Path Not Decide 109ms
Request Payload.Flags Request Omits Authorization Header 107ms
Request Payload.Token In Flags Body Matches Init 107ms
Request Payload.Groups Round Trip 107ms
Request Payload.Groups Default To Empty Object 107ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 107ms
Request Payload.Disable Geoip Omitted Defaults To False 107ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 107ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 106ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 111ms
Request Lifecycle.Mock Response Value Is Returned To Caller 106ms
Retry Behavior.Retries Flags On 502 236ms
Retry Behavior.Retries Flags On 504 246ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 109ms

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: dedupe ActiveJob exception captures" | Re-trigger Greptile

@marandaneto marandaneto requested review from a team, ablaszkiewicz, cat-ph and hpouillot July 5, 2026 07:23
@marandaneto marandaneto marked this pull request as ready for review July 5, 2026 07:28
@marandaneto marandaneto requested a review from a team as a code owner July 5, 2026 07:28
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.

ErrorSubscriber double-captures ActiveJob exceptions already captured by ActiveJobExtensions

1 participant