Remove NewRelic integration.
Remove the NewRelic integration in preparation for migrating to Elastic APM instead.
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -44,7 +44,6 @@ gem 'google-cloud-storage', require: "google/cloud/storage"
|
||||
gem 'ed25519'
|
||||
gem 'bcrypt_pbkdf' # https://github.com/net-ssh/net-ssh/issues/565
|
||||
gem 'terminal-table'
|
||||
gem 'newrelic_rpm', require: false
|
||||
gem 'clockwork'
|
||||
gem 'puma-metrics'
|
||||
gem 'puma_worker_killer'
|
||||
|
||||
@@ -309,7 +309,6 @@ GEM
|
||||
digest
|
||||
net-protocol
|
||||
timeout
|
||||
newrelic_rpm (8.5.0)
|
||||
nio4r (2.5.8)
|
||||
nokogiri (1.13.3)
|
||||
mini_portile2 (~> 2.8.0)
|
||||
@@ -555,7 +554,6 @@ DEPENDENCIES
|
||||
minitest-reporters
|
||||
mocha
|
||||
mock_redis
|
||||
newrelic_rpm
|
||||
nokogiri
|
||||
oauth2
|
||||
parallel
|
||||
|
||||
@@ -59,7 +59,6 @@ import Upload from "../src/javascripts/uploads.js";
|
||||
import UserTooltip from "../src/javascripts/user_tooltips.js";
|
||||
import Utility from "../src/javascripts/utility.js";
|
||||
import Ugoira from "../src/javascripts/ugoira.js"
|
||||
import NewRelic from "../src/javascripts/new_relic.js";
|
||||
|
||||
let Danbooru = {};
|
||||
Danbooru.Autocomplete = Autocomplete;
|
||||
@@ -87,7 +86,6 @@ Danbooru.Upload = Upload;
|
||||
Danbooru.UserTooltip = UserTooltip;
|
||||
Danbooru.Utility = Utility;
|
||||
Danbooru.Ugoira = Ugoira;
|
||||
Danbooru.NewRelic = NewRelic;
|
||||
|
||||
Danbooru.notice = Utility.notice;
|
||||
Danbooru.error = Utility.error;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
class NewRelic {
|
||||
static initialize_all() {
|
||||
/* https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-spa-api/setcustomattribute-browser-agent-api/ */
|
||||
if (typeof window.newrelic === "object") {
|
||||
window.newrelic.setCustomAttribute("screenWidth", window.screen.width);
|
||||
window.newrelic.setCustomAttribute("screenHeight", window.screen.height);
|
||||
window.newrelic.setCustomAttribute("screenResolution", `${window.screen.width}x${window.screen.height}`);
|
||||
window.newrelic.setCustomAttribute("devicePixelRatio", window.devicePixelRatio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NewRelic.initialize_all();
|
||||
export default NewRelic;
|
||||
@@ -1,27 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# The DanbooruLogger class handles logging messages to the Rails log and to NewRelic.
|
||||
# The DanbooruLogger class handles logging messages to the Rails log and to the APM.
|
||||
#
|
||||
# @see https://guides.rubyonrails.org/debugging_rails_applications.html#the-logger
|
||||
# @see https://docs.newrelic.com
|
||||
class DanbooruLogger
|
||||
HEADERS = %w[referer sec-fetch-dest sec-fetch-mode sec-fetch-site sec-fetch-user]
|
||||
|
||||
# Log a message to the Rails log and to NewRelic.
|
||||
# Log a message to the Rails log and to the APM.
|
||||
#
|
||||
# @param message [String] the message to log
|
||||
# @param params [Hash] optional key-value data to log with the message
|
||||
def self.info(message, params = {})
|
||||
Rails.logger.info(message)
|
||||
|
||||
if defined?(::NewRelic)
|
||||
params = flatten_hash(params).symbolize_keys
|
||||
::NewRelic::Agent.record_custom_event(:info, message: message, **params)
|
||||
end
|
||||
params = flatten_hash(params).symbolize_keys
|
||||
log_event(:info, message: message, **params)
|
||||
end
|
||||
|
||||
# Log an exception to the Rails log and to NewRelic. The `expected` flag is
|
||||
# Log an exception to the Rails log and to the APM. The `expected` flag is
|
||||
# used to separate expected exceptions, like search timeouts or auth failures,
|
||||
# from unexpected exceptions, like runtime errors, in the NewRelic error log.
|
||||
# from unexpected exceptions, like runtime errors, in the error logs.
|
||||
#
|
||||
# @param message [Exception] the exception to log
|
||||
# @param expected [Boolean] whether the exception was expected
|
||||
@@ -34,12 +32,10 @@ class DanbooruLogger
|
||||
Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}")
|
||||
end
|
||||
|
||||
if defined?(::NewRelic)
|
||||
::NewRelic::Agent.notice_error(exception, expected: expected, custom_params: params)
|
||||
end
|
||||
log_exception(exception, expected: expected, custom_params: params)
|
||||
end
|
||||
|
||||
# Log extra HTTP request data to NewRelic. Logs the user's IP, user agent,
|
||||
# Log extra HTTP request data to the APM. Logs the user's IP, user agent,
|
||||
# request params, and session cookies.
|
||||
#
|
||||
# @param request the HTTP request
|
||||
@@ -84,15 +80,18 @@ class DanbooruLogger
|
||||
def self.add_attributes(prefix, hash)
|
||||
attributes = flatten_hash(hash).transform_keys { |key| "#{prefix}.#{key}" }
|
||||
attributes.delete_if { |key, value| key.end_with?(*Rails.application.config.filter_parameters.map(&:to_s)) }
|
||||
add_custom_attributes(attributes)
|
||||
log_attributes(attributes)
|
||||
end
|
||||
|
||||
private_class_method
|
||||
|
||||
# @see https://docs.newrelic.com/docs/using-new-relic/data/customize-data/collect-custom-attributes/#ruby-att
|
||||
def self.add_custom_attributes(attributes)
|
||||
return unless defined?(::NewRelic)
|
||||
::NewRelic::Agent.add_custom_attributes(attributes)
|
||||
def self.log_attributes(attributes)
|
||||
end
|
||||
|
||||
def self.log_exception(exception, expected: false, custom_params: {})
|
||||
end
|
||||
|
||||
def self.log_event(level, message: nil, **params)
|
||||
end
|
||||
|
||||
# flatten_hash({ foo: { bar: { baz: 42 } } })
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<%= NewRelic::Agent.browser_timing_header rescue "" %>
|
||||
<meta charset="utf-8">
|
||||
<title><%= page_title %></title>
|
||||
<link rel="icon" href="/favicon.ico" sizes="16x16" type="image/x-icon">
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<%= NewRelic::Agent.browser_timing_header rescue "" %>
|
||||
<meta charset="utf-8">
|
||||
<title><%= page_title %></title>
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ module Danbooru
|
||||
config.active_record.schema_format = :sql
|
||||
config.encoding = "utf-8"
|
||||
|
||||
# Hide sensitive model attributes and request params in exception messages,
|
||||
# log files, and in NewRelic. These are substring matches, so they match
|
||||
# any attribute or request param containing the word 'password' etc.
|
||||
# Hide sensitive model attributes and request params in exception messages
|
||||
# and logs. These are substring matches, so they match any attribute or
|
||||
# request param containing the word 'password' etc.
|
||||
#
|
||||
# https://guides.rubyonrails.org/configuring.html#config-filter-parameters
|
||||
config.filter_parameters += [:password, :api_key, :secret, :ip_addr, :address, :email_verification_key, :signed_user_id] if Rails.env.production?
|
||||
|
||||
@@ -547,12 +547,6 @@ module Danbooru
|
||||
# "redis://localhost:6379"
|
||||
end
|
||||
|
||||
# Optional. The license key for your New Relic account.
|
||||
# https://newrelic.com/
|
||||
# https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/new-relic-license-key/
|
||||
def new_relic_license_key
|
||||
end
|
||||
|
||||
# True if the Winter Sale is active.
|
||||
def is_promotion?
|
||||
false
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
if Danbooru.config.new_relic_license_key.present?
|
||||
require "new_relic/control"
|
||||
|
||||
# https://github.com/newrelic/newrelic-ruby-agent/blob/1ef4082fe97fd19aeccb3f392a44ef3becae66d3/lib/newrelic_rpm.rb#L40
|
||||
# https://github.com/newrelic/newrelic-ruby-agent/blob/1ef4082fe97fd19aeccb3f392a44ef3becae66d3/lib/new_relic/agent.rb#L349
|
||||
NewRelic::Control.instance.init_plugin(
|
||||
app_name: Danbooru.config.canonical_app_name,
|
||||
license_key: Danbooru.config.new_relic_license_key,
|
||||
log_level: Danbooru.config.debug_mode ? "debug" : "error",
|
||||
#log: Rails.logger,
|
||||
"rake.tasks": ["maintenance:.*"],
|
||||
"browser_monitoring.auto_instrument": false,
|
||||
config: Rails.application.config,
|
||||
)
|
||||
end
|
||||
@@ -1,6 +1,3 @@
|
||||
require "newrelic_rpm"
|
||||
require "tasks/newrelic"
|
||||
|
||||
# This file contains commands for running various routine maintenance tasks on
|
||||
# a Danbooru instance. Run `bin/rails -T` to see a list of all available tasks.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user