Skip to content

Commit

Permalink
Disable log_arguments for AnalyticsJobs
Browse files Browse the repository at this point in the history
For Rails 6.0, which doesn't support this, turn of :info logging
altogether.
  • Loading branch information
duncanjbrown committed Sep 21, 2022
1 parent 8edb8f2 commit c27c002
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/dfe/analytics/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class Railtie < Rails::Railtie
app.config.middleware.use DfE::Analytics::Middleware::RequestIdentity
end

initializer 'dfe.analytics.logger' do
ActiveSupport.on_load(:active_job) do
analytics_job = DfE::Analytics::AnalyticsJob
# Rails < 6.1 doesn't support log_arguments = false so we only log warn
# to prevent wild log inflation
if analytics_job.respond_to?(:log_arguments=)
analytics_job.log_arguments = false
else
analytics_job.logger = ::Rails.logger.dup.tap { |l| l.level = Logger::WARN }
end
end
end

config.after_initialize do
# internal gem tests will sometimes suppress this so they can test the
# init process
Expand Down
1 change: 1 addition & 0 deletions lib/dfe/analytics/send_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.do(events)

def perform(events)
if DfE::Analytics.log_only?
# Use the Rails logger here as the job's logger is set to :warn by default
Rails.logger.info("DfE::Analytics: #{events.inspect}")
else
response = DfE::Analytics.events_client.insert(events, ignore_unknown: true)
Expand Down

0 comments on commit c27c002

Please sign in to comment.