sentry-rails 6.7.0 → 7.0.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 +4 -4
- data/gemfiles/ruby-2.7_rails-5.2.0.gemfile.lock +9 -9
- data/gemfiles/ruby-2.7_rails-6.0.0.gemfile.lock +9 -9
- data/gemfiles/ruby-2.7_rails-6.1.0.gemfile.lock +10 -10
- data/gemfiles/ruby-2.7_rails-7.0.0.gemfile.lock +10 -10
- data/gemfiles/ruby-2.7_rails-7.1.0.gemfile.lock +9 -9
- data/gemfiles/ruby-3.0_rails-6.1.0.gemfile.lock +12 -12
- data/gemfiles/ruby-3.0_rails-7.0.0.gemfile.lock +12 -12
- data/gemfiles/ruby-3.0_rails-7.1.0.gemfile.lock +11 -11
- data/gemfiles/ruby-3.1_rails-6.1.0.gemfile.lock +22 -22
- data/gemfiles/ruby-3.1_rails-7.0.0.gemfile.lock +22 -22
- data/gemfiles/ruby-3.1_rails-7.1.0.gemfile.lock +20 -20
- data/gemfiles/ruby-3.1_rails-7.2.0.gemfile.lock +20 -20
- data/gemfiles/ruby-3.2_rails-6.1.0.gemfile.lock +24 -24
- data/gemfiles/ruby-3.2_rails-7.0.0.gemfile.lock +24 -24
- data/gemfiles/ruby-3.2_rails-7.1.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.2_rails-7.2.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.2_rails-8.0.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.3_rails-6.1.0.gemfile.lock +24 -24
- data/gemfiles/ruby-3.3_rails-7.0.0.gemfile.lock +24 -24
- data/gemfiles/ruby-3.3_rails-7.1.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.3_rails-7.2.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.3_rails-8.0.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.4_rails-7.1.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.4_rails-7.2.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.4_rails-8.0.0.gemfile.lock +28 -28
- data/gemfiles/ruby-3.4_rails-8.1.3.gemfile.lock +28 -28
- data/gemfiles/ruby-4.0_rails-6.1.0.gemfile.lock +24 -24
- data/gemfiles/ruby-4.0_rails-7.0.0.gemfile.lock +24 -24
- data/gemfiles/ruby-4.0_rails-7.1.0.gemfile.lock +28 -28
- data/gemfiles/ruby-4.0_rails-8.0.0.gemfile.lock +28 -28
- data/gemfiles/ruby-4.0_rails-8.1.3.gemfile.lock +28 -28
- data/gemfiles/ruby-jruby-9.4.14.0_rails-6.1.0.gemfile.lock +18 -18
- data/gemfiles/ruby-jruby-9.4.14.0_rails-7.0.0.gemfile.lock +18 -18
- data/gemfiles/ruby-jruby-9.4.14.0_rails-7.1.0.gemfile.lock +16 -16
- data/lib/sentry/rails/active_job.rb +13 -7
- data/lib/sentry/rails/breadcrumb/active_support_logger.rb +30 -0
- data/lib/sentry/rails/capture_exceptions.rb +4 -1
- data/lib/sentry/rails/configuration.rb +8 -2
- data/lib/sentry/rails/controller_transaction.rb +24 -3
- data/lib/sentry/rails/error_reporter_context.rb +0 -2
- data/lib/sentry/rails/log_subscribers/action_controller_subscriber.rb +3 -7
- data/lib/sentry/rails/log_subscribers/action_mailer_subscriber.rb +5 -9
- data/lib/sentry/rails/log_subscribers/active_job_subscriber.rb +5 -7
- data/lib/sentry/rails/log_subscribers/active_record_subscriber.rb +1 -5
- data/lib/sentry/rails/railtie.rb +1 -1
- data/lib/sentry/rails/tracing/active_storage_subscriber.rb +4 -1
- data/lib/sentry/rails/version.rb +1 -1
- data/sentry-rails.gemspec +1 -1
- metadata +8 -9
- data/lib/sentry/rails/log_subscribers/parameter_filter.rb +0 -52
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "sentry/utils/http_tracing"
|
|
4
|
+
|
|
3
5
|
module Sentry
|
|
4
6
|
module Rails
|
|
5
7
|
module Breadcrumb
|
|
6
8
|
module ActiveSupportLogger
|
|
7
9
|
class << self
|
|
10
|
+
include Sentry::Utils::HttpTracing
|
|
8
11
|
def add(name, started, _finished, _unique_id, data)
|
|
12
|
+
return unless Sentry.initialized?
|
|
13
|
+
|
|
9
14
|
# skip Rails' internal events
|
|
10
15
|
return if name.start_with?("!")
|
|
11
16
|
|
|
12
17
|
if data.is_a?(Hash)
|
|
13
18
|
data = data.slice(*@allowed_keys[name])
|
|
19
|
+
filter_data_collection!(data)
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
crumb = Sentry::Breadcrumb.new(
|
|
@@ -35,6 +41,30 @@ module Sentry
|
|
|
35
41
|
def detach
|
|
36
42
|
::ActiveSupport::Notifications.unsubscribe(@subscriber)
|
|
37
43
|
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def filter_data_collection!(data)
|
|
48
|
+
filter_params!(data)
|
|
49
|
+
filter_path!(data)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def filter_params!(data)
|
|
53
|
+
return unless data.key?(:params) && data[:params].is_a?(Hash)
|
|
54
|
+
|
|
55
|
+
data[:params] = Sentry.configuration.data_collection.url_query_params.filter(data[:params])
|
|
56
|
+
data.delete(:params) if data[:params].empty?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def filter_path!(data)
|
|
60
|
+
return unless data.key?(:path) && data[:path].is_a?(String)
|
|
61
|
+
|
|
62
|
+
path, query = data[:path].split("?", 2)
|
|
63
|
+
return unless query
|
|
64
|
+
|
|
65
|
+
filtered_query = filter_query_params(query)
|
|
66
|
+
data[:path] = filtered_query ? "#{path}?#{filtered_query}" : path
|
|
67
|
+
end
|
|
38
68
|
end
|
|
39
69
|
end
|
|
40
70
|
end
|
|
@@ -34,7 +34,10 @@ module Sentry
|
|
|
34
34
|
return unless Sentry.initialized?
|
|
35
35
|
return if show_exceptions?(exception, env) && !Sentry.configuration.rails.report_rescued_exceptions
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
options = {}
|
|
38
|
+
options[:contexts] = execution_context if Sentry.configuration.data_collection.user_info
|
|
39
|
+
|
|
40
|
+
Sentry::Rails.capture_exception(exception, **options).tap do |event|
|
|
38
41
|
env[ERROR_EVENT_ID_KEY] = event.event_id if event
|
|
39
42
|
end
|
|
40
43
|
end
|
|
@@ -35,7 +35,13 @@ module Sentry
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
after(:configured) do
|
|
38
|
-
|
|
38
|
+
collection = data_collection.url_query_params
|
|
39
|
+
if collection.mode == :deny_list
|
|
40
|
+
filter_parameters = ::Rails.application.config.filter_parameters.select do |filter|
|
|
41
|
+
filter.is_a?(String) || filter.is_a?(Symbol) || filter.is_a?(Regexp)
|
|
42
|
+
end
|
|
43
|
+
collection.terms = (Array(collection.terms) + filter_parameters).uniq
|
|
44
|
+
end
|
|
39
45
|
end
|
|
40
46
|
end
|
|
41
47
|
|
|
@@ -218,7 +224,7 @@ module Sentry
|
|
|
218
224
|
}.freeze
|
|
219
225
|
|
|
220
226
|
def initialize
|
|
221
|
-
@enabled =
|
|
227
|
+
@enabled = true
|
|
222
228
|
@subscribers = DEFAULT_SUBSCRIBERS.dup
|
|
223
229
|
end
|
|
224
230
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "sentry/utils/http_tracing"
|
|
4
|
+
|
|
3
5
|
module Sentry
|
|
4
6
|
module Rails
|
|
5
7
|
module ControllerTransaction
|
|
@@ -24,9 +26,28 @@ module Sentry
|
|
|
24
26
|
child_span.set_data(:format, request.format)
|
|
25
27
|
child_span.set_data(:method, request.method)
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
data_collection = Sentry.configuration.data_collection
|
|
30
|
+
|
|
31
|
+
path = request.path
|
|
32
|
+
query_parameters = request.query_parameters
|
|
33
|
+
|
|
34
|
+
if query_parameters.is_a?(Hash)
|
|
35
|
+
filtered_query_parameters = data_collection.url_query_params.filter(query_parameters)
|
|
36
|
+
|
|
37
|
+
unless filtered_query_parameters.empty?
|
|
38
|
+
formatted_query = Sentry::Utils::HttpTracing.format_query(filtered_query_parameters)
|
|
39
|
+
path = "#{path}?#{formatted_query}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
child_span.set_data(:path, path)
|
|
44
|
+
|
|
45
|
+
# all params request + body
|
|
46
|
+
params = request.params
|
|
47
|
+
if params.is_a?(Hash)
|
|
48
|
+
filtered_params = data_collection.url_query_params.filter(params)
|
|
49
|
+
child_span.set_data(:params, filtered_params)
|
|
50
|
+
end
|
|
30
51
|
end
|
|
31
52
|
|
|
32
53
|
result
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sentry/rails/log_subscriber"
|
|
4
|
-
require "sentry/rails/log_subscribers/parameter_filter"
|
|
5
4
|
|
|
6
5
|
module Sentry
|
|
7
6
|
module Rails
|
|
@@ -16,13 +15,10 @@ module Sentry
|
|
|
16
15
|
# @example Usage
|
|
17
16
|
# # Enable structured logging for ActionController
|
|
18
17
|
# Sentry.init do |config|
|
|
19
|
-
# config.enable_logs = true
|
|
20
18
|
# config.rails.structured_logging = true
|
|
21
19
|
# config.rails.structured_logging.subscribers = { action_controller: Sentry::Rails::LogSubscribers::ActionControllerSubscriber }
|
|
22
20
|
# end
|
|
23
21
|
class ActionControllerSubscriber < Sentry::Rails::LogSubscriber
|
|
24
|
-
include ParameterFilter
|
|
25
|
-
|
|
26
22
|
# Handle process_action.action_controller events
|
|
27
23
|
#
|
|
28
24
|
# @param event [ActiveSupport::Notifications::Event] The controller action event
|
|
@@ -55,9 +51,9 @@ module Sentry
|
|
|
55
51
|
attributes[:db_runtime_ms] = payload[:db_runtime].round(2)
|
|
56
52
|
end
|
|
57
53
|
|
|
58
|
-
if
|
|
59
|
-
|
|
60
|
-
attributes[:params] =
|
|
54
|
+
if payload[:params].is_a?(Hash)
|
|
55
|
+
params = Sentry.configuration.data_collection.url_query_params.filter(payload[:params])
|
|
56
|
+
attributes[:params] = params unless params.empty?
|
|
61
57
|
end
|
|
62
58
|
|
|
63
59
|
level = level_for_request(payload)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sentry/rails/log_subscriber"
|
|
4
|
-
require "sentry/rails/log_subscribers/parameter_filter"
|
|
5
4
|
|
|
6
5
|
module Sentry
|
|
7
6
|
module Rails
|
|
@@ -15,13 +14,10 @@ module Sentry
|
|
|
15
14
|
# @example Usage
|
|
16
15
|
# # Enable structured logging for ActionMailer
|
|
17
16
|
# Sentry.init do |config|
|
|
18
|
-
# config.enable_logs = true
|
|
19
17
|
# config.rails.structured_logging = true
|
|
20
18
|
# config.rails.structured_logging.subscribers = { action_mailer: Sentry::Rails::LogSubscribers::ActionMailerSubscriber }
|
|
21
19
|
# end
|
|
22
20
|
class ActionMailerSubscriber < Sentry::Rails::LogSubscriber
|
|
23
|
-
include ParameterFilter
|
|
24
|
-
|
|
25
21
|
# Handle deliver.action_mailer events
|
|
26
22
|
#
|
|
27
23
|
# @param event [ActiveSupport::Notifications::Event] The email delivery event
|
|
@@ -41,8 +37,8 @@ module Sentry
|
|
|
41
37
|
attributes[:delivery_method] = payload[:delivery_method] if payload[:delivery_method]
|
|
42
38
|
attributes[:date] = payload[:date].to_s if payload[:date]
|
|
43
39
|
|
|
44
|
-
if Sentry.configuration.
|
|
45
|
-
attributes[:message_id] = payload[:message_id]
|
|
40
|
+
if Sentry.configuration.data_collection.user_info && payload[:message_id]
|
|
41
|
+
attributes[:message_id] = payload[:message_id]
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
message = "Email delivered via #{mailer}"
|
|
@@ -73,9 +69,9 @@ module Sentry
|
|
|
73
69
|
duration_ms: duration
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
if
|
|
77
|
-
|
|
78
|
-
attributes[:params] =
|
|
72
|
+
if payload[:params].is_a?(Hash)
|
|
73
|
+
params = Sentry.configuration.data_collection.url_query_params.filter(payload[:params])
|
|
74
|
+
attributes[:params] = params unless params.empty?
|
|
79
75
|
end
|
|
80
76
|
|
|
81
77
|
message = "#{mailer}##{action}"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sentry/rails/log_subscriber"
|
|
4
|
-
require "sentry/rails/log_subscribers/parameter_filter"
|
|
5
4
|
|
|
6
5
|
module Sentry
|
|
7
6
|
module Rails
|
|
@@ -15,13 +14,10 @@ module Sentry
|
|
|
15
14
|
# @example Usage
|
|
16
15
|
# # Enable structured logging for ActiveJob
|
|
17
16
|
# Sentry.init do |config|
|
|
18
|
-
# config.enable_logs = true
|
|
19
17
|
# config.rails.structured_logging = true
|
|
20
18
|
# config.rails.structured_logging.subscribers = { active_job: Sentry::Rails::LogSubscribers::ActiveJobSubscriber }
|
|
21
19
|
# end
|
|
22
20
|
class ActiveJobSubscriber < Sentry::Rails::LogSubscriber
|
|
23
|
-
include ParameterFilter
|
|
24
|
-
|
|
25
21
|
# Handle perform.active_job events
|
|
26
22
|
#
|
|
27
23
|
# @param event [ActiveSupport::Notifications::Event] The job performance event
|
|
@@ -47,7 +43,7 @@ module Sentry
|
|
|
47
43
|
attributes[:delay_ms] = ((Time.current - job.scheduled_at) * 1000).round(2)
|
|
48
44
|
end
|
|
49
45
|
|
|
50
|
-
if Sentry.configuration.
|
|
46
|
+
if Sentry.configuration.data_collection.queues && job.arguments.present?
|
|
51
47
|
filtered_args = filter_sensitive_arguments(job.arguments)
|
|
52
48
|
attributes[:arguments] = filtered_args unless filtered_args.empty?
|
|
53
49
|
end
|
|
@@ -149,9 +145,11 @@ module Sentry
|
|
|
149
145
|
arguments.map do |arg|
|
|
150
146
|
case arg
|
|
151
147
|
when Hash
|
|
152
|
-
|
|
148
|
+
# we're using url_query_params here since rails filter_parameters end up there
|
|
149
|
+
# and we don't have a dedicated queue params config yet
|
|
150
|
+
Sentry.configuration.data_collection.url_query_params.filter(arg, cookie: false)
|
|
153
151
|
when String
|
|
154
|
-
arg.length > 100 ? "[
|
|
152
|
+
arg.length > 100 ? "[Filtered: #{arg.length} chars]" : arg
|
|
155
153
|
else
|
|
156
154
|
arg
|
|
157
155
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sentry/rails/log_subscriber"
|
|
4
|
-
require "sentry/rails/log_subscribers/parameter_filter"
|
|
5
4
|
|
|
6
5
|
module Sentry
|
|
7
6
|
module Rails
|
|
@@ -16,13 +15,10 @@ module Sentry
|
|
|
16
15
|
# @example Usage
|
|
17
16
|
# # Automatically attached when structured logging is enabled for :active_record
|
|
18
17
|
# Sentry.init do |config|
|
|
19
|
-
# config.enable_logs = true
|
|
20
18
|
# config.rails.structured_logging = true
|
|
21
19
|
# config.rails.structured_logging.subscribers = { active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber }
|
|
22
20
|
# end
|
|
23
21
|
class ActiveRecordSubscriber < Sentry::Rails::LogSubscriber
|
|
24
|
-
include ParameterFilter
|
|
25
|
-
|
|
26
22
|
EXCLUDED_NAMES = ["SCHEMA", "TRANSACTION"].freeze
|
|
27
23
|
EMPTY_ARRAY = [].freeze
|
|
28
24
|
|
|
@@ -49,7 +45,7 @@ module Sentry
|
|
|
49
45
|
|
|
50
46
|
binds = event.payload[:binds]
|
|
51
47
|
|
|
52
|
-
if Sentry.configuration.
|
|
48
|
+
if Sentry.configuration.data_collection.database_query_data && (binds && !binds.empty?)
|
|
53
49
|
type_casted_binds = type_casted_binds(event)
|
|
54
50
|
|
|
55
51
|
type_casted_binds.each_with_index do |value, index|
|
data/lib/sentry/rails/railtie.rb
CHANGED
|
@@ -142,7 +142,7 @@ module Sentry
|
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
def activate_structured_logging
|
|
145
|
-
if Sentry.configuration.rails.structured_logging.enabled?
|
|
145
|
+
if Sentry.configuration.rails.structured_logging.enabled?
|
|
146
146
|
Sentry::Rails::StructuredLogging.attach(Sentry.configuration.rails.structured_logging)
|
|
147
147
|
end
|
|
148
148
|
end
|
|
@@ -34,7 +34,10 @@ module Sentry
|
|
|
34
34
|
) do |span|
|
|
35
35
|
payload.each do |key, value|
|
|
36
36
|
next if key == START_TIMESTAMP_NAME
|
|
37
|
-
|
|
37
|
+
# Active Storage keys are automatically generated storage data,
|
|
38
|
+
# rather than URL/query data. Use the database query-data switch
|
|
39
|
+
# for the legacy PII-compatible on/off behavior.
|
|
40
|
+
next if key == :key && !Sentry.configuration.data_collection.database_query_data
|
|
38
41
|
|
|
39
42
|
span.set_data(key, value)
|
|
40
43
|
end
|
data/lib/sentry/rails/version.rb
CHANGED
data/sentry-rails.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sentry-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 7.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sentry Team
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 7.0.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: 7.0.0
|
|
40
40
|
description: A gem that provides Rails integration for the Sentry error logger
|
|
41
41
|
email: accounts@sentry.io
|
|
42
42
|
executables: []
|
|
@@ -112,7 +112,6 @@ files:
|
|
|
112
112
|
- lib/sentry/rails/log_subscribers/action_mailer_subscriber.rb
|
|
113
113
|
- lib/sentry/rails/log_subscribers/active_job_subscriber.rb
|
|
114
114
|
- lib/sentry/rails/log_subscribers/active_record_subscriber.rb
|
|
115
|
-
- lib/sentry/rails/log_subscribers/parameter_filter.rb
|
|
116
115
|
- lib/sentry/rails/overrides/streaming_reporter.rb
|
|
117
116
|
- lib/sentry/rails/railtie.rb
|
|
118
117
|
- lib/sentry/rails/rescued_exception_interceptor.rb
|
|
@@ -126,15 +125,15 @@ files:
|
|
|
126
125
|
- lib/sentry/rails/tracing/active_support_subscriber.rb
|
|
127
126
|
- lib/sentry/rails/version.rb
|
|
128
127
|
- sentry-rails.gemspec
|
|
129
|
-
homepage: https://github.com/getsentry/sentry-ruby/tree/
|
|
128
|
+
homepage: https://github.com/getsentry/sentry-ruby/tree/7.0.0/sentry-rails
|
|
130
129
|
licenses:
|
|
131
130
|
- MIT
|
|
132
131
|
metadata:
|
|
133
|
-
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/
|
|
134
|
-
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/
|
|
135
|
-
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/
|
|
132
|
+
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.0.0/sentry-rails
|
|
133
|
+
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.0.0/sentry-rails
|
|
134
|
+
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.0.0/CHANGELOG.md
|
|
136
135
|
bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
|
|
137
|
-
documentation_uri: http://www.rubydoc.info/gems/sentry-rails/
|
|
136
|
+
documentation_uri: http://www.rubydoc.info/gems/sentry-rails/7.0.0
|
|
138
137
|
rdoc_options: []
|
|
139
138
|
require_paths:
|
|
140
139
|
- lib
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Sentry
|
|
4
|
-
module Rails
|
|
5
|
-
module LogSubscribers
|
|
6
|
-
# Shared utility module for filtering sensitive parameters in log subscribers.
|
|
7
|
-
#
|
|
8
|
-
# This module provides consistent parameter filtering across all Sentry Rails
|
|
9
|
-
# log subscribers, leveraging Rails' built-in parameter filtering when available.
|
|
10
|
-
# It automatically detects the correct Rails parameter filtering API based on
|
|
11
|
-
# the Rails version and includes the appropriate implementation module.
|
|
12
|
-
#
|
|
13
|
-
# @example Usage in a log subscriber
|
|
14
|
-
# class MySubscriber < Sentry::Rails::LogSubscriber
|
|
15
|
-
# include Sentry::Rails::LogSubscribers::ParameterFilter
|
|
16
|
-
#
|
|
17
|
-
# def my_event(event)
|
|
18
|
-
# if Sentry.configuration.send_default_pii && event.payload[:params]
|
|
19
|
-
# filtered_params = filter_sensitive_params(event.payload[:params])
|
|
20
|
-
# attributes[:params] = filtered_params unless filtered_params.empty?
|
|
21
|
-
# end
|
|
22
|
-
# end
|
|
23
|
-
# end
|
|
24
|
-
module ParameterFilter
|
|
25
|
-
EMPTY_HASH = {}.freeze
|
|
26
|
-
|
|
27
|
-
if ::Rails.version.to_f >= 6.0
|
|
28
|
-
def self.backend
|
|
29
|
-
ActiveSupport::ParameterFilter
|
|
30
|
-
end
|
|
31
|
-
else
|
|
32
|
-
def self.backend
|
|
33
|
-
ActionDispatch::Http::ParameterFilter
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Filter sensitive parameters from a hash, respecting Rails configuration.
|
|
38
|
-
#
|
|
39
|
-
# @param params [Hash] The parameters to filter
|
|
40
|
-
# @return [Hash] Filtered parameters with sensitive data removed
|
|
41
|
-
def filter_sensitive_params(params)
|
|
42
|
-
return EMPTY_HASH unless params.is_a?(Hash)
|
|
43
|
-
|
|
44
|
-
filter_parameters = ::Rails.application.config.filter_parameters
|
|
45
|
-
parameter_filter = ParameterFilter.backend.new(filter_parameters)
|
|
46
|
-
|
|
47
|
-
parameter_filter.filter(params)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|