asklytics-influxdb-rails 1.0.0.beta3
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +78 -0
- data/.travis.yml +37 -0
- data/CHANGELOG.md +127 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +291 -0
- data/Rakefile +34 -0
- data/config.ru +7 -0
- data/gemfiles/Gemfile.rails-4.2.x +7 -0
- data/gemfiles/Gemfile.rails-5.0.x +7 -0
- data/gemfiles/Gemfile.rails-5.1.x +7 -0
- data/gemfiles/Gemfile.rails-5.2.x +7 -0
- data/influxdb-rails.gemspec +52 -0
- data/lib/httplog.rb +8 -0
- data/lib/influxdb-rails.rb +134 -0
- data/lib/influxdb/rails/air_traffic_controller.rb +41 -0
- data/lib/influxdb/rails/backtrace.rb +44 -0
- data/lib/influxdb/rails/configuration.rb +263 -0
- data/lib/influxdb/rails/context.rb +42 -0
- data/lib/influxdb/rails/exception_presenter.rb +94 -0
- data/lib/influxdb/rails/httplog/adapters/ethon.rb +62 -0
- data/lib/influxdb/rails/httplog/adapters/excon.rb +67 -0
- data/lib/influxdb/rails/httplog/adapters/http.rb +64 -0
- data/lib/influxdb/rails/httplog/adapters/httpclient.rb +76 -0
- data/lib/influxdb/rails/httplog/adapters/net_http.rb +53 -0
- data/lib/influxdb/rails/httplog/adapters/patron.rb +44 -0
- data/lib/influxdb/rails/httplog/helpers/al_helper.rb +12 -0
- data/lib/influxdb/rails/httplog/http_configuration.rb +55 -0
- data/lib/influxdb/rails/httplog/http_log.rb +332 -0
- data/lib/influxdb/rails/instrumentation.rb +34 -0
- data/lib/influxdb/rails/logger.rb +16 -0
- data/lib/influxdb/rails/middleware/hijack_render_exception.rb +16 -0
- data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +31 -0
- data/lib/influxdb/rails/middleware/render_subscriber.rb +28 -0
- data/lib/influxdb/rails/middleware/request_subscriber.rb +69 -0
- data/lib/influxdb/rails/middleware/simple_subscriber.rb +71 -0
- data/lib/influxdb/rails/middleware/sql_subscriber.rb +35 -0
- data/lib/influxdb/rails/middleware/subscriber.rb +44 -0
- data/lib/influxdb/rails/rack.rb +39 -0
- data/lib/influxdb/rails/railtie.rb +52 -0
- data/lib/influxdb/rails/sql/normalizer.rb +27 -0
- data/lib/influxdb/rails/sql/query.rb +32 -0
- data/lib/influxdb/rails/version.rb +5 -0
- data/lib/rails/generators/influxdb/influxdb_generator.rb +15 -0
- data/lib/rails/generators/influxdb/templates/initializer.rb +11 -0
- data/spec/controllers/widgets_controller_spec.rb +15 -0
- data/spec/integration/exceptions_spec.rb +37 -0
- data/spec/integration/integration_helper.rb +1 -0
- data/spec/integration/metrics_spec.rb +28 -0
- data/spec/shared_examples/tags.rb +42 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/rails4/app.rb +44 -0
- data/spec/support/rails5/app.rb +44 -0
- data/spec/support/views/widgets/_item.html.erb +1 -0
- data/spec/support/views/widgets/index.html.erb +5 -0
- data/spec/unit/backtrace_spec.rb +85 -0
- data/spec/unit/configuration_spec.rb +125 -0
- data/spec/unit/context_spec.rb +40 -0
- data/spec/unit/exception_presenter_spec.rb +23 -0
- data/spec/unit/influxdb_rails_spec.rb +78 -0
- data/spec/unit/middleware/render_subscriber_spec.rb +92 -0
- data/spec/unit/middleware/request_subscriber_spec.rb +91 -0
- data/spec/unit/middleware/sql_subscriber_spec.rb +81 -0
- data/spec/unit/sql/normalizer_spec.rb +15 -0
- data/spec/unit/sql/query_spec.rb +29 -0
- metadata +487 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rubocop/rake_task"
|
|
3
|
+
RuboCop::RakeTask.new
|
|
4
|
+
|
|
5
|
+
targeted_files = ARGV.drop(1)
|
|
6
|
+
file_pattern = targeted_files.empty? ? "spec/**/*_spec.rb" : targeted_files
|
|
7
|
+
|
|
8
|
+
require "rspec/core"
|
|
9
|
+
require "rspec/core/rake_task"
|
|
10
|
+
|
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
12
|
+
t.pattern = FileList[file_pattern]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RSpec.configure do |config|
|
|
16
|
+
config.color = true
|
|
17
|
+
config.formatter = :documentation
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
task default: %i[spec rubocop]
|
|
21
|
+
|
|
22
|
+
task "test:all" => :default do
|
|
23
|
+
Dir.glob("gemfiles/Gemfile.rails-*.x") do |gemfile|
|
|
24
|
+
if RUBY_VERSION >= "2.6.0" && gemfile == "gemfiles/Gemfile.rails-4.2.x"
|
|
25
|
+
msg = "ignore #{gemfile} on Ruby #{RUBY_VERSION}"
|
|
26
|
+
puts RSpec::Core::Formatters::ConsoleCodes.wrap(msg, :yellow)
|
|
27
|
+
next
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
puts RSpec::Core::Formatters::ConsoleCodes.wrap(gemfile, :cyan)
|
|
31
|
+
sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "install", "--quiet", "--retry=2", "--jobs=2")
|
|
32
|
+
sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "exec", "rspec")
|
|
33
|
+
end
|
|
34
|
+
end
|
data/config.ru
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "influxdb/rails/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "asklytics-influxdb-rails"
|
|
7
|
+
spec.version = InfluxDB::Rails::VERSION
|
|
8
|
+
spec.authors = ["Gildas darex"]
|
|
9
|
+
spec.email = ["tdarex@asklytics.io"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Instrumentation of rails app"
|
|
12
|
+
spec.description = "Instrumentation of rails app"
|
|
13
|
+
spec.homepage = "http://www.asklytics.io"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars
|
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/})
|
|
18
|
+
spec.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
spec.required_ruby_version = ">= 2.3.0"
|
|
21
|
+
|
|
22
|
+
spec.add_runtime_dependency "influxdb", "~> 0.6", ">= 0.6.4"
|
|
23
|
+
spec.add_runtime_dependency "railties", ">= 4.2"
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "activerecord"
|
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.0.0"
|
|
27
|
+
spec.add_development_dependency "fakeweb"
|
|
28
|
+
#spec.add_development_dependency "rake"
|
|
29
|
+
spec.add_development_dependency "rdoc"
|
|
30
|
+
#spec.add_development_dependency "rspec"
|
|
31
|
+
spec.add_development_dependency "rspec-rails", ">= 3.0.0"
|
|
32
|
+
spec.add_development_dependency "rubocop", "~> 0.61.1"
|
|
33
|
+
spec.add_development_dependency "sqlite3"
|
|
34
|
+
spec.add_development_dependency "tzinfo"
|
|
35
|
+
|
|
36
|
+
spec.add_development_dependency 'ethon', ['~> 0.11']
|
|
37
|
+
spec.add_development_dependency 'excon', ['~> 0.60']
|
|
38
|
+
spec.add_development_dependency 'faraday', ['~> 0.14']
|
|
39
|
+
spec.add_development_dependency 'guard-rspec', ['~> 4.7']
|
|
40
|
+
spec.add_development_dependency 'http', ['~> 4.0']
|
|
41
|
+
spec.add_development_dependency 'httparty', ['~> 0.16']
|
|
42
|
+
spec.add_development_dependency 'httpclient', ['~> 2.8']
|
|
43
|
+
spec.add_development_dependency 'listen', ['~> 3.0']
|
|
44
|
+
spec.add_development_dependency 'patron', ['~> 0.12']
|
|
45
|
+
spec.add_development_dependency 'rake', ['~> 12.3.2']
|
|
46
|
+
spec.add_development_dependency 'rspec', ['~> 3.7']
|
|
47
|
+
spec.add_development_dependency 'simplecov', ['~> 0.15']
|
|
48
|
+
spec.add_development_dependency 'thin', ['~> 1.7']
|
|
49
|
+
|
|
50
|
+
spec.add_dependency 'rack', ['>= 1.0']
|
|
51
|
+
spec.add_dependency 'rainbow', ['>= 2.0.0']
|
|
52
|
+
end
|
data/lib/httplog.rb
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'influxdb/rails/httplog/http_configuration'
|
|
2
|
+
require 'influxdb/rails/httplog/http_log'
|
|
3
|
+
require 'influxdb/rails/httplog/adapters/net_http'
|
|
4
|
+
require 'influxdb/rails/httplog/adapters/httpclient'
|
|
5
|
+
require 'influxdb/rails/httplog/adapters/excon'
|
|
6
|
+
require 'influxdb/rails/httplog/adapters/ethon'
|
|
7
|
+
require 'influxdb/rails/httplog/adapters/patron'
|
|
8
|
+
require 'influxdb/rails/httplog/adapters/http'
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "net/https"
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "influxdb/rails/middleware/render_subscriber"
|
|
6
|
+
require "influxdb/rails/middleware/request_subscriber"
|
|
7
|
+
require "influxdb/rails/middleware/sql_subscriber"
|
|
8
|
+
require "influxdb/rails/sql/query"
|
|
9
|
+
require "influxdb/rails/version"
|
|
10
|
+
require "influxdb/rails/logger"
|
|
11
|
+
require "influxdb/rails/exception_presenter"
|
|
12
|
+
require "influxdb/rails/configuration"
|
|
13
|
+
require "influxdb/rails/backtrace"
|
|
14
|
+
require "influxdb/rails/context"
|
|
15
|
+
require "influxdb/rails/rack"
|
|
16
|
+
|
|
17
|
+
require "influxdb/rails/railtie" if defined?(Rails::Railtie)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
module InfluxDB
|
|
21
|
+
# InfluxDB::Rails contains the glue code needed to integrate with
|
|
22
|
+
# InfluxDB and Rails. This is a singleton class.
|
|
23
|
+
module Rails
|
|
24
|
+
class << self
|
|
25
|
+
include InfluxDB::Rails::Logger
|
|
26
|
+
|
|
27
|
+
attr_writer :configuration
|
|
28
|
+
attr_writer :client
|
|
29
|
+
|
|
30
|
+
def configure(_silent = false)
|
|
31
|
+
yield(configuration)
|
|
32
|
+
|
|
33
|
+
# if we change configuration, reload the client
|
|
34
|
+
self.client = nil
|
|
35
|
+
|
|
36
|
+
InfluxDB::Logging.logger = configuration.logger unless configuration.logger.nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# rubocop:disable Metrics/MethodLength
|
|
40
|
+
# rubocop:disable Metrics/AbcSize
|
|
41
|
+
|
|
42
|
+
def client
|
|
43
|
+
@client ||= InfluxDB::Client.new \
|
|
44
|
+
database: configuration.influxdb_database,
|
|
45
|
+
username: configuration.influxdb_username,
|
|
46
|
+
password: configuration.influxdb_password,
|
|
47
|
+
hosts: configuration.influxdb_hosts,
|
|
48
|
+
port: configuration.influxdb_port,
|
|
49
|
+
async: configuration.async,
|
|
50
|
+
use_ssl: configuration.use_ssl,
|
|
51
|
+
retry: configuration.retry,
|
|
52
|
+
open_timeout: configuration.open_timeout,
|
|
53
|
+
read_timeout: configuration.read_timeout,
|
|
54
|
+
max_delay: configuration.max_delay,
|
|
55
|
+
time_precision: configuration.time_precision
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
|
59
|
+
# rubocop:enable Metrics/AbcSize
|
|
60
|
+
|
|
61
|
+
def configuration
|
|
62
|
+
@configuration ||= InfluxDB::Rails::Configuration.new
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# def configuration_http_tracing
|
|
67
|
+
# HttpLog.configure do |config|
|
|
68
|
+
# config.enable_http_tracing = configuration.enable_http_tracing
|
|
69
|
+
# config.http_tracing_id = configuration.http_tracing_id
|
|
70
|
+
# config.series_name_for_http_client_log = configuration.series_name_for_http_client_log
|
|
71
|
+
# end
|
|
72
|
+
# end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def current
|
|
76
|
+
@current ||= InfluxDB::Rails::Context.new
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def report_exception_unless_ignorable(ex, env = {})
|
|
80
|
+
report_exception(ex, env) unless ignorable_exception?(ex)
|
|
81
|
+
end
|
|
82
|
+
alias transmit_unless_ignorable report_exception_unless_ignorable
|
|
83
|
+
|
|
84
|
+
# rubocop:disable Metrics/MethodLength
|
|
85
|
+
# rubocop:disable Metrics/AbcSize
|
|
86
|
+
|
|
87
|
+
def report_exception(ex, env = {})
|
|
88
|
+
timestamp = InfluxDB::Rails.current_timestamp
|
|
89
|
+
env = influxdb_request_data if env.empty? && defined? influxdb_request_data
|
|
90
|
+
exception_presenter = ExceptionPresenter.new(ex, env)
|
|
91
|
+
log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
|
|
92
|
+
tags = configuration.tags_middleware.call(
|
|
93
|
+
exception_presenter.context.merge(exception_presenter.dimensions)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
client.write_point \
|
|
97
|
+
configuration.series_name_for_exceptions,
|
|
98
|
+
values: exception_presenter.values.merge(ts: timestamp),
|
|
99
|
+
tags: tags,
|
|
100
|
+
timestamp: timestamp
|
|
101
|
+
rescue StandardError => ex
|
|
102
|
+
log :info, "[InfluxDB::Rails] Something went terribly wrong." \
|
|
103
|
+
" Exception failed to take off! #{ex.class}: #{ex.message}"
|
|
104
|
+
end
|
|
105
|
+
alias transmit report_exception
|
|
106
|
+
|
|
107
|
+
# rubocop:enable Metrics/MethodLength
|
|
108
|
+
# rubocop:enable Metrics/AbcSize
|
|
109
|
+
|
|
110
|
+
def current_timestamp
|
|
111
|
+
InfluxDB.now(configuration.time_precision)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def ignorable_exception?(ex)
|
|
115
|
+
configuration.ignore_current_environment? || configuration.ignore_exception?(ex)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def rescue
|
|
119
|
+
yield
|
|
120
|
+
rescue StandardError => ex
|
|
121
|
+
raise ex if configuration.ignore_current_environment?
|
|
122
|
+
|
|
123
|
+
transmit_unless_ignorable(ex)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def rescue_and_reraise
|
|
127
|
+
yield
|
|
128
|
+
rescue StandardError => ex
|
|
129
|
+
transmit_unless_ignorable(ex)
|
|
130
|
+
raise ex
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module InfluxDB
|
|
2
|
+
module Rails
|
|
3
|
+
module AirTrafficController # :nodoc:
|
|
4
|
+
def influxdb_request_data # rubocop:disable Metrics/MethodLength
|
|
5
|
+
{
|
|
6
|
+
params: influxdb_filtered_params,
|
|
7
|
+
session_data: influxdb_session_data,
|
|
8
|
+
controller: params[:controller],
|
|
9
|
+
action: params[:action],
|
|
10
|
+
request_url: influxdb_request_url,
|
|
11
|
+
user_agent: request.env["HTTP_USER_AGENT"],
|
|
12
|
+
remote_ip: request.remote_ip,
|
|
13
|
+
referer: request.referer,
|
|
14
|
+
current_user: (current_user rescue nil),
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def influxdb_session_data
|
|
21
|
+
session.respond_to?(:to_hash) ? session.to_hash : session.data
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def influxdb_request_url
|
|
25
|
+
url = "#{request.protocol}#{request.host}"
|
|
26
|
+
url << ":#{request.port}" unless [80, 443].include?(request.port)
|
|
27
|
+
url << request.fullpath
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def influxdb_filtered_params
|
|
31
|
+
if respond_to?(:filter_parameters)
|
|
32
|
+
filter_parameters(unfiltered_params)
|
|
33
|
+
elsif defined?(request.filtered_parameters)
|
|
34
|
+
request.filtered_parameters
|
|
35
|
+
else
|
|
36
|
+
params.to_hash.except(:password, :password_confirmation)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module InfluxDB
|
|
2
|
+
module Rails
|
|
3
|
+
class Backtrace # rubocop:disable Style/Documentation
|
|
4
|
+
class Line # rubocop:disable Style/Documentation
|
|
5
|
+
FORMAT = /^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/.freeze
|
|
6
|
+
|
|
7
|
+
attr_reader :file
|
|
8
|
+
attr_reader :number
|
|
9
|
+
attr_reader :method
|
|
10
|
+
|
|
11
|
+
def initialize(line)
|
|
12
|
+
_, @file, @number, @method = line.match(FORMAT).to_a
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
"#{file}:#{number} in `#{method}'"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def inspect
|
|
20
|
+
"<Line: #{to_s}>" # rubocop:disable Lint/StringConversionInInterpolation
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :lines
|
|
25
|
+
|
|
26
|
+
def initialize(backtrace)
|
|
27
|
+
@lines = Array(backtrace).each.collect do |line|
|
|
28
|
+
InfluxDB::Rails.configuration.backtrace_filters.each do |filter|
|
|
29
|
+
line = filter.call(line)
|
|
30
|
+
end
|
|
31
|
+
Line.new(line)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_a
|
|
36
|
+
lines.map(&:to_s)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def inspect
|
|
40
|
+
"<Backtrace: " + lines.collect(&:to_s).join(", ") + ">"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
module InfluxDB
|
|
2
|
+
module Rails
|
|
3
|
+
# rubocop:disable Metrics/ClassLength
|
|
4
|
+
|
|
5
|
+
class Configuration # rubocop:disable Style/Documentation
|
|
6
|
+
attr_accessor :influxdb_hosts
|
|
7
|
+
attr_accessor :influxdb_port
|
|
8
|
+
attr_accessor :influxdb_username
|
|
9
|
+
attr_accessor :influxdb_password
|
|
10
|
+
attr_accessor :influxdb_database
|
|
11
|
+
attr_accessor :async
|
|
12
|
+
attr_accessor :use_ssl
|
|
13
|
+
attr_accessor :retry
|
|
14
|
+
attr_accessor :open_timeout
|
|
15
|
+
attr_accessor :read_timeout
|
|
16
|
+
attr_accessor :max_delay
|
|
17
|
+
attr_accessor :time_precision
|
|
18
|
+
|
|
19
|
+
attr_accessor :series_name_for_controller_runtimes
|
|
20
|
+
attr_accessor :series_name_for_view_runtimes
|
|
21
|
+
attr_accessor :series_name_for_db_runtimes
|
|
22
|
+
attr_accessor :series_name_for_exceptions
|
|
23
|
+
attr_accessor :series_name_for_instrumentation
|
|
24
|
+
attr_accessor :series_name_for_render_template
|
|
25
|
+
attr_accessor :series_name_for_render_partial
|
|
26
|
+
attr_accessor :series_name_for_render_collection
|
|
27
|
+
attr_accessor :series_name_for_sql
|
|
28
|
+
|
|
29
|
+
attr_accessor :tags_middleware
|
|
30
|
+
attr_accessor :rails_app_name
|
|
31
|
+
|
|
32
|
+
attr_accessor :application_name
|
|
33
|
+
attr_accessor :application_root
|
|
34
|
+
|
|
35
|
+
attr_accessor :logger
|
|
36
|
+
attr_accessor :environment
|
|
37
|
+
attr_accessor :framework
|
|
38
|
+
attr_accessor :framework_version
|
|
39
|
+
attr_accessor :language
|
|
40
|
+
attr_accessor :language_version
|
|
41
|
+
attr_accessor :ignored_exceptions
|
|
42
|
+
attr_accessor :ignored_exception_messages
|
|
43
|
+
attr_accessor :ignored_reports
|
|
44
|
+
attr_accessor :ignored_environments
|
|
45
|
+
attr_accessor :ignored_user_agents
|
|
46
|
+
attr_accessor :backtrace_filters
|
|
47
|
+
attr_accessor :aggregated_exception_classes
|
|
48
|
+
attr_accessor :environment_variables
|
|
49
|
+
attr_accessor :environment_variable_filters
|
|
50
|
+
|
|
51
|
+
attr_accessor :instrumentation_enabled
|
|
52
|
+
attr_accessor :debug
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Http logs
|
|
56
|
+
# attr_accessor :enabled
|
|
57
|
+
# attr_accessor :compact_log
|
|
58
|
+
# attr_accessor :json_log
|
|
59
|
+
# attr_accessor :logger
|
|
60
|
+
# attr_accessor :logger_method
|
|
61
|
+
# attr_accessor :severity
|
|
62
|
+
# attr_accessor :prefix
|
|
63
|
+
# attr_accessor :log_connect
|
|
64
|
+
# attr_accessor :log_request
|
|
65
|
+
# attr_accessor :log_headers
|
|
66
|
+
# attr_accessor :log_data
|
|
67
|
+
# attr_accessor :log_status
|
|
68
|
+
# attr_accessor :log_response
|
|
69
|
+
# attr_accessor :log_benchmark
|
|
70
|
+
# attr_accessor :url_whitelist_pattern
|
|
71
|
+
# attr_accessor :url_blacklist_pattern
|
|
72
|
+
# attr_accessor :color
|
|
73
|
+
# attr_accessor :prefix_data_lines
|
|
74
|
+
# attr_accessor :prefix_response_lines
|
|
75
|
+
# attr_accessor :prefix_line_numbers
|
|
76
|
+
# attr_accessor :filter_parameters
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
DEFAULTS = {
|
|
80
|
+
influxdb_hosts: ["localhost"].freeze,
|
|
81
|
+
influxdb_port: 8086,
|
|
82
|
+
influxdb_username: "root".freeze,
|
|
83
|
+
influxdb_password: "root".freeze,
|
|
84
|
+
influxdb_database: nil,
|
|
85
|
+
async: true,
|
|
86
|
+
use_ssl: false,
|
|
87
|
+
retry: nil,
|
|
88
|
+
open_timeout: 5,
|
|
89
|
+
read_timeout: 300,
|
|
90
|
+
max_delay: 30,
|
|
91
|
+
time_precision: "s".freeze,
|
|
92
|
+
|
|
93
|
+
series_name_for_controller_runtimes: "rails.controller".freeze,
|
|
94
|
+
series_name_for_view_runtimes: "rails.view".freeze,
|
|
95
|
+
series_name_for_db_runtimes: "rails.db".freeze,
|
|
96
|
+
series_name_for_exceptions: "rails.exceptions".freeze,
|
|
97
|
+
series_name_for_instrumentation: "instrumentation".freeze,
|
|
98
|
+
series_name_for_render_template: "rails.render_template".freeze,
|
|
99
|
+
series_name_for_render_partial: "rails.render_partial".freeze,
|
|
100
|
+
series_name_for_render_collection: "rails.render_collection".freeze,
|
|
101
|
+
series_name_for_sql: nil,
|
|
102
|
+
|
|
103
|
+
series_name_for_http_client_log: "rails.http_client".freeze,
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
tags_middleware: ->(tags) { tags },
|
|
107
|
+
rails_app_name: nil,
|
|
108
|
+
|
|
109
|
+
ignored_exceptions: %w[
|
|
110
|
+
ActiveRecord::RecordNotFound
|
|
111
|
+
ActionController::RoutingError
|
|
112
|
+
].freeze,
|
|
113
|
+
|
|
114
|
+
ignored_exception_messages: [].freeze,
|
|
115
|
+
ignored_reports: [].freeze,
|
|
116
|
+
ignored_environments: %w[test cucumber selenium].freeze,
|
|
117
|
+
ignored_user_agents: %w[GoogleBot].freeze,
|
|
118
|
+
environment_variable_filters: [
|
|
119
|
+
/password/i,
|
|
120
|
+
/key/i,
|
|
121
|
+
/secret/i,
|
|
122
|
+
/ps1/i,
|
|
123
|
+
/rvm_.*_clr/i,
|
|
124
|
+
/color/i,
|
|
125
|
+
].freeze,
|
|
126
|
+
|
|
127
|
+
backtrace_filters: [
|
|
128
|
+
->(line) { line.gsub(%r{^\./}, "") },
|
|
129
|
+
lambda { |line|
|
|
130
|
+
return line if InfluxDB::Rails.configuration.application_root.to_s.empty?
|
|
131
|
+
|
|
132
|
+
line.gsub(/#{InfluxDB::Rails.configuration.application_root}/, "[APP_ROOT]")
|
|
133
|
+
},
|
|
134
|
+
lambda { |line|
|
|
135
|
+
if defined?(Gem) && !Gem.path.nil? && !Gem.path.empty?
|
|
136
|
+
Gem.path.each { |path| line = line.gsub(/#{path}/, "[GEM_ROOT]") }
|
|
137
|
+
end
|
|
138
|
+
line
|
|
139
|
+
},
|
|
140
|
+
].freeze,
|
|
141
|
+
}.freeze
|
|
142
|
+
|
|
143
|
+
# rubocop:disable Metrics/MethodLength
|
|
144
|
+
# rubocop:disable Metrics/AbcSize
|
|
145
|
+
|
|
146
|
+
def initialize
|
|
147
|
+
@influxdb_hosts = DEFAULTS[:influxdb_hosts]
|
|
148
|
+
@influxdb_port = DEFAULTS[:influxdb_port]
|
|
149
|
+
@influxdb_username = DEFAULTS[:influxdb_username]
|
|
150
|
+
@influxdb_password = DEFAULTS[:influxdb_password]
|
|
151
|
+
@influxdb_database = DEFAULTS[:influxdb_database]
|
|
152
|
+
@async = DEFAULTS[:async]
|
|
153
|
+
@use_ssl = DEFAULTS[:use_ssl]
|
|
154
|
+
@retry = DEFAULTS[:retry]
|
|
155
|
+
@open_timeout = DEFAULTS[:open_timeout]
|
|
156
|
+
@read_timeout = DEFAULTS[:read_timeout]
|
|
157
|
+
@max_delay = DEFAULTS[:max_delay]
|
|
158
|
+
@time_precision = DEFAULTS[:time_precision]
|
|
159
|
+
|
|
160
|
+
@series_name_for_controller_runtimes = DEFAULTS[:series_name_for_controller_runtimes]
|
|
161
|
+
@series_name_for_view_runtimes = DEFAULTS[:series_name_for_view_runtimes]
|
|
162
|
+
@series_name_for_db_runtimes = DEFAULTS[:series_name_for_db_runtimes]
|
|
163
|
+
@series_name_for_exceptions = DEFAULTS[:series_name_for_exceptions]
|
|
164
|
+
@series_name_for_instrumentation = DEFAULTS[:series_name_for_instrumentation]
|
|
165
|
+
@series_name_for_render_template = DEFAULTS[:series_name_for_render_template]
|
|
166
|
+
@series_name_for_render_partial = DEFAULTS[:series_name_for_render_partial]
|
|
167
|
+
@series_name_for_render_collection = DEFAULTS[:series_name_for_render_collection]
|
|
168
|
+
@series_name_for_sql = DEFAULTS[:series_name_for_sql]
|
|
169
|
+
@series_name_for_http_client_log = DEFAULTS[:series_name_for_http_client_log]
|
|
170
|
+
|
|
171
|
+
@tags_middleware = DEFAULTS[:tags_middleware]
|
|
172
|
+
@rails_app_name = DEFAULTS[:rails_app_name]
|
|
173
|
+
|
|
174
|
+
@ignored_exceptions = DEFAULTS[:ignored_exceptions].dup
|
|
175
|
+
@ignored_exception_messages = DEFAULTS[:ignored_exception_messages].dup
|
|
176
|
+
@ignored_reports = DEFAULTS[:ignored_reports].dup
|
|
177
|
+
@ignored_environments = DEFAULTS[:ignored_environments].dup
|
|
178
|
+
@ignored_user_agents = DEFAULTS[:ignored_user_agents].dup
|
|
179
|
+
@backtrace_filters = DEFAULTS[:backtrace_filters].dup
|
|
180
|
+
@environment_variable_filters = DEFAULTS[:environment_variable_filters]
|
|
181
|
+
@aggregated_exception_classes = []
|
|
182
|
+
|
|
183
|
+
@debug = false
|
|
184
|
+
@rescue_global_exceptions = false
|
|
185
|
+
@instrumentation_enabled = true
|
|
186
|
+
|
|
187
|
+
# Http logs
|
|
188
|
+
# @enabled = true
|
|
189
|
+
# @compact_log = false
|
|
190
|
+
# @json_log = false
|
|
191
|
+
# @logger = Logger.new($stdout)
|
|
192
|
+
# @logger_method = :log
|
|
193
|
+
# @severity = Logger::Severity::DEBUG
|
|
194
|
+
# @prefix = LOG_PREFIX
|
|
195
|
+
# @log_connect = true
|
|
196
|
+
# @log_request = true
|
|
197
|
+
# @log_headers = false
|
|
198
|
+
# @log_data = true
|
|
199
|
+
# @log_status = true
|
|
200
|
+
# @log_response = true
|
|
201
|
+
# @log_benchmark = true
|
|
202
|
+
# @url_whitelist_pattern = nil
|
|
203
|
+
# @url_blacklist_pattern = nil
|
|
204
|
+
# @color = false
|
|
205
|
+
# @prefix_data_lines = false
|
|
206
|
+
# @prefix_response_lines = false
|
|
207
|
+
# @prefix_line_numbers = false
|
|
208
|
+
# @filter_parameters = []
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# rubocop:enable Metrics/MethodLength
|
|
212
|
+
# rubocop:enable Metrics/AbcSize
|
|
213
|
+
|
|
214
|
+
def debug?
|
|
215
|
+
!!@debug # rubocop:disable Style/DoubleNegation
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def instrumentation_enabled?
|
|
219
|
+
!!@instrumentation_enabled # rubocop:disable Style/DoubleNegation
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def ignore_user_agent?(incoming_user_agent)
|
|
223
|
+
return false if ignored_user_agents.nil?
|
|
224
|
+
|
|
225
|
+
ignored_user_agents.any? { |agent| incoming_user_agent =~ /#{agent}/ }
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def ignore_current_environment?
|
|
229
|
+
ignored_environments.include?(environment)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def ignore_exception?(ex)
|
|
233
|
+
!ignored_exception_messages.find { |msg| /.*#{msg}.*/ =~ ex.message }.nil? ||
|
|
234
|
+
ignored_exceptions.include?(ex.class.to_s)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def define_custom_exception_data(&block)
|
|
238
|
+
@custom_exception_data_handler = block
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def add_custom_exception_data(exception_presenter)
|
|
242
|
+
@custom_exception_data_handler&.call(exception_presenter)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def load_rails_defaults
|
|
246
|
+
@logger ||= ::Rails.logger
|
|
247
|
+
@environment ||= ::Rails.env
|
|
248
|
+
@application_root ||= ::Rails.root
|
|
249
|
+
@application_name ||= ::Rails.application.class.parent_name
|
|
250
|
+
@framework = "Rails"
|
|
251
|
+
@framework_version = ::Rails.version
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
private
|
|
255
|
+
|
|
256
|
+
def initialize_http_connection
|
|
257
|
+
Net::HTTP.new(@app_host, "80")
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# rubocop:enable Metrics/ClassLength
|
|
262
|
+
end
|
|
263
|
+
end
|