Last active
January 22, 2024 20:39
-
-
Save n3bulous/df8abc8cbe21d96f2e11a49da7a572c1 to your computer and use it in GitHub Desktop.
Lograge with NewRelic Config
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
# Shared by Martin Streicher in the Rails Performance Slack | |
# https://railsperf.slack.com/archives/C0RUUGY6R/p1702565130357359 | |
# | |
config.lograge.enabled = true # see lograge section below... | |
config.lograge.formatter = Lograge::Formatters::Logstash.new | |
config.log_formatter = ::NewRelic::Agent::Logging::DecoratingFormatter.new | |
config.lograge.custom_options = | |
lambda do |event| | |
payload = event.payload | |
parameter_filter = | |
ActiveSupport::ParameterFilter.new( | |
Rails.application.config.filter_parameters | |
) | |
params = | |
parameter_filter.filter( | |
payload.fetch(:params, {}).except(*ActionController::LogSubscriber::INTERNAL_PARAMS) | |
) | |
{ | |
log_type: "api", | |
request_id: payload[:request_id], | |
params: params.to_json, | |
exception: payload[:exception], # ["ExceptionClass", "the message"] | |
backtrace: payload[:exception_object]&.backtrace&.join(" -- ") # the exception instance | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ended up using the following for JSON-only logging
with app/application_controller.rb