app_perf_rpm 0.0.5 → 0.0.6
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/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
@@ -19,82 +19,123 @@ 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, :sqlite)
|
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('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
|
-
exec_query_without_trace(sql, name, binds)
|
39
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
|
40
49
|
end
|
41
50
|
|
42
51
|
def exec_delete_with_trace(sql, name = nil, binds = [])
|
43
52
|
if ::AppPerfRpm::Tracer.tracing?
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
sanitized_sql = sanitize_sql(sql, :sqlite)
|
48
|
-
|
49
|
-
AppPerfRpm::Tracer.trace('activerecord', opts) do |span|
|
50
|
-
span.options = {
|
51
|
-
"adapter" => "postgresql",
|
52
|
-
"query" => sanitized_sql,
|
53
|
-
"name" => name
|
54
|
-
}
|
53
|
+
unless ignore_trace?(name)
|
54
|
+
adapter = connection_config.fetch(:adapter)
|
55
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
span = AppPerfRpm.tracer.start_span('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)
|
58
68
|
end
|
59
|
-
else
|
60
|
-
exec_delete_without_trace(sql, name, binds)
|
61
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
|
62
80
|
end
|
63
81
|
|
64
82
|
def exec_insert_with_trace(sql, name = nil, binds = [], *args)
|
65
83
|
if ::AppPerfRpm::Tracer.tracing?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
sanitized_sql = sanitize_sql(sql, :sqlite)
|
70
|
-
|
71
|
-
AppPerfRpm::Tracer.trace('activerecord', opts) do |span|
|
72
|
-
span.options = {
|
73
|
-
"adapter" => "postgresql",
|
74
|
-
"query" => sanitized_sql,
|
75
|
-
"name" => name
|
76
|
-
}
|
84
|
+
unless ignore_trace?(name)
|
85
|
+
adapter = connection_config.fetch(:adapter)
|
86
|
+
sanitized_sql = sanitize_sql(sql, adapter)
|
77
87
|
|
78
|
-
|
79
|
-
|
88
|
+
span = AppPerfRpm.tracer.start_span('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)
|
80
99
|
end
|
81
|
-
else
|
82
|
-
exec_insert_without_trace(sql, name, binds, *args)
|
83
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
|
84
111
|
end
|
85
112
|
|
86
113
|
def begin_db_transaction_with_trace
|
87
114
|
if ::AppPerfRpm::Tracer.tracing?
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
115
|
+
adapter = connection_config.fetch(:adapter)
|
116
|
+
|
117
|
+
span = AppPerfRpm.tracer.start_span('sql.query', tags: {
|
118
|
+
"component" => "ActiveRecord",
|
119
|
+
"span.kind" => "client",
|
120
|
+
"db.statement" => "BEGIN",
|
121
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
122
|
+
"db.instance" => connection_config.fetch(:database),
|
123
|
+
"db.vendor" => adapter,
|
124
|
+
"db.type" => "sql"
|
125
|
+
})
|
126
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
127
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
128
|
+
end
|
129
|
+
|
130
|
+
begin_db_transaction_without_trace
|
131
|
+
rescue Exception => e
|
132
|
+
if span
|
133
|
+
span.set_tag('error', true)
|
134
|
+
span.log_error(e)
|
97
135
|
end
|
136
|
+
raise
|
137
|
+
ensure
|
138
|
+
span.finish if span
|
98
139
|
end
|
99
140
|
end
|
100
141
|
end
|
@@ -7,7 +7,7 @@ module AppPerfRpm
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
if ::AppPerfRpm.
|
10
|
+
if ::AppPerfRpm.config.instrumentation[:active_record][:enabled] &&
|
11
11
|
defined?(::ActiveRecord)
|
12
12
|
AppPerfRpm.logger.info "Initializing activerecord tracer."
|
13
13
|
|
@@ -12,29 +12,38 @@ module AppPerfRpm
|
|
12
12
|
[sql_copy.shift, sql_copy.join( ' ' )]
|
13
13
|
end
|
14
14
|
|
15
|
-
adapter =
|
16
|
-
|
15
|
+
adapter = connection_config.fetch(:adapter)
|
17
16
|
sanitized_sql = sanitize_sql(base_sql + values.join( ',' ) + post_sql, adapter)
|
18
17
|
|
19
|
-
AppPerfRpm
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
span = AppPerfRpm.tracer.start_span(self.class.name || 'sql.query', tags: {
|
19
|
+
"component" => "ActiveRecordImport",
|
20
|
+
"span.kind" => "client",
|
21
|
+
"db.statement" => sanitized_sql,
|
22
|
+
"db.user" => connection_config.fetch(:username, 'unknown'),
|
23
|
+
"db.instance" => connection_config.fetch(:database),
|
24
|
+
"db.vendor" => adapter,
|
25
|
+
"db.type" => "sql"
|
26
|
+
})
|
27
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
28
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
29
|
+
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
insert_many_without_trace(sql, values, *args)
|
32
|
+
rescue Exception => e
|
33
|
+
if span
|
34
|
+
span.set_tag('error', true)
|
35
|
+
span.log_error(e)
|
30
36
|
end
|
37
|
+
raise
|
38
|
+
ensure
|
39
|
+
span.finish if span
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
36
45
|
|
37
|
-
if ::AppPerfRpm.
|
46
|
+
if ::AppPerfRpm.config.instrumentation[:active_record_import][:enabled] &&
|
38
47
|
defined?(ActiveRecord::Import::PostgreSQLAdapter)
|
39
48
|
AppPerfRpm.logger.info "Initializing activerecord-import tracer."
|
40
49
|
|
@@ -5,21 +5,30 @@ module AppPerfRpm
|
|
5
5
|
def route_with_trace(topic, type, message)
|
6
6
|
action = type.to_s.split(".").last
|
7
7
|
|
8
|
-
::AppPerfRpm
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
span = ::AppPerfRpm.tracer.start_span("#{topic}##{action}", tags: {
|
9
|
+
"component" => "EmqueConsuming",
|
10
|
+
"http.url" => "/#{topic}/#{action}",
|
11
|
+
"peer.address" => Socket.gethostname
|
12
|
+
})
|
13
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
14
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
13
15
|
|
14
|
-
|
16
|
+
route_without_trace(topic, type, message)
|
17
|
+
rescue Exception => e
|
18
|
+
if span
|
19
|
+
span.set_tag('error', true)
|
20
|
+
span.log_error(e)
|
15
21
|
end
|
22
|
+
raise
|
23
|
+
ensure
|
24
|
+
span.finish if span
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
22
|
-
if ::AppPerfRpm.
|
31
|
+
if ::AppPerfRpm.config.instrumentation[:emque_consuming][:enabled] && defined?(Emque::Consuming)
|
23
32
|
AppPerfRpm.logger.info "Initializing emque-consuming tracer."
|
24
33
|
|
25
34
|
Emque::Consuming::Router.send(:include, AppPerfRpm::Instruments::EmqueConsuming::Router)
|
@@ -2,31 +2,41 @@ module AppPerfRpm
|
|
2
2
|
module Instruments
|
3
3
|
module FaradayConnection
|
4
4
|
def run_request_with_trace(method, url, body, headers, &block)
|
5
|
-
if ::AppPerfRpm.tracing?
|
6
|
-
span = ::AppPerfRpm
|
5
|
+
if ::AppPerfRpm::Tracer.tracing?
|
6
|
+
span = ::AppPerfRpm.tracer.start_span("faraday", tags: {
|
7
|
+
"component" => "Faraday",
|
8
|
+
"span.kind" => "client"
|
9
|
+
})
|
10
|
+
AppPerfRpm.tracer.inject(span.context, OpenTracing::FORMAT_RACK, @headers)
|
7
11
|
result = run_request_without_trace(method, url, body, headers, &block)
|
12
|
+
span.set_tag "middleware", @builder.handlers
|
13
|
+
span.set_tag "peer.hostname", @url_prefix.host
|
14
|
+
span.set_tag "peer.port", @url_prefix.port
|
15
|
+
span.set_tag "http.protocol", @url_prefix.scheme
|
16
|
+
span.set_tag "http.url", url
|
17
|
+
span.set_tag "http.method", method
|
18
|
+
span.set_tag "http.status_code", result.status
|
19
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
20
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
8
21
|
span.finish
|
9
|
-
span.options = {
|
10
|
-
"middleware" => @builder.handlers,
|
11
|
-
"protocol" => @url_prefix.scheme,
|
12
|
-
"remote_host" => @url_prefix.host,
|
13
|
-
"remote_port" => @url_prefix.port,
|
14
|
-
"service_url" => url,
|
15
|
-
"http_method" => method,
|
16
|
-
"http_status" => result.status
|
17
|
-
}
|
18
|
-
span.submit(opts)
|
19
|
-
|
20
|
-
result
|
21
22
|
else
|
22
|
-
run_request_without_trace(method, url, body, headers, &block)
|
23
|
+
result = run_request_without_trace(method, url, body, headers, &block)
|
24
|
+
end
|
25
|
+
result
|
26
|
+
rescue Exception => e
|
27
|
+
if span
|
28
|
+
span.set_tag('error', true)
|
29
|
+
span.log_error(e)
|
23
30
|
end
|
31
|
+
raise
|
32
|
+
ensure
|
33
|
+
span.finish if span
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
|
-
if ::AppPerfRpm.
|
39
|
+
if ::AppPerfRpm.config.instrumentation[:faraday][:enabled] && defined?(::Faraday)
|
30
40
|
::AppPerfRpm.logger.info "Initializing faraday tracer."
|
31
41
|
|
32
42
|
::Faraday::Connection.send(:include, AppPerfRpm::Instruments::FaradayConnection)
|
@@ -1,29 +1,35 @@
|
|
1
|
-
if ::AppPerfRpm.
|
1
|
+
if ::AppPerfRpm.config.instrumentation[:net_http][:enabled] && defined?(Net::HTTP)
|
2
2
|
::AppPerfRpm.logger.info "Initializing net-http tracer."
|
3
3
|
|
4
4
|
Net::HTTP.class_eval do
|
5
5
|
def request_with_trace(*args, &block)
|
6
6
|
if ::AppPerfRpm::Tracer.tracing?
|
7
|
-
span = ::AppPerfRpm
|
7
|
+
span = ::AppPerfRpm.tracer.start_span("net-http", {
|
8
|
+
"component" => "NetHttp",
|
9
|
+
"span.kind" => "client"
|
10
|
+
})
|
8
11
|
|
9
12
|
if args.length && args[0]
|
10
13
|
req = args[0]
|
11
|
-
span.
|
12
|
-
span.
|
13
|
-
span.
|
14
|
-
span.
|
14
|
+
AppPerfRpm.tracer.inject(span.context, OpenTracing::FORMAT_RACK, req)
|
15
|
+
span.set_tag "http.protocol", (use_ssl? ? "https" : "http")
|
16
|
+
span.set_tag "http.url", req.path
|
17
|
+
span.set_tag "http.method", req.method
|
18
|
+
span.set_tag "peer.hostname", addr_port
|
19
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
20
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
15
21
|
end
|
16
22
|
|
17
23
|
response = request_without_trace(*args, &block)
|
18
24
|
|
19
|
-
span.
|
20
|
-
span.
|
25
|
+
span.exit
|
26
|
+
span.set_tag "http.status_code", response.code
|
21
27
|
|
22
28
|
if (response.code.to_i >= 300 || response.code.to_i <= 308) && response.header["Location"]
|
23
|
-
span.
|
29
|
+
span.set_tag "http.redirect", response.header["Location"]
|
24
30
|
end
|
25
31
|
|
26
|
-
|
32
|
+
span.finish
|
27
33
|
else
|
28
34
|
response = request_without_trace(*args, &block)
|
29
35
|
end
|
@@ -3,54 +3,103 @@ module AppPerfRpm
|
|
3
3
|
module RackModule
|
4
4
|
def call(env)
|
5
5
|
req = ::Rack::Request.new(env)
|
6
|
-
status, headers, body = nil, nil, nil
|
7
6
|
|
8
|
-
if ::AppPerfRpm::Tracer.in_trace? &&
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
#if ::AppPerfRpm::Tracer.in_trace? &&
|
8
|
+
# ::AppPerfRpm.config.instrumentation[:rack][:trace_middleware]
|
9
|
+
# AppPerfRpm::Tracer.trace("rack-middleware") do |span|
|
10
|
+
# span.set_tag "type", "web"
|
11
|
+
# span.set_tag "domain", req.host
|
12
|
+
# span.set_tag "url", req.path
|
13
|
+
# span.set_tag "class", @app.class.name
|
14
|
+
#
|
15
|
+
# status, headers, body = @app.call env
|
16
|
+
# end
|
17
|
+
#else
|
18
|
+
span = AppPerfRpm.tracer.start_span("rack")
|
19
|
+
span.set_tag "type", "web"
|
20
|
+
span.set_tag "domain", req.host
|
21
|
+
span.set_tag "url", req.path
|
22
|
+
span.set_tag "class", @app.class.name
|
23
|
+
span.set_tag "backtrace", ::AppPerfRpm::Backtrace.backtrace
|
24
|
+
span.set_tag "source", ::AppPerfRpm::Backtrace.source_extract
|
15
25
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
span.domain = req.host
|
22
|
-
span.url = req.path
|
23
|
-
span.options["class"] = @app.class.name
|
24
|
-
|
25
|
-
status, headers, body = @app.call env
|
26
|
-
end
|
26
|
+
@app.call(env)
|
27
|
+
rescue Exception => e
|
28
|
+
if span
|
29
|
+
span.set_tag('error', true)
|
30
|
+
span.log_error(e)
|
27
31
|
end
|
28
|
-
|
29
|
-
|
32
|
+
raise
|
33
|
+
ensure
|
34
|
+
span.finish if span
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
|
-
if ::AppPerfRpm.
|
40
|
+
if ::AppPerfRpm.config.instrumentation[:rack][:enabled]
|
36
41
|
::AppPerfRpm.logger.info "Initializing rack tracer."
|
37
42
|
|
38
|
-
if ::AppPerfRpm.
|
43
|
+
if ::AppPerfRpm.config.instrumentation[:rack][:trace_middleware]
|
39
44
|
::AppPerfRpm.logger.info "Initializing rack-middleware tracer."
|
40
45
|
end
|
41
46
|
|
42
47
|
module AppPerfRpm
|
43
48
|
module Instruments
|
44
49
|
class Rack
|
45
|
-
|
50
|
+
attr_reader :app
|
51
|
+
|
52
|
+
#include AppPerfRpm::Instruments::RackModule
|
46
53
|
|
47
54
|
def initialize(app)
|
48
55
|
@app = app
|
49
56
|
end
|
57
|
+
|
58
|
+
def call(env)
|
59
|
+
req = ::Rack::Request.new(env)
|
60
|
+
|
61
|
+
unless ignore_path?(req.path)
|
62
|
+
extracted_ctx = AppPerfRpm.tracer.extract(OpenTracing::FORMAT_RACK, env)
|
63
|
+
AppPerfRpm::Tracer.sample!(extracted_ctx)
|
64
|
+
|
65
|
+
if AppPerfRpm::Tracer.tracing?
|
66
|
+
span = AppPerfRpm.tracer.start_span(@app.class.name, :child_of => extracted_ctx, tags: {
|
67
|
+
"component" => "Rack",
|
68
|
+
"span.kind" => "client"
|
69
|
+
})
|
70
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
71
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
status, headers, response = @app.call(env)
|
76
|
+
|
77
|
+
if span
|
78
|
+
span.set_tag "peer.address", req.host
|
79
|
+
span.set_tag "peer.port", req.port
|
80
|
+
span.set_tag "http.method", req.request_method
|
81
|
+
span.set_tag "http.url", req.path
|
82
|
+
span.set_tag "http.status_code", status
|
83
|
+
end
|
84
|
+
|
85
|
+
[status, headers, response]
|
86
|
+
rescue Exception => e
|
87
|
+
if span
|
88
|
+
span.set_tag('error', true)
|
89
|
+
span.log_error(e)
|
90
|
+
end
|
91
|
+
raise
|
92
|
+
ensure
|
93
|
+
span.finish if span
|
94
|
+
end
|
95
|
+
|
96
|
+
def ignore_path?(path)
|
97
|
+
path.to_s =~ AppPerfRpm.config.ignore_paths
|
98
|
+
end
|
50
99
|
end
|
51
100
|
end
|
52
101
|
end
|
53
|
-
|
102
|
+
=begin
|
54
103
|
module ActionDispatch
|
55
104
|
class MiddlewareStack
|
56
105
|
class AppPerfRack
|
@@ -74,4 +123,5 @@ if ::AppPerfRpm.configuration.instrumentation[:rack][:enabled]
|
|
74
123
|
end
|
75
124
|
end
|
76
125
|
end
|
126
|
+
=end
|
77
127
|
end
|
@@ -1,30 +1,66 @@
|
|
1
1
|
module AppPerf
|
2
2
|
module Instruments
|
3
3
|
module Redis
|
4
|
-
|
4
|
+
include AppPerfRpm::Utils
|
5
|
+
|
6
|
+
def call_with_trace(*command, &block)
|
5
7
|
if ::AppPerfRpm::Tracer.tracing?
|
6
|
-
::AppPerfRpm
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
span = ::AppPerfRpm.tracer.start_span("redis", tags: {
|
9
|
+
"component" => "Redis",
|
10
|
+
"span.kind" => "client",
|
11
|
+
"peer.address" => self.host,
|
12
|
+
"peer.port" => self.port,
|
13
|
+
"db.type" => "redis",
|
14
|
+
"db.vendor" => "redis",
|
15
|
+
"db.instance" => self.db,
|
16
|
+
"db.statement" => format_redis_command(*command)
|
17
|
+
})
|
18
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
19
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
20
|
+
end
|
21
|
+
|
22
|
+
call_without_trace(*command, &block)
|
23
|
+
rescue Exception => e
|
24
|
+
if span
|
25
|
+
span.set_tag('error', true)
|
26
|
+
span.log_error(e)
|
11
27
|
end
|
28
|
+
raise
|
29
|
+
ensure
|
30
|
+
span.finish if span
|
12
31
|
end
|
13
32
|
|
14
|
-
def call_pipeline_with_trace(pipeline)
|
33
|
+
def call_pipeline_with_trace(*pipeline)
|
15
34
|
if ::AppPerfRpm::Tracer.tracing?
|
16
|
-
::AppPerfRpm
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
35
|
+
span = ::AppPerfRpm.tracer.start_span("redis", tags: {
|
36
|
+
"component" => "Redis",
|
37
|
+
"span.kind" => "client",
|
38
|
+
"peer.address" => self.host,
|
39
|
+
"peer.port" => self.port,
|
40
|
+
"db.type" => "redis",
|
41
|
+
"db.vendor" => "redis",
|
42
|
+
"db.instance" => self.db,
|
43
|
+
"db.statement" => pipeline[0].commands.map { |c| format_redis_command(c) }.join("\n")
|
44
|
+
})
|
45
|
+
span.log(event: "backtrace", stack: ::AppPerfRpm::Backtrace.backtrace)
|
46
|
+
span.log(event: "source", stack: ::AppPerfRpm::Backtrace.source_extract)
|
47
|
+
end
|
48
|
+
|
49
|
+
call_pipeline_without_trace(*pipeline)
|
50
|
+
rescue Exception => e
|
51
|
+
if span
|
52
|
+
span.set_tag('error', true)
|
53
|
+
span.log_error(e)
|
21
54
|
end
|
55
|
+
raise
|
56
|
+
ensure
|
57
|
+
span.finish if span
|
22
58
|
end
|
23
59
|
end
|
24
60
|
end
|
25
61
|
end
|
26
62
|
|
27
|
-
if ::AppPerfRpm.
|
63
|
+
if ::AppPerfRpm.config.instrumentation[:redis][:enabled] &&
|
28
64
|
defined?(::Redis)
|
29
65
|
::AppPerfRpm.logger.info "Initializing redis tracer."
|
30
66
|
|