posthog-rails 3.25.0 → 3.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94abc2b8a286465010b2f0ab2581933e9d2fa68abcdb145e7076193a21cfe854
4
- data.tar.gz: 8d220b357b4a739bd50b791bce91ccbe053978866875deb8ad69a9d247336d6d
3
+ metadata.gz: 586ceff3bdce7582a56dfbbe58ee4fd262a0a43896806ae77b1bfbbb2ed53c35
4
+ data.tar.gz: b29984205eaf4be92d8faab5d4d46be91783215dc32e64911453f991fe45f60f
5
5
  SHA512:
6
- metadata.gz: 9a50c5a41a58e760e75458379d55f3054768b81c413929dfa3177bc33311d139fa61807f69678a6f9ad3ee6b20c5592fea0007f9b480c0a6607ecc6fc0887db6
7
- data.tar.gz: f140b196bb5487e4e33fb4eda36f6581fb44acc62a7a27ee322da653585cdbe6dd9be4df86b53e03c9d8bc2b6deb5d1fbffc756f31999598b3cbc4fe63fbd561
6
+ metadata.gz: 54176111e05e831c4a0783786f011d96f564edf6209827178470a356fb7fdec9ddd0e18a94687312a855cb9abeb2be1c147a04e8eba65ff37d70fce73be154a7
7
+ data.tar.gz: ef7ed8f03eb0fc2f98aea58c6445f7e5333797ca2f361513b581f0292ced45b40e00fe425fe624974a4d276844c1f74c07c8ef7a7e5bc3d649b64a4b420a580c
@@ -49,7 +49,8 @@ PostHog::Rails.configure do |config|
49
49
  # config.current_user_resolver = proc { |controller| controller.current_user }
50
50
 
51
51
  # Additional exception classes to exclude from reporting
52
- # These are added to the default excluded exceptions
52
+ # These are added to the default excluded exceptions. Subclasses of a listed
53
+ # class are excluded too, and so is any exception whose cause chain contains one.
53
54
  # config.excluded_exceptions = [
54
55
  # # 'MyCustom404Error',
55
56
  # # 'MyCustomValidationError'
@@ -178,7 +178,6 @@ module PostHog
178
178
  config = PostHog::Rails.config
179
179
  return unless config&.auto_instrument_active_job && config.report_active_job_retries && exception
180
180
  return unless PostHog.initialized? && PostHog.client.enabled?
181
- return if excluded_posthog_retry?(exception, config)
182
181
 
183
182
  Internal::Context.with_context(
184
183
  @posthog_execution_context || posthog_job_context, fresh: true, enrich_current_span: false
@@ -189,20 +188,9 @@ module PostHog
189
188
  PostHog::Logging.logger.error("Failed to capture job retry: #{e.class}")
190
189
  end
191
190
 
192
- def excluded_posthog_retry?(exception, config)
193
- seen = {}.compare_by_identity
194
- current = exception
195
- while current && seen.size < PostHog::ExceptionCapture::MAX_CHAINED_EXCEPTIONS && !seen.key?(current)
196
- return true unless config.should_capture_exception?(current)
197
-
198
- seen[current] = true
199
- current = current.respond_to?(:cause) ? current.cause : nil
200
- end
201
- false
202
- end
203
-
204
191
  def capture_job_exception(exception, retry_failure: false)
205
192
  return unless PostHog::Rails.config&.auto_instrument_active_job
193
+ return unless PostHog::Rails.config&.should_capture_exception?(exception)
206
194
 
207
195
  # Build distinct_id from job arguments if possible
208
196
  distinct_id = if @posthog_execution_context
@@ -4,6 +4,8 @@
4
4
  # Copyright (c) 2020 Sentry
5
5
  # Licensed under the MIT License: https://github.com/getsentry/sentry-ruby/blob/master/LICENSE
6
6
 
7
+ require 'posthog/exception_capture'
8
+
7
9
  module PostHog
8
10
  module Rails
9
11
  class Configuration
@@ -23,7 +25,8 @@ module PostHog
23
25
  # Defaults to false.
24
26
  attr_accessor :report_active_job_retries
25
27
 
26
- # @return [Array<String>] Exception class names to ignore in addition to the defaults.
28
+ # @return [Array<String>] Exception class names to ignore in addition to the defaults. Subclasses are
29
+ # ignored too, and so is any exception whose cause chain contains a listed class.
27
30
  attr_accessor :excluded_exceptions
28
31
 
29
32
  # @return [Boolean] Whether to use PostHog tracing headers for request-scoped identity/session context.
@@ -117,8 +120,10 @@ module PostHog
117
120
  # @param exception [Exception] The exception to check.
118
121
  # @return [Boolean] Whether the exception should be captured.
119
122
  def should_capture_exception?(exception)
120
- exception_name = exception.class.name
121
- !all_excluded_exceptions.include?(exception_name)
123
+ excluded = all_excluded_exceptions
124
+ exception_chain(exception).none? do |error|
125
+ error.class.ancestors.any? { |ancestor| excluded.include?(ancestor.name) }
126
+ end
122
127
  end
123
128
 
124
129
  private
@@ -126,6 +131,15 @@ module PostHog
126
131
  def all_excluded_exceptions
127
132
  default_excluded_exceptions + excluded_exceptions
128
133
  end
134
+
135
+ def exception_chain(exception)
136
+ chain = []
137
+ while exception.is_a?(Exception) && chain.size < ExceptionCapture::MAX_CHAINED_EXCEPTIONS
138
+ chain << exception
139
+ exception = exception.cause
140
+ end
141
+ chain
142
+ end
129
143
  end
130
144
  end
131
145
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module PostHog
4
4
  module Rails
5
- VERSION = '3.25.0'
5
+ VERSION = '3.26.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.25.0
4
+ version: 3.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PostHog