app_perf_rpm 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app_perf_rpm/backtrace.rb +7 -7
- data/lib/app_perf_rpm/configuration.rb +6 -4
- data/lib/app_perf_rpm/instruments/action_controller.rb +33 -16
- data/lib/app_perf_rpm/instruments/action_view.rb +93 -65
- data/lib/app_perf_rpm/instruments/active_record/adapters/mysql2.rb +24 -15
- data/lib/app_perf_rpm/instruments/active_record/adapters/postgresql.rb +95 -52
- data/lib/app_perf_rpm/instruments/active_record/adapters/sqlite3.rb +95 -54
- data/lib/app_perf_rpm/instruments/active_record.rb +1 -1
- data/lib/app_perf_rpm/instruments/activerecord_import.rb +22 -13
- data/lib/app_perf_rpm/instruments/emque_consuming.rb +16 -7
- data/lib/app_perf_rpm/instruments/faraday.rb +26 -16
- data/lib/app_perf_rpm/instruments/net_http.rb +16 -10
- data/lib/app_perf_rpm/instruments/rack.rb +75 -25
- data/lib/app_perf_rpm/instruments/redis.rb +49 -13
- data/lib/app_perf_rpm/instruments/sequel.rb +36 -28
- data/lib/app_perf_rpm/instruments/sidekiq.rb +65 -21
- data/lib/app_perf_rpm/instruments/sinatra.rb +34 -20
- data/lib/app_perf_rpm/instruments/typhoeus.rb +40 -21
- data/lib/app_perf_rpm/rails.rb +2 -1
- data/lib/app_perf_rpm/railtie.rb +4 -4
- data/lib/app_perf_rpm/reporters/json_client.rb +69 -0
- data/lib/app_perf_rpm/reporters/null_client.rb +14 -0
- data/lib/app_perf_rpm/tracer.rb +20 -89
- data/lib/app_perf_rpm/tracing/buffer.rb +25 -0
- data/lib/app_perf_rpm/tracing/carrier.rb +23 -0
- data/lib/app_perf_rpm/tracing/collector.rb +31 -0
- data/lib/app_perf_rpm/tracing/endpoint.rb +19 -0
- data/lib/app_perf_rpm/tracing/managed_span.rb +36 -0
- data/lib/app_perf_rpm/tracing/managed_tracer.rb +32 -0
- data/lib/app_perf_rpm/tracing/span.rb +67 -0
- data/lib/app_perf_rpm/tracing/span_context.rb +41 -0
- data/lib/app_perf_rpm/tracing/thread_span_stack.rb +32 -0
- data/lib/app_perf_rpm/tracing/trace_id.rb +11 -0
- data/lib/app_perf_rpm/tracing/tracer.rb +91 -0
- data/lib/app_perf_rpm/utils.rb +18 -0
- data/lib/app_perf_rpm.rb +59 -26
- metadata +90 -12
- data/lib/app_perf_rpm/aggregator.rb +0 -77
- data/lib/app_perf_rpm/dispatcher.rb +0 -85
- data/lib/app_perf_rpm/middleware.rb +0 -30
- data/lib/app_perf_rpm/span.rb +0 -103
- data/lib/app_perf_rpm/worker.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 049ed9d70578f19385c19d57d2a9794be48518a0
|
4
|
+
data.tar.gz: 5ebeb333e89d38319a413d92f4a7e41f5bd11348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50cfe054972dcb5a8ba179383c4ad7433a4a84c13d2c70f73afe6dd1401715e82d8bcecab2311b8e2a737de84507376eb5794b6e4e624ecbfda9c5a3a86ae3f3
|
7
|
+
data.tar.gz: 9ac2e437821c812c0c345dc61c32067ad35d7dc45c7614ae5f5bf6e1e85a89ee10b13f2c99ec83ecbe58ce4a3dda8c40211bf7901b23e41284d8903b146820f5
|
@@ -8,7 +8,7 @@ module AppPerfRpm
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def clean(backtrace)
|
11
|
-
backtrace
|
11
|
+
Array(backtrace)
|
12
12
|
.map {|b| clean_line(b) }
|
13
13
|
.select {|b| b !~ %r{lib/app_perf_rpm} }
|
14
14
|
end
|
@@ -27,7 +27,7 @@ module AppPerfRpm
|
|
27
27
|
#end
|
28
28
|
|
29
29
|
def source_extract(_backtrace = Kernel.caller(0))
|
30
|
-
Array(_backtrace).select {|bt| bt[/^#{::AppPerfRpm.
|
30
|
+
Array(_backtrace).select {|bt| bt[/^#{::AppPerfRpm.config.app_root.to_s}\//] }.map do |trace|
|
31
31
|
file, line_number = extract_file_and_line_number(trace)
|
32
32
|
source_to_hash(file, line_number)
|
33
33
|
end
|
@@ -41,14 +41,14 @@ module AppPerfRpm
|
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
44
|
-
private
|
45
|
-
|
46
44
|
def clean_line(line)
|
47
45
|
line
|
48
|
-
.sub(/#{::AppPerfRpm.
|
46
|
+
.sub(/#{::AppPerfRpm.config.app_root.to_s}\//, "[APP_PATH]/")
|
49
47
|
.sub(gems_regexp, '\2 (\3) [GEM_PATH]/\4')
|
50
48
|
end
|
51
49
|
|
50
|
+
private
|
51
|
+
|
52
52
|
def gems_regexp
|
53
53
|
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
|
54
54
|
if gems_paths
|
@@ -59,8 +59,8 @@ module AppPerfRpm
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def source_fragment(path, line)
|
62
|
-
return unless AppPerfRpm.
|
63
|
-
full_path = AppPerfRpm.
|
62
|
+
return unless AppPerfRpm.config.app_root
|
63
|
+
full_path = AppPerfRpm.config.app_root.join(path)
|
64
64
|
if File.exist?(full_path)
|
65
65
|
File.open(full_path, "r") do |file|
|
66
66
|
start = [line - 3, 0].max
|
@@ -9,10 +9,11 @@ module AppPerfRpm
|
|
9
9
|
:ssl,
|
10
10
|
:sample_rate,
|
11
11
|
:sample_threshold,
|
12
|
-
:
|
12
|
+
:flush_interval,
|
13
13
|
:application_name,
|
14
14
|
:instrumentation,
|
15
|
-
:agent_disabled
|
15
|
+
:agent_disabled,
|
16
|
+
:ignore_paths
|
16
17
|
|
17
18
|
def initialize
|
18
19
|
reload
|
@@ -27,10 +28,11 @@ module AppPerfRpm
|
|
27
28
|
self.application_name ||= "Default"
|
28
29
|
self.sample_rate ||= 10 # Percentage of request to sample
|
29
30
|
self.sample_threshold ||= 0 # Minimum amount of duration to sample
|
30
|
-
self.
|
31
|
+
self.flush_interval ||= 60 # In seconds
|
31
32
|
self.agent_disabled ||= default_if_blank(ENV["APP_PERF_AGENT_DISABLED"], false)
|
33
|
+
self.ignore_paths ||= /\/assets/
|
32
34
|
self.instrumentation = {
|
33
|
-
:rack => { :enabled => true, :backtrace => false, :trace_middleware =>
|
35
|
+
:rack => { :enabled => true, :backtrace => false, :trace_middleware => false },
|
34
36
|
:active_record => { :enabled => true, :backtrace => false },
|
35
37
|
:active_record_import => { :enabled => true, :backtrace => false },
|
36
38
|
:action_view => { :enabled => true, :backtrace => false },
|
@@ -3,34 +3,51 @@ module AppPerfRpm
|
|
3
3
|
module ActionController
|
4
4
|
def process_action_with_trace(method_name, *args)
|
5
5
|
if ::AppPerfRpm::Tracer.tracing?
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
operation = "#{self.class.name}##{self.action_name}"
|
7
|
+
span = AppPerfRpm.tracer.start_span(operation, tags: {
|
8
|
+
"component" => "ActionController",
|
9
|
+
"span.kind" => "client"
|
10
|
+
})
|
11
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
12
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
process_action_without_trace(method_name, *args)
|
16
|
+
rescue Exception => e
|
17
|
+
if span
|
18
|
+
span.set_tag('error', true)
|
19
|
+
span.log_error(e)
|
14
20
|
end
|
21
|
+
raise
|
22
|
+
ensure
|
23
|
+
span.finish if span
|
15
24
|
end
|
16
25
|
|
17
26
|
def perform_action_with_trace(*arguments)
|
18
27
|
if ::AppPerfRpm::Tracer.tracing?
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
operation = "#{@_request.path_parameters['controller']}##{@_request.path_parameters['action']}"
|
29
|
+
span = AppPerfRpm.tracer.start_span(operation, tags: {
|
30
|
+
"component" => "ActionController",
|
31
|
+
"span.kind" => "client"
|
32
|
+
})
|
33
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
34
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
35
|
+
end
|
36
|
+
perform_action_without_trace(*arguments)
|
37
|
+
rescue Exception => e
|
38
|
+
if span
|
39
|
+
span.set_tag('error', true)
|
40
|
+
span.log_error(e)
|
27
41
|
end
|
42
|
+
raise
|
43
|
+
ensure
|
44
|
+
span.finish if span
|
28
45
|
end
|
29
46
|
end
|
30
47
|
end
|
31
48
|
end
|
32
49
|
|
33
|
-
if ::AppPerfRpm.
|
50
|
+
if ::AppPerfRpm.config.instrumentation[:action_controller][:enabled] &&
|
34
51
|
defined?(::ActionController)
|
35
52
|
AppPerfRpm.logger.info "Initializing actioncontroller tracer."
|
36
53
|
|
@@ -1,46 +1,54 @@
|
|
1
|
-
if ::AppPerfRpm.
|
1
|
+
if ::AppPerfRpm.config.instrumentation[:action_view][:enabled] && defined?(::ActionView)
|
2
2
|
if defined?(Rails) && Rails::VERSION::MAJOR == 2
|
3
3
|
ActionView::Partials.module_eval do
|
4
4
|
alias :render_partial_without_trace :render_partial
|
5
5
|
def render_partial(options = {})
|
6
6
|
if ::AppPerfRpm::Tracer.tracing? && options.key?(:partial) && options[:partial].is_a?(String)
|
7
|
-
|
8
|
-
"
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
span.action = @_request.path_parameters['action']
|
18
|
-
span.backtrace = ::AppPerfRpm::Backtrace.backtrace
|
19
|
-
span.source = ::AppPerfRpm::Backtrace.source_extract
|
7
|
+
span = AppPerfRpm.tracer.start_span("render_partial", tags: {
|
8
|
+
"component" => "ActionView",
|
9
|
+
"span.kind" => "client",
|
10
|
+
"view.controller" => @_request.path_parameters['controller'],
|
11
|
+
"view.action" => @_request.path_parameters['action'],
|
12
|
+
"view.template" => options[:partial]
|
13
|
+
})
|
14
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
15
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
render_partial_without_trace(options)
|
19
|
+
rescue Exception => e
|
20
|
+
if span
|
21
|
+
span.set_tag('error', true)
|
22
|
+
span.log_error(e)
|
25
23
|
end
|
24
|
+
raise
|
25
|
+
ensure
|
26
|
+
span.finish if span
|
26
27
|
end
|
27
28
|
|
28
29
|
alias :render_partial_collection_without_trace :render_partial_collection
|
29
30
|
def render_partial_collection(options = {})
|
30
31
|
if ::AppPerfRpm::Tracer.tracing?
|
31
|
-
AppPerfRpm
|
32
|
-
|
33
|
-
span.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
span = AppPerfRpm.tracer.start_span("render_partial_collection", tags: {
|
33
|
+
"component" => "ActionView",
|
34
|
+
"span.kind" => "client",
|
35
|
+
"view.controller" => @_request.path_parameters['controller'],
|
36
|
+
"view.action" => @_request.path_parameters['action'],
|
37
|
+
"view.template" => @path
|
38
|
+
})
|
39
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
40
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
41
|
+
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
render_partial_collection_without_trace(options)
|
44
|
+
rescue Exception => e
|
45
|
+
if span
|
46
|
+
span.set_tag('error', true)
|
47
|
+
span.log_error(e)
|
43
48
|
end
|
49
|
+
raise
|
50
|
+
ensure
|
51
|
+
span.finish if span
|
44
52
|
end
|
45
53
|
end
|
46
54
|
else
|
@@ -48,35 +56,49 @@ if ::AppPerfRpm.configuration.instrumentation[:action_view][:enabled] && defined
|
|
48
56
|
alias :render_partial_without_trace :render_partial
|
49
57
|
def render_partial
|
50
58
|
if ::AppPerfRpm::Tracer.tracing?
|
51
|
-
AppPerfRpm
|
52
|
-
|
53
|
-
span.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
span = AppPerfRpm.tracer.start_span("render_partial", tags: {
|
60
|
+
"component" => "ActionView",
|
61
|
+
"span.kind" => "client",
|
62
|
+
"view.template" => @options[:partial]
|
63
|
+
})
|
64
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
65
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
66
|
+
end
|
58
67
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
render_partial_without_trace
|
69
|
+
rescue Exception => e
|
70
|
+
if span
|
71
|
+
span.set_tag('error', true)
|
72
|
+
span.log_error(e)
|
63
73
|
end
|
74
|
+
raise
|
75
|
+
ensure
|
76
|
+
span.finish if span
|
64
77
|
end
|
65
78
|
|
66
79
|
alias :render_collection_without_trace :render_collection
|
67
80
|
def render_collection
|
68
81
|
if ::AppPerfRpm::Tracer.tracing?
|
69
|
-
AppPerfRpm
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
82
|
+
span = AppPerfRpm.tracer.start_span("render_collection", tags: {
|
83
|
+
"component" => "ActionView",
|
84
|
+
"span.kind" => "client",
|
85
|
+
"view.controller" => @_request.path_parameters['controller'],
|
86
|
+
"view.action" => @_request.path_parameters['action'],
|
87
|
+
"view.template" => @path
|
88
|
+
})
|
89
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
90
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
91
|
+
end
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
93
|
+
render_collection_without_trace
|
94
|
+
rescue Exception => e
|
95
|
+
if span
|
96
|
+
span.set_tag('error', true)
|
97
|
+
span.log_error(e)
|
79
98
|
end
|
99
|
+
raise
|
100
|
+
ensure
|
101
|
+
span.finish if span
|
80
102
|
end
|
81
103
|
end
|
82
104
|
|
@@ -99,25 +121,31 @@ if ::AppPerfRpm.configuration.instrumentation[:action_view][:enabled] && defined
|
|
99
121
|
@path = path
|
100
122
|
end
|
101
123
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
else
|
111
|
-
span.options = {
|
112
|
-
"method" => "render_without_layout",
|
113
|
-
"path" => @path
|
114
|
-
}
|
124
|
+
if layout
|
125
|
+
span = AppPerfRpm.tracer.start_span("render_with_layout")
|
126
|
+
# span.set_tag "view.layout", layout
|
127
|
+
span.set_tag "view.template", layout.identifier
|
128
|
+
else
|
129
|
+
span = AppPerfRpm.tracer.start_span("render_without_layout")
|
130
|
+
if @path
|
131
|
+
span.set_tag "view.template", @path.call
|
115
132
|
end
|
116
|
-
render_with_layout_without_trace(path, locals, *args, &block)
|
117
133
|
end
|
118
|
-
|
119
|
-
|
134
|
+
span.set_tag "component", "ActionView"
|
135
|
+
span.set_tag "span.kind", "client"
|
136
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
137
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
138
|
+
end
|
139
|
+
|
140
|
+
render_with_layout_without_trace(path, locals, *args, &block)
|
141
|
+
rescue Exception => e
|
142
|
+
if span
|
143
|
+
span.set_tag('error', true)
|
144
|
+
span.log_error(e)
|
120
145
|
end
|
146
|
+
raise
|
147
|
+
ensure
|
148
|
+
span.finish if span
|
121
149
|
end
|
122
150
|
end
|
123
151
|
end
|
@@ -19,24 +19,33 @@ module AppPerfRpm
|
|
19
19
|
|
20
20
|
def execute_with_trace(sql, name = nil)
|
21
21
|
if ::AppPerfRpm::Tracer.tracing?
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
sanitized_sql = sanitize_sql(sql, :mysql2)
|
22
|
+
unless ignore_trace?(name)
|
23
|
+
adapter = connection_config.fetch(:adapter)
|
24
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
26
25
|
|
27
|
-
AppPerfRpm
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
|
27
|
+
"component" => "ActiveRecord",
|
28
|
+
"span.kind" => "client",
|
29
|
+
"db.statement" => sanitized_sql,
|
30
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
31
|
+
"db.instance" => connection_config.fetch(:database),
|
32
|
+
"db.vendor" => adapter,
|
33
|
+
"db.type" => "sql"
|
34
|
+
})
|
35
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
36
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
36
37
|
end
|
37
|
-
else
|
38
|
-
execute_without_trace(sql, name)
|
39
38
|
end
|
39
|
+
|
40
|
+
execute_without_trace(sql, name)
|
41
|
+
rescue Exception => e
|
42
|
+
if span
|
43
|
+
span.set_tag('error', true)
|
44
|
+
span.log_error(e)
|
45
|
+
end
|
46
|
+
raise
|
47
|
+
ensure
|
48
|
+
span.finish if span
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
@@ -19,81 +19,124 @@ module AppPerfRpm
|
|
19
19
|
|
20
20
|
def exec_query_with_trace(sql, name = nil, binds = [])
|
21
21
|
if ::AppPerfRpm::Tracer.tracing?
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
sanitized_sql = sanitize_sql(sql, :postgres)
|
22
|
+
unless ignore_trace?(name)
|
23
|
+
adapter = connection_config.fetch(:adapter)
|
24
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
26
25
|
|
27
|
-
AppPerfRpm
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
|
27
|
+
"component" => "ActiveRecord",
|
28
|
+
"span.kind" => "client",
|
29
|
+
"db.statement" => sanitized_sql,
|
30
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
31
|
+
"db.instance" => connection_config.fetch(:database),
|
32
|
+
"db.vendor" => adapter,
|
33
|
+
"db.type" => "sql"
|
34
|
+
})
|
35
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
36
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
35
37
|
end
|
36
|
-
else
|
37
|
-
exec_query_without_trace(sql, name, binds)
|
38
38
|
end
|
39
|
+
|
40
|
+
exec_query_without_trace(sql, name, binds)
|
41
|
+
rescue Exception => e
|
42
|
+
if span
|
43
|
+
span.set_tag('error', true)
|
44
|
+
span.log_error(e)
|
45
|
+
end
|
46
|
+
raise
|
47
|
+
ensure
|
48
|
+
span.finish if span
|
39
49
|
end
|
40
50
|
|
41
51
|
def exec_delete_with_trace(sql, name = nil, binds = [])
|
42
52
|
if ::AppPerfRpm::Tracer.tracing?
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
sanitized_sql = sanitize_sql(sql)
|
53
|
+
unless ignore_trace?(name)
|
54
|
+
adapter = connection_config.fetch(:adapter)
|
55
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
47
56
|
|
48
|
-
AppPerfRpm
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
|
58
|
+
"component" => "ActiveRecord",
|
59
|
+
"span.kind" => "client",
|
60
|
+
"db.statement" => sanitized_sql,
|
61
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
62
|
+
"db.instance" => connection_config.fetch(:database),
|
63
|
+
"db.vendor" => adapter,
|
64
|
+
"db.type" => "sql"
|
65
|
+
})
|
66
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
67
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
56
68
|
end
|
57
|
-
else
|
58
|
-
exec_delete_without_trace(sql, name, binds)
|
59
69
|
end
|
70
|
+
|
71
|
+
exec_delete_without_trace(sql, name, binds)
|
72
|
+
rescue Exception => e
|
73
|
+
if span
|
74
|
+
span.set_tag('error', true)
|
75
|
+
span.log_error(e)
|
76
|
+
end
|
77
|
+
raise
|
78
|
+
ensure
|
79
|
+
span.finish if span
|
60
80
|
end
|
61
81
|
|
62
82
|
def exec_insert_with_trace(sql, name = nil, binds = [], *args)
|
63
83
|
if ::AppPerfRpm::Tracer.tracing?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
sanitized_sql = sanitize_sql(sql, :postgres)
|
68
|
-
|
69
|
-
AppPerfRpm::Tracer.trace('activerecord') do |span|
|
70
|
-
span.options = {
|
71
|
-
"adapter" => "postgresql",
|
72
|
-
"query" => sanitized_sql,
|
73
|
-
"name" => name
|
74
|
-
}
|
84
|
+
unless ignore_trace?(name)
|
85
|
+
adapter = connection_config.fetch(:adapter)
|
86
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
75
87
|
|
76
|
-
|
77
|
-
|
88
|
+
span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
|
89
|
+
"component" => "ActiveRecord",
|
90
|
+
"span.kind" => "client",
|
91
|
+
"db.statement" => sanitized_sql,
|
92
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
93
|
+
"db.instance" => connection_config.fetch(:database),
|
94
|
+
"db.vendor" => adapter,
|
95
|
+
"db.type" => "sql"
|
96
|
+
})
|
97
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
98
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
78
99
|
end
|
79
|
-
else
|
80
|
-
exec_insert_without_trace(sql, name, binds, *args)
|
81
100
|
end
|
101
|
+
|
102
|
+
exec_insert_without_trace(sql, name, binds, *args)
|
103
|
+
rescue Exception => e
|
104
|
+
if span
|
105
|
+
span.set_tag('error', true)
|
106
|
+
span.log_error(e)
|
107
|
+
end
|
108
|
+
raise
|
109
|
+
ensure
|
110
|
+
span.finish if span
|
82
111
|
end
|
83
112
|
|
84
113
|
def begin_db_transaction_with_trace
|
85
114
|
if ::AppPerfRpm::Tracer.tracing?
|
86
|
-
|
87
|
-
|
88
|
-
"adapter" => "postgresql",
|
89
|
-
"query" => "BEGIN"
|
90
|
-
}
|
115
|
+
adapter = connection_config.fetch(:adapter)
|
116
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
91
117
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
118
|
+
span = AppPerfRpm.tracer.start_span('sql.query', tags: {
|
119
|
+
"component" => "ActiveRecord",
|
120
|
+
"span.kind" => "client",
|
121
|
+
"db.statement" => "BEGIN",
|
122
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
123
|
+
"db.instance" => connection_config.fetch(:database),
|
124
|
+
"db.vendor" => adapter,
|
125
|
+
"db.type" => "sql"
|
126
|
+
})
|
127
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
128
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
129
|
+
end
|
130
|
+
|
131
|
+
begin_db_transaction_without_trace
|
132
|
+
rescue Exception => e
|
133
|
+
if span
|
134
|
+
span.set_tag('error', true)
|
135
|
+
span.log_error(e)
|
96
136
|
end
|
137
|
+
raise
|
138
|
+
ensure
|
139
|
+
span.finish if span
|
97
140
|
end
|
98
141
|
end
|
99
142
|
end
|