Skip to content

fix(rails): capture handled Rails.error reports during web requests - #307

Merged
marandaneto merged 3 commits into
PostHog:mainfrom
bradleypriest:codex/rails-error-reporting-cleanup
Oct 23, 2026
Merged

marandaneto merged 3 commits into
PostHog:mainfrom
bradleypriest:codex/rails-error-reporting-cleanup

Conversation

@bradleypriest

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

The Rails subscriber currently skips all reports during web requests. Handled errors reported through Rails.error never reach the exception middleware, so PostHog loses them.

Allow these reports and move duplicate suppression into the core client, replacing the separate Rails and ActiveJob markers and web request flag.

Changed behaviour

  • Successful captures mark mutable exception objects and their captured causes. Subsequent captures return false, including explicit manual captures and captures through another client.
  • The first successful report wins. Later reports do not merge context, so an early report may lack metadata available only to later middleware or job handlers.
  • Remove PostHog::Rails::IN_WEB_REQUEST_KEY and the request-tracking and exception-marker helpers documented as private.

Failed captures remain retryable. Frozen exceptions can still be captured but cannot be marked for duplicate suppression.

💚 How did you test it?

  • 163 focused client and Rails tests pass.
  • RuboCop passes.
  • Changesets validates a major release for both packages.

📝 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)

Developed with Codex using Git, GitHub CLI, RSpec, RuboCop and Changesets.

@bradleypriest
bradleypriest requested a review from a team as a code owner October 16, 2026 20:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1eae04866

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .changeset/olive-cats-take.md
Comment thread lib/posthog/client.rb
Comment thread lib/posthog/client.rb Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T20:50:11.996276Z b1eae04 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@marandaneto

Copy link
Copy Markdown
Member

@bradleypriest wondering if you are gonna follow up on the comments? thanks for the PR btw

@bradleypriest

Copy link
Copy Markdown
Contributor Author

Hey @marandaneto, 2 of the comments were unrelated to this change, and the third (making it a major version bump) seemed a bit overkill, have left comments inline.

Thanks!

@bradleypriest

Copy link
Copy Markdown
Contributor Author

Both resolved in the latest commit

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good; no qualifying findings. Verdict: correct.

Bradley Priest and others added 3 commits October 23, 2026 12:13
The web request guard drops handled errors reported through Rails.error
because they never reach the exception middleware.

Deduplicate successful captures in the core client, including captured
causes, so the Rails subscriber, middleware and ActiveJob integration can
report the same exception safely. Remove their separate markers and the
web request guard.
@marandaneto
marandaneto force-pushed the codex/rails-error-reporting-cleanup branch from d02dac5 to 50663de Compare October 23, 2026 10:13
@marandaneto
marandaneto merged commit 3cf8079 into PostHog:main Oct 23, 2026
24 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.

2 participants