Repository navigation
feat(rails): add controller exception reporting helper #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+896
−131
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eec4502
feat(rails): add controller exception reporting helper
marandaneto 2d0bb77
Merge remote-tracking branch 'origin/main' into feat/rails-controller…
marandaneto d7b1bb6
fix(rails): honor request-specific controller parameter filters
marandaneto 602a6fb
fix(rails): support private request parameter filters
marandaneto 7f85c76
docs(rails): clarify controller exception helper API decision
marandaneto 2207a3c
Merge branch 'main' into feat/rails-controller-helpers-zPpC27
marandaneto d657424
Merge branch 'main' into feat/rails-controller-helpers-zPpC27
marandaneto dd98b89
fix(rails): preserve Action Cable capture after context refactor
marandaneto a6a19c6
Merge remote-tracking branch 'origin/feat/rails-controller-helpers-zP…
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog-rails": minor | ||
| --- | ||
|
|
||
| Add a private controller capture_exception helper with filtered request metadata, configured user identity, explicit argument precedence, and the existing exception capture pipeline. Manual reports work independently of automatic exception capture without initializing an unavailable client. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'posthog/rails/exception_context' | ||
|
|
||
| module PostHog | ||
| module Rails | ||
| module ControllerHelpers | ||
| private | ||
|
|
||
| # Report a handled exception with filtered Rails request context. | ||
| # Manual reporting is independent of automatic capture and its exclusions. | ||
| # | ||
| # @param exception [Exception, String, Object] Input accepted by {PostHog::Client#capture_exception}. | ||
| # @param distinct_id [String, nil] Explicit identity, before configured user and request identity. | ||
| # @param additional_properties [Hash, nil] Explicit properties override inferred request properties. | ||
| # @param flags [PostHog::FeatureFlagEvaluations, nil] Flag evaluation snapshot. | ||
| # @param mechanism [Hash, nil] Explicit exception mechanism; defaults to core manual capture semantics. | ||
| # @return [Boolean, nil] The result of {PostHog.capture_exception}, or false when unavailable or capture fails. | ||
| def capture_exception(exception, distinct_id = nil, additional_properties = {}, flags: nil, mechanism: nil) | ||
| return false unless PostHog.initialized? && PostHog.client.enabled? | ||
|
|
||
| context = ExceptionContext.new(request, self, manual: true) | ||
| distinct_id = context.distinct_id if distinct_id.nil? | ||
| properties = context.properties.merge(additional_properties || {}) | ||
|
|
||
| PostHog.capture_exception(exception, distinct_id, properties, flags: flags, mechanism: mechanism) | ||
|
marandaneto marked this conversation as resolved.
Resolved
|
||
| rescue StandardError | ||
| PostHog::Logging.logger.error('Failed to capture controller exception') | ||
| false | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.