Remove NewRelic integration.

Remove the NewRelic integration in preparation for migrating to Elastic APM instead.
This commit is contained in:
evazion
2022-04-11 01:09:36 -05:00
parent 05261bf6d7
commit 98b313f8de
11 changed files with 20 additions and 66 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 } } })

View File

@@ -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">

View File

@@ -1,7 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<%= NewRelic::Agent.browser_timing_header rescue "" %>
<meta charset="utf-8">
<title><%= page_title %></title>