oneapm_rpm 1.1.1 → 1.1.2
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 +4 -4
- data/lib/one_apm/agent/database/active_record_helper.rb +16 -18
- data/lib/one_apm/agent/event/event_loop.rb +1 -48
- data/lib/one_apm/agent/event/timer.rb +56 -0
- data/lib/one_apm/agent/javascript_instrumentor.rb +1 -6
- data/lib/one_apm/agent/pipe/pipe_service.rb +1 -1
- data/lib/one_apm/agent.rb +0 -8
- data/lib/one_apm/configuration/default_source.rb +8 -9
- data/lib/one_apm/configuration/environment_source.rb +11 -12
- data/lib/one_apm/frameworks/ruby.rb +1 -1
- data/lib/one_apm/inst/background_job/delayed_job.rb +1 -2
- data/lib/one_apm/inst/background_job/event_machine_standalone.rb +24 -0
- data/lib/one_apm/inst/orm/sequel.rb +1 -3
- data/lib/one_apm/inst/support/queue_time.rb +0 -3
- data/lib/one_apm/support/local_environment.rb +8 -1
- data/lib/one_apm/support/method_tracer/helpers.rb +38 -39
- data/lib/one_apm/support/method_tracer.rb +26 -18
- data/lib/one_apm/support/rules_engine.rb +1 -0
- data/lib/one_apm/support/supported_versions.rb +1 -3
- data/lib/one_apm/support/{method_tracer/traced_method_stack.rb → traced_method_stack.rb} +0 -0
- data/lib/one_apm/transaction/transaction_state.rb +1 -1
- data/lib/one_apm/transaction.rb +0 -38
- data/lib/one_apm/version.rb +1 -1
- data/lib/sequel/plugins/oneapm_instrumentation.rb +7 -7
- data/oneapm.yml +8 -105
- metadata +5 -4
- data/lib/one_apm/inst/orm/data_mapper.rb +0 -180
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4759f9e2a49b073a72ef050065da0b3169782a50
|
4
|
+
data.tar.gz: e06c21dc7767a5c5ee0b2371eb367cb3286b1231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523b7b03147cb529a70bf76da7bdd1761621460169d4eeb74d972db31134eae5ab7d0430d693cd7e51d4699d66b71615de5b9a42b81ca45c8d7d4a23a3d2ddc1
|
7
|
+
data.tar.gz: 60387048069ae8167d4f237070131090558fb44104b47af2e5e86597f44eb2dcbef8223da1516fc37c13684e2da1e8a827a86a26765c2ee4ed8c0b9656c39d44
|
@@ -12,20 +12,18 @@ module OneApm
|
|
12
12
|
model = parts.first
|
13
13
|
operation = parts.last.downcase
|
14
14
|
case operation
|
15
|
-
when 'load', 'count', 'exists'
|
16
|
-
op_name = '
|
17
|
-
when '
|
18
|
-
op_name =
|
19
|
-
when '
|
20
|
-
op_name =
|
21
|
-
when 'update'
|
22
|
-
op_name = '
|
15
|
+
when 'find', 'load', 'count', 'exists'
|
16
|
+
op_name = 'select'
|
17
|
+
when 'destroy'
|
18
|
+
op_name = 'delete'
|
19
|
+
when 'create'
|
20
|
+
op_name = 'insert'
|
21
|
+
when 'update', 'save'
|
22
|
+
op_name = 'update'
|
23
23
|
else
|
24
|
-
|
25
|
-
op_name = operation
|
26
|
-
end
|
24
|
+
op_name = nil
|
27
25
|
end
|
28
|
-
"
|
26
|
+
"Database/#{model}/#{op_name}" if op_name
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -44,11 +42,11 @@ module OneApm
|
|
44
42
|
metric
|
45
43
|
end
|
46
44
|
|
47
|
-
# Given a metric name such as "
|
45
|
+
# Given a metric name such as "Database/model/action" this
|
48
46
|
# returns an array of rollup metrics:
|
49
|
-
# [ "Database/all", "
|
50
|
-
# If the metric name is in the form of "
|
51
|
-
# this returns merely: [ "Database/all", "
|
47
|
+
# [ "Database/all", "Database/all", "Database/action" ]
|
48
|
+
# If the metric name is in the form of "Database/action"
|
49
|
+
# this returns merely: [ "Database/all", "Database/all" ]
|
52
50
|
def rollup_metrics_for(metric)
|
53
51
|
metrics = ["Database/all"]
|
54
52
|
|
@@ -56,11 +54,11 @@ module OneApm
|
|
56
54
|
# database metrics. This is to prevent metrics from background tasks
|
57
55
|
# from polluting the metrics used to drive overview graphs.
|
58
56
|
if OneApm::Transaction.recording_web_transaction?
|
59
|
-
metrics << "
|
57
|
+
metrics << "Database/allWeb"
|
60
58
|
else
|
61
59
|
metrics << "Database/allOther"
|
62
60
|
end
|
63
|
-
metrics << "
|
61
|
+
metrics << "Database/#{$1}" if metric =~ /Database\/[\w|\:]+\/(\w+)/
|
64
62
|
|
65
63
|
metrics
|
66
64
|
end
|
@@ -1,58 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'thread'
|
4
|
+
require 'one_apm/agent/event/timer'
|
4
5
|
|
5
6
|
module OneApm
|
6
7
|
module Agent
|
7
8
|
class EventLoop
|
8
|
-
class Timer
|
9
|
-
|
10
|
-
attr_reader :next_fire_time, :event, :interval, :last_fired_at
|
11
|
-
|
12
|
-
def initialize(interval, event, repeat=false)
|
13
|
-
@interval = interval
|
14
|
-
@event = event
|
15
|
-
@repeat = repeat
|
16
|
-
@started_at = Time.now
|
17
|
-
@last_fired_at = nil
|
18
|
-
reschedule
|
19
|
-
end
|
20
|
-
|
21
|
-
def reschedule
|
22
|
-
@next_fire_time = calculate_next_fire_time
|
23
|
-
end
|
24
|
-
|
25
|
-
def advance(amount)
|
26
|
-
@next_fire_time -= amount
|
27
|
-
end
|
28
|
-
|
29
|
-
def last_interval_start
|
30
|
-
@last_fired_at || @started_at
|
31
|
-
end
|
32
|
-
|
33
|
-
def calculate_next_fire_time
|
34
|
-
now = Time.now
|
35
|
-
return now if @interval == 0
|
36
|
-
fire_time = @last_fired_at || now
|
37
|
-
while fire_time <= now
|
38
|
-
fire_time += @interval
|
39
|
-
end
|
40
|
-
fire_time
|
41
|
-
end
|
42
|
-
|
43
|
-
def set_fired_time
|
44
|
-
@last_fired_at = Time.now
|
45
|
-
end
|
46
|
-
|
47
|
-
def due?(now=Time.now)
|
48
|
-
now >= @next_fire_time
|
49
|
-
end
|
50
|
-
|
51
|
-
def finished?
|
52
|
-
!@repeat && @last_fired_at
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
9
|
|
57
10
|
def initialize
|
58
11
|
@self_pipe_rd, @self_pipe_wr = IO.pipe
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
module Agent
|
5
|
+
class EventLoop
|
6
|
+
class Timer
|
7
|
+
|
8
|
+
attr_reader :next_fire_time, :event, :interval, :last_fired_at
|
9
|
+
|
10
|
+
def initialize(interval, event, repeat=false)
|
11
|
+
@interval = interval
|
12
|
+
@event = event
|
13
|
+
@repeat = repeat
|
14
|
+
@started_at = Time.now
|
15
|
+
@last_fired_at = nil
|
16
|
+
reschedule
|
17
|
+
end
|
18
|
+
|
19
|
+
def reschedule
|
20
|
+
@next_fire_time = calculate_next_fire_time
|
21
|
+
end
|
22
|
+
|
23
|
+
def advance(amount)
|
24
|
+
@next_fire_time -= amount
|
25
|
+
end
|
26
|
+
|
27
|
+
def last_interval_start
|
28
|
+
@last_fired_at || @started_at
|
29
|
+
end
|
30
|
+
|
31
|
+
def calculate_next_fire_time
|
32
|
+
now = Time.now
|
33
|
+
return now if @interval == 0
|
34
|
+
fire_time = @last_fired_at || now
|
35
|
+
while fire_time <= now
|
36
|
+
fire_time += @interval
|
37
|
+
end
|
38
|
+
fire_time
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_fired_time
|
42
|
+
@last_fired_at = Time.now
|
43
|
+
end
|
44
|
+
|
45
|
+
def due?(now=Time.now)
|
46
|
+
now >= @next_fire_time
|
47
|
+
end
|
48
|
+
|
49
|
+
def finished?
|
50
|
+
!@repeat && @last_fired_at
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -164,13 +164,8 @@ module OneApm
|
|
164
164
|
data[USER_ATTRIBUTES_KEY] = obfuscator.obfuscate(json)
|
165
165
|
end
|
166
166
|
|
167
|
-
# Still support deprecated capture_attributes.page_view_events for
|
168
|
-
# clients that use it. Could potentially be removed if we don't have
|
169
|
-
# anymore users with it set according to zeitgeist.
|
170
167
|
def include_custom_parameters?(txn)
|
171
|
-
has_custom_parameters?(txn) &&
|
172
|
-
(OneApm::Agent.config[:'browser_monitoring.capture_attributes'] ||
|
173
|
-
OneApm::Agent.config[:'capture_attributes.page_view_events'])
|
168
|
+
has_custom_parameters?(txn) && OneApm::Agent.config[:'browser_monitoring.capture_attributes']
|
174
169
|
end
|
175
170
|
|
176
171
|
def has_custom_parameters?(txn)
|
@@ -13,7 +13,7 @@ module OneApm
|
|
13
13
|
if @pipe && @pipe.parent_pid != $$
|
14
14
|
@pipe.after_fork_in_child
|
15
15
|
else
|
16
|
-
OneApm::Agent.logger.error("No communication channel to parent process
|
16
|
+
OneApm::Agent.logger.error("No communication channel to parent process.")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/one_apm/agent.rb
CHANGED
@@ -222,14 +222,6 @@ module OneApm
|
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
-
def with_database_metric_name(model, method, &block) #THREAD_LOCAL_ACCESS
|
226
|
-
if txn = Transaction.tl_current
|
227
|
-
txn.with_database_metric_name(model, method, &block)
|
228
|
-
else
|
229
|
-
yield
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
225
|
def subscribe(event_type, &handler)
|
234
226
|
instance.events.subscribe( event_type, &handler )
|
235
227
|
end
|
@@ -235,7 +235,7 @@ module OneApm
|
|
235
235
|
:default => value_of(:enabled),
|
236
236
|
:public => true,
|
237
237
|
:type => Boolean,
|
238
|
-
:description => 'Enable or disable the transmission of data to the OneApm collector
|
238
|
+
:description => 'Enable or disable the transmission of data to the OneApm collector.'
|
239
239
|
},
|
240
240
|
:log_level => {
|
241
241
|
:default => 'info',
|
@@ -296,7 +296,7 @@ module OneApm
|
|
296
296
|
:default => DefaultSource.config_path,
|
297
297
|
:public => true,
|
298
298
|
:type => String,
|
299
|
-
:description => 'Path to <b>oneapm.yml</b>. When omitted the agent will check (in order) <b>config/oneapm.yml</b
|
299
|
+
:description => 'Path to <b>oneapm.yml</b>. When omitted the agent will check (in order) <b>config/oneapm.yml</b>.'
|
300
300
|
},
|
301
301
|
:config_search_paths => {
|
302
302
|
:default => DefaultSource.config_search_paths,
|
@@ -761,13 +761,6 @@ module OneApm
|
|
761
761
|
:type => Boolean,
|
762
762
|
:description => 'Enable or disable HTTPS instrumentation by JavaScript agent on HTTP pages.'
|
763
763
|
},
|
764
|
-
:'capture_attributes.page_view_events' => {
|
765
|
-
:default => false,
|
766
|
-
:public => false,
|
767
|
-
:type => Boolean,
|
768
|
-
:deprecated => true,
|
769
|
-
:description => 'Correct setting is browser_monitoring.capture_attributes.'
|
770
|
-
},
|
771
764
|
:js_agent_loader => {
|
772
765
|
:default => '',
|
773
766
|
:public => false,
|
@@ -1020,6 +1013,12 @@ module OneApm
|
|
1020
1013
|
:public => true,
|
1021
1014
|
:type => Boolean,
|
1022
1015
|
:description => 'Disables installation of Grape instrumentation.'
|
1016
|
+
},
|
1017
|
+
:event_machine_standalone => {
|
1018
|
+
:default => false,
|
1019
|
+
:public => true,
|
1020
|
+
:type => Boolean,
|
1021
|
+
:description => 'enable standalone mode of event_machine'
|
1023
1022
|
}
|
1024
1023
|
}.freeze
|
1025
1024
|
end
|
@@ -4,10 +4,10 @@ module OneApm
|
|
4
4
|
module Configuration
|
5
5
|
class EnvironmentSource < OneApm::Support::DottedHash
|
6
6
|
|
7
|
-
SUPPORTED_PREFIXES = /^
|
7
|
+
SUPPORTED_PREFIXES = /^oneapm_/i
|
8
8
|
SPECIAL_CASE_KEYS = [
|
9
|
-
'
|
10
|
-
'
|
9
|
+
'ONEAPM_ENV', # read by OneApm::Probe::Frameworks::Ruby
|
10
|
+
'ONEAPM_LOG' # read by set_log_file
|
11
11
|
]
|
12
12
|
|
13
13
|
attr_accessor :alias_map, :type_map
|
@@ -46,24 +46,24 @@ module OneApm
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def set_log_file
|
49
|
-
if ENV['
|
50
|
-
if ENV['
|
49
|
+
if ENV['ONEAPM_LOG']
|
50
|
+
if ENV['ONEAPM_LOG'].upcase == 'STDOUT'
|
51
51
|
self[:log_file_path] = self[:log_file_name] = 'STDOUT'
|
52
52
|
else
|
53
|
-
self[:log_file_path] = File.dirname(ENV['
|
54
|
-
self[:log_file_name] = File.basename(ENV['
|
53
|
+
self[:log_file_path] = File.dirname(ENV['ONEAPM_LOG'])
|
54
|
+
self[:log_file_name] = File.basename(ENV['ONEAPM_LOG'])
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def set_config_file
|
60
|
-
self[:config_path] = ENV['
|
60
|
+
self[:config_path] = ENV['ONEAPM_CONFIG'] if ENV['ONEAPM_CONFIG']
|
61
61
|
end
|
62
62
|
|
63
63
|
def set_values_from_one_apm_environment_variables
|
64
|
-
|
64
|
+
env_var_keys = collect_one_apm_environment_variable_keys
|
65
65
|
|
66
|
-
|
66
|
+
env_var_keys.each do |key|
|
67
67
|
next if SPECIAL_CASE_KEYS.include?(key.upcase)
|
68
68
|
set_value_from_environment_variable(key)
|
69
69
|
end
|
@@ -93,8 +93,7 @@ module OneApm
|
|
93
93
|
self[config_key] = true
|
94
94
|
end
|
95
95
|
else
|
96
|
-
|
97
|
-
::OneApm::Agent.logger.info("Run `rake oneapm:config:docs` or visit https://oneapm.com/docs/ruby/ruby-agent-configuration to see a list of available configuration settings.")
|
96
|
+
OneApm::Agent.logger.info("#{environment_key} does not have a corresponding configuration setting (#{config_key} does not exist).")
|
98
97
|
self[config_key] = value
|
99
98
|
end
|
100
99
|
end
|
@@ -12,7 +12,7 @@ LibraryDetection.defer do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
executes do
|
15
|
-
::OneApm::Agent.logger.info 'Installing DelayedJob instrumentation
|
15
|
+
::OneApm::Agent.logger.info 'Installing DelayedJob instrumentation'
|
16
16
|
end
|
17
17
|
|
18
18
|
executes do
|
@@ -26,7 +26,6 @@ LibraryDetection.defer do
|
|
26
26
|
OneApm::DelayedJobInjection.worker_name = worker_name
|
27
27
|
|
28
28
|
if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job)
|
29
|
-
::OneApm::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
|
30
29
|
install_oneapm_job_tracer
|
31
30
|
OneApm::Probe.instance.init_plugin :dispatcher => :delayed_job
|
32
31
|
else
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
LibraryDetection.defer do
|
4
|
+
named :event_machine_standalone
|
5
|
+
|
6
|
+
depends_on do
|
7
|
+
OneApm::Agent.config[:event_machine_standalone] && defined?(::EventMachine)
|
8
|
+
end
|
9
|
+
|
10
|
+
executes do
|
11
|
+
OneApm::Agent.logger.info 'Installing EventMachine Standalone Mode instrumentation'
|
12
|
+
|
13
|
+
module EventMachine
|
14
|
+
|
15
|
+
PeriodicTimer.class_eval do
|
16
|
+
include OneApm::Agent::Instrumentation::TransactionBase
|
17
|
+
|
18
|
+
add_transaction_tracer "fire", :category => 'OtherTransaction/Background'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -25,9 +25,7 @@ LibraryDetection.defer do
|
|
25
25
|
if Sequel::Database.respond_to?(:extension)
|
26
26
|
Sequel::Database.extension :oneapm_instrumentation
|
27
27
|
else
|
28
|
-
OneApm::Agent.logger.
|
29
|
-
OneApm::Agent.logger.info "Please see additional documentation: " +
|
30
|
-
"https://oneapm.com/docs/ruby/sequel-instrumentation"
|
28
|
+
OneApm::Agent.logger.warn("Detected Sequel version #{Sequel::VERSION}.")
|
31
29
|
end
|
32
30
|
|
33
31
|
Sequel.synchronize{Sequel::DATABASES.dup}.each do |db|
|
@@ -3,9 +3,6 @@
|
|
3
3
|
module OneApm
|
4
4
|
module Agent
|
5
5
|
module Instrumentation
|
6
|
-
# https://oneapm.com/docs/features/tracking-front-end-time
|
7
|
-
# Record queue time metrics based on any of three headers
|
8
|
-
# which can be set on the request.
|
9
6
|
module QueueTime
|
10
7
|
unless defined?(REQUEST_START_HEADER)
|
11
8
|
REQUEST_START_HEADER = 'HTTP_X_REQUEST_START'.freeze
|
@@ -17,7 +17,7 @@ module OneApm
|
|
17
17
|
# into the same log, it's useful to be able to identify what kind of
|
18
18
|
# process a given PID mapped to.
|
19
19
|
#
|
20
|
-
# Overriding the dispatcher is possible via the
|
20
|
+
# Overriding the dispatcher is possible via the ONEAPM_DISPATCHER
|
21
21
|
# environment variable, but this should not generally be necessary unless
|
22
22
|
# you're on a dispatcher that falls into category 1 above, and our detection
|
23
23
|
# logic isn't working correctly.
|
@@ -72,6 +72,7 @@ module OneApm
|
|
72
72
|
unicorn
|
73
73
|
goliath
|
74
74
|
webrick
|
75
|
+
event_machine
|
75
76
|
]
|
76
77
|
while dispatchers.any? && @discovered_dispatcher.nil?
|
77
78
|
send 'check_for_'+(dispatchers.shift)
|
@@ -180,6 +181,12 @@ module OneApm
|
|
180
181
|
end
|
181
182
|
end
|
182
183
|
|
184
|
+
def check_for_event_machine
|
185
|
+
if defined?(::EventMachine)
|
186
|
+
@discovered_dispatcher = :event_machine
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
183
190
|
public
|
184
191
|
# outputs a human-readable description
|
185
192
|
def to_s
|
@@ -8,8 +8,17 @@ module OneApm
|
|
8
8
|
|
9
9
|
extend self
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def record_metrics(state, first_name, other_names, duration, exclusive, options)
|
12
|
+
record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
|
13
|
+
stats_engine = OneApm::Agent.instance.stats_engine
|
14
|
+
if record_scoped_metric
|
15
|
+
stats_engine.record_scoped_and_unscoped_metrics(state, first_name, other_names, duration, exclusive)
|
16
|
+
else
|
17
|
+
metrics = [first_name].concat(other_names)
|
18
|
+
stats_engine.record_unscoped_metrics(state, metrics, duration, exclusive)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
13
22
|
def log_errors(code_area)
|
14
23
|
yield
|
15
24
|
rescue => e
|
@@ -23,45 +32,35 @@ module OneApm
|
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
26
|
-
def
|
27
|
-
record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
|
28
|
-
stat_engine = OneApm::Agent.instance.stats_engine
|
29
|
-
if record_scoped_metric
|
30
|
-
stat_engine.record_scoped_and_unscoped_metrics(state, first_name, other_names, duration, exclusive)
|
31
|
-
else
|
32
|
-
metrics = [first_name].concat(other_names)
|
33
|
-
stat_engine.record_unscoped_metrics(state, metrics, duration, exclusive)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def trace_execution_scoped_footer(state, t0, first_name, metric_names, expected_frame, options, t1=Time.now.to_f)
|
35
|
+
def trace_execution_scoped_footer(state, t0, first_name, metric_names, expected_frame, options, t1 = Time.now.to_f)
|
38
36
|
log_errors(:trace_method_execution_footer) do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
record_metrics(state, first_name, metric_names, duration, exclusive, options)
|
59
|
-
else
|
60
|
-
::OneApm::Agent.logger.log_once(:warn, "too_huge_metric:#{first_name}",
|
61
|
-
"Ignoring metric #{first_name} with unacceptably large duration: #{duration} s")
|
62
|
-
end
|
63
|
-
end
|
37
|
+
return unless expected_frame
|
38
|
+
|
39
|
+
stack = state.traced_method_stack
|
40
|
+
create_metrics = options.has_key?(:metric) ? options[:metric] : true
|
41
|
+
frame = stack.pop_frame(state, expected_frame, first_name, t1, create_metrics)
|
42
|
+
return unless create_metrics
|
43
|
+
|
44
|
+
duration = t1 - t0
|
45
|
+
exclusive = duration - frame.children_time
|
46
|
+
|
47
|
+
if duration >= MAX_ALLOWED_METRIC_DURATION
|
48
|
+
::OneApm::Agent.logger.log_once(:warn, "too_huge_metric:#{first_name}",
|
49
|
+
"Ignoring metric #{first_name} with unacceptably large duration: #{duration} s")
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
if duration < 0
|
54
|
+
::OneApm::Agent.logger.log_once(:warn, "metric_duration_negative:#{first_name}",
|
55
|
+
"Metric #{first_name} has negative duration: #{duration} s")
|
64
56
|
end
|
57
|
+
|
58
|
+
if exclusive < 0
|
59
|
+
::OneApm::Agent.logger.log_once(:warn, "metric_exclusive_negative:#{first_name}",
|
60
|
+
"Metric #{first_name} has negative exclusive time: duration = #{duration} s, child_time = #{frame.children_time}")
|
61
|
+
end
|
62
|
+
|
63
|
+
record_metrics(state, first_name, metric_names, duration, exclusive, options)
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
@@ -241,25 +241,33 @@ module OneApm
|
|
241
241
|
#
|
242
242
|
# If not provided, the metric name will be <tt>Custom/ClassName/method_name</tt>.
|
243
243
|
#
|
244
|
-
# @param [Symbol] method_name
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
# name
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
244
|
+
# @param [Symbol] method_name
|
245
|
+
# the name of the method to trace
|
246
|
+
#
|
247
|
+
# @param [String] metric_name_code
|
248
|
+
# the metric name to record calls to the traced method under. This may
|
249
|
+
# be either a static string, or Ruby code to be evaluated at call-time
|
250
|
+
# in order to determine the metric name dynamically.
|
251
|
+
#
|
252
|
+
# @param [Hash] options
|
253
|
+
# additional options controlling how the method is traced.
|
254
|
+
#
|
255
|
+
# @option options [Boolean] :push_scope (true)
|
256
|
+
# If false, the traced method will not appear in transaction traces or
|
257
|
+
# breakdown charts, and it will only be visible in custom dashboards.
|
258
|
+
#
|
259
|
+
# @option options [Boolean] :metric (true)
|
260
|
+
# If false, the traced method will only appear in transaction traces,
|
261
|
+
# but no metrics will be recorded for it.
|
262
|
+
#
|
263
|
+
# @option options [String] :code_header ('')
|
264
|
+
# Ruby code to be inserted and run before the tracer begins timing.
|
265
|
+
#
|
266
|
+
# @option options [String] :code_footer ('')
|
267
|
+
# Ruby code to be inserted and run after the tracer stops timing.
|
261
268
|
#
|
262
269
|
# @example
|
270
|
+
#
|
263
271
|
# add_method_tracer :foo
|
264
272
|
#
|
265
273
|
# # With a custom metric name
|
@@ -274,7 +282,7 @@ module OneApm
|
|
274
282
|
#
|
275
283
|
# @api public
|
276
284
|
#
|
277
|
-
def add_method_tracer(method_name, metric_name_code=nil, options = {})
|
285
|
+
def add_method_tracer(method_name, metric_name_code = nil, options = {})
|
278
286
|
return unless oneapm_method_exists?(method_name)
|
279
287
|
metric_name_code ||= default_metric_name_code(method_name)
|
280
288
|
return if traced_method_exists?(method_name, metric_name_code)
|
@@ -209,9 +209,7 @@ module OneApm
|
|
209
209
|
{
|
210
210
|
:type => :http,
|
211
211
|
:name => "Net::HTTP",
|
212
|
-
:notes => [
|
213
|
-
"Supported for all agent-supported versions of Ruby.",
|
214
|
-
"For more information on supported HTTP clients see http://docs.oneapm.com/docs/ruby/ruby-http-clients."]
|
212
|
+
:notes => [ "Supported for all agent-supported versions of Ruby." ]
|
215
213
|
},
|
216
214
|
|
217
215
|
# Other
|
File without changes
|
data/lib/one_apm/transaction.rb
CHANGED
@@ -222,22 +222,6 @@ module OneApm
|
|
222
222
|
@instrumentation_state ||= {}
|
223
223
|
end
|
224
224
|
|
225
|
-
def with_database_metric_name(model, method)
|
226
|
-
previous = self.instrumentation_state[:datastore_override]
|
227
|
-
model_name = case model
|
228
|
-
when Class
|
229
|
-
model.name
|
230
|
-
when String
|
231
|
-
model
|
232
|
-
else
|
233
|
-
model.to_s
|
234
|
-
end
|
235
|
-
self.instrumentation_state[:datastore_override] = [method, model_name]
|
236
|
-
yield
|
237
|
-
ensure
|
238
|
-
self.instrumentation_state[:datastore_override] = previous
|
239
|
-
end
|
240
|
-
|
241
225
|
def noticed_error_ids
|
242
226
|
@noticed_error_ids ||= []
|
243
227
|
end
|
@@ -310,27 +294,5 @@ module OneApm
|
|
310
294
|
end
|
311
295
|
end
|
312
296
|
|
313
|
-
# Yield to a block that is run with a database metric name context. This means
|
314
|
-
# the Database instrumentation will use this for the metric name if it does not
|
315
|
-
# otherwise know about a model. This is re-entrant.
|
316
|
-
#
|
317
|
-
# * <tt>model</tt> is the DB model class
|
318
|
-
# * <tt>method</tt> is the name of the finder method or other method to identify the operation with.
|
319
|
-
#
|
320
|
-
def with_database_metric_name(model, method)
|
321
|
-
previous = @database_metric_name
|
322
|
-
model_name = case model
|
323
|
-
when Class
|
324
|
-
model.name
|
325
|
-
when String
|
326
|
-
model
|
327
|
-
else
|
328
|
-
model.to_s
|
329
|
-
end
|
330
|
-
@database_metric_name = "ActiveRecord/#{model_name}/#{method}"
|
331
|
-
yield
|
332
|
-
ensure
|
333
|
-
@database_metric_name = previous
|
334
|
-
end
|
335
297
|
end
|
336
298
|
end
|
data/lib/one_apm/version.rb
CHANGED
@@ -12,7 +12,7 @@ module Sequel
|
|
12
12
|
def make_tracer_method( opname, options )
|
13
13
|
body = Proc.new do |*args, &block|
|
14
14
|
classname = self.is_a?( Class ) ? self.name : self.class.name
|
15
|
-
metric = "
|
15
|
+
metric = "Database/%s/%s" % [ classname, opname ]
|
16
16
|
trace_execution_scoped( metric, options ) do
|
17
17
|
super( *args, &block )
|
18
18
|
end
|
@@ -41,13 +41,13 @@ module Sequel
|
|
41
41
|
extend Sequel::Plugins::OneapmInstrumentation::MethodTracer
|
42
42
|
|
43
43
|
add_method_tracer :delete
|
44
|
-
add_method_tracer :destroy
|
44
|
+
add_method_tracer :destroy, :delete
|
45
45
|
add_method_tracer :update
|
46
|
-
add_method_tracer :update_all
|
47
|
-
add_method_tracer :update_except
|
48
|
-
add_method_tracer :update_fields
|
49
|
-
add_method_tracer :update_only
|
50
|
-
add_method_tracer :save
|
46
|
+
add_method_tracer :update_all, :update
|
47
|
+
add_method_tracer :update_except, :update
|
48
|
+
add_method_tracer :update_fields, :update
|
49
|
+
add_method_tracer :update_only, :update
|
50
|
+
add_method_tracer :save, :insert
|
51
51
|
|
52
52
|
end
|
53
53
|
|
data/oneapm.yml
CHANGED
@@ -2,116 +2,24 @@
|
|
2
2
|
# OneApm RubyAgent Configuration
|
3
3
|
#
|
4
4
|
|
5
|
-
# Here are the settings that are common to all environments
|
6
5
|
common: &default_settings
|
7
|
-
# ============================== LICENSE KEY ===============================
|
8
6
|
|
9
|
-
#
|
10
|
-
# Get your license key from oneapm.com
|
11
|
-
#
|
12
7
|
license_key: 'please-paste-your-license-key-here'
|
13
8
|
|
14
|
-
# Agent Enabled (Ruby/Rails Only)
|
15
|
-
# Valid values are true, false and auto.
|
16
|
-
#
|
17
|
-
# agent_enabled: auto
|
18
|
-
|
19
9
|
# This app_name will be the application name in oneapm.com in your account.
|
20
10
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# app with the old name.
|
11
|
+
# If you change this name, a new application will appear in your account with
|
12
|
+
# the new name. and data will stop reporting to the app with the old name.
|
24
13
|
#
|
25
14
|
app_name: My Application
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# environment below. (formerly called 'enabled')
|
31
|
-
monitor_mode: true
|
32
|
-
|
33
|
-
# Specify its log level here.
|
34
|
-
log_level: info
|
35
|
-
|
36
|
-
# log_file_path: 'log'
|
37
|
-
# log_file_name: 'oneapm_agent.log'
|
38
|
-
|
39
|
-
# The oneapm agent communicates with the service via https by default.
|
40
|
-
# ssl: true
|
41
|
-
|
42
|
-
# ======================== Browser Monitoring =============================
|
43
|
-
browser_monitoring:
|
44
|
-
# By default the agent automatically injects the monitoring JavaScript
|
45
|
-
# into web pages. Set this attribute to false to turn off this behavior.
|
46
|
-
auto_instrument: true
|
47
|
-
|
48
|
-
# Proxy settings for connecting to the OneApm server.
|
49
|
-
#
|
50
|
-
# proxy_host: hostname
|
51
|
-
# proxy_port: 8080
|
52
|
-
# proxy_user:
|
53
|
-
# proxy_pass:
|
54
|
-
|
55
|
-
# Tells transaction tracer and error collector (when enabled)
|
56
|
-
# whether or not to capture HTTP params. When true, frameworks can
|
57
|
-
# exclude HTTP parameters from being captured.
|
58
|
-
# Rails: the RoR filter_parameter_logging excludes parameters
|
59
|
-
capture_params: false
|
60
|
-
|
61
|
-
# Transaction tracer captures deep information about slow
|
62
|
-
# transactions and sends this to the OneApm service once a
|
63
|
-
# minute. Included in the transaction is the exact call sequence of
|
64
|
-
# the transactions including any SQL statements issued.
|
65
|
-
transaction_tracer:
|
66
|
-
|
67
|
-
# Transaction tracer is enabled by default.
|
68
|
-
enabled: true
|
69
|
-
|
70
|
-
# Threshold in seconds for when to collect a transaction
|
71
|
-
# trace. When the response time of a controller action exceeds
|
72
|
-
# this threshold, a transaction trace will be recorded and sent to
|
73
|
-
# OneApm. Valid values are any float value, or (default) "apdex_f",
|
74
|
-
# which will use the threshold for an dissatisfying Apdex
|
75
|
-
# controller action - four times the Apdex T value.
|
76
|
-
transaction_threshold: apdex_f
|
77
|
-
|
78
|
-
# When transaction tracer is on, SQL statements can optionally be
|
79
|
-
# recorded. The recorder has three modes, "off" which sends no
|
80
|
-
# SQL, "raw" which sends the SQL statement in its original form,
|
81
|
-
# and "obfuscated", which strips out numeric and string literals.
|
82
|
-
record_sql: obfuscated
|
83
|
-
|
84
|
-
# Threshold in seconds for when to collect stack trace for a SQL
|
85
|
-
# call. In other words, when SQL statements exceed this threshold,
|
86
|
-
# then capture and send to OneApm the current stack trace. This is
|
87
|
-
# helpful for pinpointing where long SQL calls originate from.
|
88
|
-
stack_trace_threshold: 0.500
|
89
|
-
|
90
|
-
# Determines whether the agent will capture query plans for slow
|
91
|
-
# SQL queries. Only supported in mysql and postgres. Should be
|
92
|
-
# set to false when using other adapters.
|
93
|
-
# explain_enabled: true
|
94
|
-
|
95
|
-
# Threshold for query execution time below which query plans will
|
96
|
-
# not be captured. Relevant only when `explain_enabled` is true.
|
97
|
-
# explain_threshold: 0.5
|
98
|
-
|
99
|
-
# Error collector captures information about uncaught exceptions and
|
100
|
-
# sends them to OneApm for viewing
|
101
|
-
error_collector:
|
102
|
-
|
103
|
-
# Error collector is enabled by default.
|
104
|
-
enabled: true
|
105
|
-
|
106
|
-
# Ignore the following errors, add your own.
|
107
|
-
ignore_errors: "ActionController::RoutingError,Sinatra::NotFound"
|
108
|
-
|
109
|
-
# ===================== Application Environments ========================
|
110
|
-
# Environment-specific settings are in this section.
|
111
|
-
# For Rails applications, RAILS_ENV is used to determine the environment.
|
16
|
+
#
|
17
|
+
# Environment-specific settings
|
18
|
+
#
|
112
19
|
|
113
|
-
|
114
|
-
|
20
|
+
production:
|
21
|
+
<<: *default_settings
|
22
|
+
monitor_mode: true
|
115
23
|
|
116
24
|
development:
|
117
25
|
<<: *default_settings
|
@@ -123,11 +31,6 @@ test:
|
|
123
31
|
<<: *default_settings
|
124
32
|
monitor_mode: false
|
125
33
|
|
126
|
-
# Turn on the agent in production for 24x7 monitoring.
|
127
|
-
production:
|
128
|
-
<<: *default_settings
|
129
|
-
monitor_mode: true
|
130
|
-
|
131
34
|
# Staging environment which behaves identically to production.
|
132
35
|
staging:
|
133
36
|
<<: *default_settings
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneapm_rpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oneapm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- lib/one_apm/agent/datastores/mongo/statement_formatter.rb
|
248
248
|
- lib/one_apm/agent/event/event_listener.rb
|
249
249
|
- lib/one_apm/agent/event/event_loop.rb
|
250
|
+
- lib/one_apm/agent/event/timer.rb
|
250
251
|
- lib/one_apm/agent/event/worker_loop.rb
|
251
252
|
- lib/one_apm/agent/harvester.rb
|
252
253
|
- lib/one_apm/agent/inbound_request_monitor.rb
|
@@ -308,6 +309,7 @@ files:
|
|
308
309
|
- lib/one_apm/inst/background_job/active_job.rb
|
309
310
|
- lib/one_apm/inst/background_job/delayed_job.rb
|
310
311
|
- lib/one_apm/inst/background_job/delayed_job_injection.rb
|
312
|
+
- lib/one_apm/inst/background_job/event_machine_standalone.rb
|
311
313
|
- lib/one_apm/inst/background_job/resque.rb
|
312
314
|
- lib/one_apm/inst/background_job/sidekiq.rb
|
313
315
|
- lib/one_apm/inst/dispatcher/passenger.rb
|
@@ -330,7 +332,6 @@ files:
|
|
330
332
|
- lib/one_apm/inst/nosql/redis.rb
|
331
333
|
- lib/one_apm/inst/orm/active_record.rb
|
332
334
|
- lib/one_apm/inst/orm/active_record_4.rb
|
333
|
-
- lib/one_apm/inst/orm/data_mapper.rb
|
334
335
|
- lib/one_apm/inst/orm/sequel.rb
|
335
336
|
- lib/one_apm/inst/rack.rb
|
336
337
|
- lib/one_apm/inst/rack/rack.rb
|
@@ -393,7 +394,6 @@ files:
|
|
393
394
|
- lib/one_apm/support/marshaller.rb
|
394
395
|
- lib/one_apm/support/method_tracer.rb
|
395
396
|
- lib/one_apm/support/method_tracer/helpers.rb
|
396
|
-
- lib/one_apm/support/method_tracer/traced_method_stack.rb
|
397
397
|
- lib/one_apm/support/obfuscator.rb
|
398
398
|
- lib/one_apm/support/okjson.rb
|
399
399
|
- lib/one_apm/support/parameter_filtering.rb
|
@@ -404,6 +404,7 @@ files:
|
|
404
404
|
- lib/one_apm/support/supported_versions.rb
|
405
405
|
- lib/one_apm/support/system_info.rb
|
406
406
|
- lib/one_apm/support/timer_lib.rb
|
407
|
+
- lib/one_apm/support/traced_method_stack.rb
|
407
408
|
- lib/one_apm/support/version_number.rb
|
408
409
|
- lib/one_apm/support/vm.rb
|
409
410
|
- lib/one_apm/support/vm/jruby_vm.rb
|
@@ -1,180 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
LibraryDetection.defer do
|
4
|
-
@name = :data_mapper
|
5
|
-
|
6
|
-
depends_on do
|
7
|
-
defined?(::DataMapper)
|
8
|
-
end
|
9
|
-
|
10
|
-
depends_on do
|
11
|
-
defined?(DataMapper::Model)
|
12
|
-
end
|
13
|
-
|
14
|
-
depends_on do
|
15
|
-
defined?(DataMapper::Resource)
|
16
|
-
end
|
17
|
-
|
18
|
-
depends_on do
|
19
|
-
defined?(DataMapper::Collection)
|
20
|
-
end
|
21
|
-
|
22
|
-
executes do
|
23
|
-
::OneApm::Agent.logger.info 'Installing DataMapper instrumentation'
|
24
|
-
end
|
25
|
-
|
26
|
-
executes do
|
27
|
-
DataMapper::Model.class_eval do
|
28
|
-
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
|
29
|
-
add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
|
30
|
-
add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
|
31
|
-
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
32
|
-
|
33
|
-
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
34
|
-
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
35
|
-
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
36
|
-
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
37
|
-
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
38
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
39
|
-
|
40
|
-
# For dm-aggregates and partial dm-ar-finders support:
|
41
|
-
for method in [ :aggregate, :find, :find_by_sql ] do
|
42
|
-
next unless method_defined? method
|
43
|
-
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
executes do
|
50
|
-
DataMapper::Resource.class_eval do
|
51
|
-
add_method_tracer :update, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
|
52
|
-
add_method_tracer :update!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
|
53
|
-
add_method_tracer :save, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
|
54
|
-
add_method_tracer :save!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
|
55
|
-
add_method_tracer :destroy, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
56
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
executes do
|
62
|
-
DataMapper::Collection.class_eval do
|
63
|
-
# DM's Collection instance methods
|
64
|
-
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
|
65
|
-
add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
|
66
|
-
add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
|
67
|
-
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
68
|
-
|
69
|
-
add_method_tracer :lazy_load, 'ActiveRecord/#{self.name}/lazy_load'
|
70
|
-
|
71
|
-
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
72
|
-
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
73
|
-
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
74
|
-
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
75
|
-
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
76
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
77
|
-
|
78
|
-
# For dm-aggregates support:
|
79
|
-
for method in [ :aggregate ] do
|
80
|
-
next unless method_defined? method
|
81
|
-
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
LibraryDetection.defer do
|
89
|
-
|
90
|
-
depends_on do
|
91
|
-
defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
|
92
|
-
end
|
93
|
-
|
94
|
-
executes do
|
95
|
-
|
96
|
-
DataMapper::Adapters::DataObjectsAdapter.class_eval do
|
97
|
-
|
98
|
-
add_method_tracer :select, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/select'
|
99
|
-
add_method_tracer :execute, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/execute'
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
LibraryDetection.defer do
|
106
|
-
|
107
|
-
depends_on do
|
108
|
-
defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
|
109
|
-
end
|
110
|
-
|
111
|
-
executes do
|
112
|
-
DataMapper::Validations::ClassMethods.class_eval do
|
113
|
-
next unless method_defined? :create
|
114
|
-
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
LibraryDetection.defer do
|
120
|
-
|
121
|
-
depends_on do
|
122
|
-
defined?(DataMapper) && defined?(DataMapper::Transaction)
|
123
|
-
end
|
124
|
-
|
125
|
-
executes do
|
126
|
-
DataMapper::Transaction.module_eval do
|
127
|
-
add_method_tracer :commit, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/commit'
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
module OneApm
|
134
|
-
module Agent
|
135
|
-
module Instrumentation
|
136
|
-
module DataMapperInstrumentation
|
137
|
-
|
138
|
-
def log(msg) #THREAD_LOCAL_ACCESS
|
139
|
-
state = OneApm::TransactionState.tl_get
|
140
|
-
return unless state.is_execution_traced?
|
141
|
-
return unless operation = case OneApm::Helper.correctly_encoded(msg.query)
|
142
|
-
when /^\s*select/i then 'find'
|
143
|
-
when /^\s*(update|insert)/i then 'save'
|
144
|
-
when /^\s*delete/i then 'destroy'
|
145
|
-
else nil
|
146
|
-
end
|
147
|
-
|
148
|
-
# FYI: self.to_s will yield connection URI string.
|
149
|
-
duration = msg.duration / 1000000.0
|
150
|
-
|
151
|
-
# Attach SQL to current segment/scope.
|
152
|
-
OneApm::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration, state)
|
153
|
-
|
154
|
-
# Record query duration associated with each of the desired metrics.
|
155
|
-
metric = "ActiveRecord/#{operation}"
|
156
|
-
rollup_metrics = ActiveRecordHelper.rollup_metrics_for(metric)
|
157
|
-
metrics = [metric] + rollup_metrics
|
158
|
-
OneApm::Agent.instance.stats_engine.tl_record_unscoped_metrics(metrics, duration)
|
159
|
-
ensure
|
160
|
-
super
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
LibraryDetection.defer do
|
169
|
-
|
170
|
-
depends_on do
|
171
|
-
defined?(DataObjects) && defined?(DataObjects::Connection)
|
172
|
-
end
|
173
|
-
|
174
|
-
executes do
|
175
|
-
DataObjects::Connection.class_eval do
|
176
|
-
include ::OneApm::Agent::Instrumentation::DataMapperInstrumentation
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|