app_perf_rpm 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3acd152efd84397682641dd381b931c8a005251
4
- data.tar.gz: 3f6b8ee3b1bc73675323e7050791511b725a2360
3
+ metadata.gz: 5514146ba2ff7a662504fe584fbc5f7275f88ae8
4
+ data.tar.gz: 71671f2252b993f5e99d0c240c9502e564001eff
5
5
  SHA512:
6
- metadata.gz: d60c4242d0f5d71a614bffba15b140a3d05b9b98a8eef9b51d080786802a31ab8bb34cdf69549c03445ae9e6aeb033f7d55caf0f0781291ab79604309b9020ed
7
- data.tar.gz: 13ca881a617b1af03acc08c3a579de2678c240c0a746c77e2633417ad8a42678422e5a5e56b8548e387298653078d06ce5c08c836bf5449ffa4c51ad1de2cc6e
6
+ metadata.gz: 115dfee2ee761d034683660bc271503977de17915a679893074ab904fa963f5dc028986db2e420a2ccd2787286ff443b6387dc0183489197d6d2c976eba6f443
7
+ data.tar.gz: 98749bc895ca61c62195a522a938a91b4750fcbd18eec63f25279ffe4c990a9d476263f10598760e6b9de5781b59687f5e6f0922bbc81063a3e94a2b272e6334
@@ -150,7 +150,11 @@ module AppPerfRpm
150
150
  end
151
151
 
152
152
  def now
153
- Process.clock_gettime(Process::CLOCK_REALTIME)
153
+ if defined?(Process::CLOCK_REALTIME)
154
+ Process.clock_gettime(Process::CLOCK_REALTIME)
155
+ else
156
+ Time.now
157
+ end
154
158
  end
155
159
 
156
160
  end
@@ -1,7 +1,9 @@
1
1
  module AppPerfRpm
2
2
  class Backtrace
3
3
  class << self
4
- def backtrace(kind: :all)
4
+ def backtrace(opts = {})
5
+ kind = opts[:kind]
6
+
5
7
  if kind
6
8
  bt = Kernel.caller
7
9
  bt = clean(bt)
@@ -42,7 +44,9 @@ module AppPerfRpm
42
44
  # end
43
45
  #end
44
46
 
45
- def source_extract(backtrace: Kernel.caller(0))
47
+ def source_extract(opts = {})
48
+ backtrace = opts[:backtrace] || Kernel.caller(0)
49
+
46
50
  Array(backtrace).select {|bt| bt[/^#{::AppPerfRpm.config.app_root.to_s}\//] }.map do |trace|
47
51
  file, line_number = extract_file_and_line_number(trace)
48
52
  source_to_hash(file, line_number)
@@ -91,7 +95,9 @@ module AppPerfRpm
91
95
  [file, line.to_i]
92
96
  end
93
97
 
94
- def trim_backtrace(_backtrace, kind: :all)
98
+ def trim_backtrace(_backtrace, opts = {})
99
+ kind = opts[:kind]
100
+
95
101
  return _backtrace unless _backtrace.is_a?(Array)
96
102
 
97
103
  length = _backtrace.size
@@ -34,6 +34,7 @@ module AppPerfRpm
34
34
  self.instrumentation = {
35
35
  :rack => { :enabled => true, :backtrace => :app, :source => true, :trace_middleware => false },
36
36
  :roda => { :enabled => true, :backtrace => :app, :source => true },
37
+ :grape => { :enabled => true, :backtrace => :app, :source => true },
37
38
  :active_record => { :enabled => true, :backtrace => :app, :source => true },
38
39
  :active_record_import => { :enabled => true, :backtrace => :app, :source => true },
39
40
  :active_model_serializer => { :enabled => true, :backtrace => :app, :source => true },
@@ -49,8 +49,10 @@ if ::AppPerfRpm.config.instrumentation[:action_view][:enabled] && defined?(::Act
49
49
  span.finish if span
50
50
  end
51
51
  end
52
- else
53
- ActionView::PartialRenderer.class_eval do
52
+ end
53
+
54
+ if defined?(Rails) && Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 0
55
+ ::ActionView::Partials::PartialRenderer.class_eval do
54
56
  alias :render_partial_without_trace :render_partial
55
57
  def render_partial
56
58
  if ::AppPerfRpm::Tracer.tracing?
@@ -100,41 +102,104 @@ if ::AppPerfRpm.config.instrumentation[:action_view][:enabled] && defined?(::Act
100
102
  end
101
103
  end
102
104
 
103
- ::ActionView::TemplateRenderer.class_eval do
104
- alias render_with_layout_without_trace render_with_layout
105
+ ::ActionView::Rendering.class_eval do
106
+ alias :_render_template_without_trace _render_template
105
107
 
106
- def render_with_layout(path, locals, *args, &block)
108
+ def _render_template(template, layout = nil, options = {})
107
109
  if ::AppPerfRpm::Tracer.tracing?
108
- layout = nil
109
-
110
- if path
111
- if method(:find_layout).arity == 3
112
- # Rails 5
113
- layout = find_layout(path, locals.keys, [formats.first])
114
- else
115
- # Rails 3, 4
116
- layout = find_layout(path, locals.keys)
117
- end
118
-
119
- @path = path
120
- end
110
+ span = AppPerfRpm.tracer.start_span("render_template")
111
+ span.set_tag "view.template", template
112
+ span.set_tag "view.layout", layout
113
+ span.set_tag "component", "ActionView"
114
+ span.set_tag "span.kind", "client"
115
+ AppPerfRpm::Utils.log_source_and_backtrace(span, :action_view)
116
+ end
121
117
 
122
- if layout
123
- span = AppPerfRpm.tracer.start_span("render_with_layout")
124
- # span.set_tag "view.layout", layout
125
- span.set_tag "view.template", layout.identifier
126
- else
127
- span = AppPerfRpm.tracer.start_span("render_without_layout")
128
- if @path
129
- span.set_tag "view.template", @path.call
130
- end
118
+ _render_template_without_trace(template, layout, options)
119
+ rescue Exception => e
120
+ if span
121
+ span.set_tag('error', true)
122
+ span.log_error(e)
123
+ end
124
+ raise
125
+ ensure
126
+ span.finish if span
127
+ end
128
+ end
129
+ end
130
+
131
+ if defined?(Rails) && Rails.version >= '3.1.0'
132
+ ActionView::PartialRenderer.class_eval do
133
+ alias :render_partial_without_trace :render_partial
134
+ def render_partial
135
+ if ::AppPerfRpm::Tracer.tracing?
136
+ span = AppPerfRpm.tracer.start_span("render_partial", tags: {
137
+ "component" => "ActionView",
138
+ "span.kind" => "client",
139
+ "view.template" => @options[:partial]
140
+ })
141
+ AppPerfRpm::Utils.log_source_and_backtrace(span, :action_view)
142
+ end
143
+
144
+ render_partial_without_trace
145
+ rescue Exception => e
146
+ if span
147
+ span.set_tag('error', true)
148
+ span.log_error(e)
149
+ end
150
+ raise
151
+ ensure
152
+ span.finish if span
153
+ end
154
+
155
+ alias :render_collection_without_trace :render_collection
156
+ def render_collection
157
+ if ::AppPerfRpm::Tracer.tracing?
158
+ span = AppPerfRpm.tracer.start_span("render_collection", tags: {
159
+ "component" => "ActionView",
160
+ "span.kind" => "client",
161
+ "view.template" => @path
162
+ })
163
+ if @_request
164
+ span.set_tag('view.controller', @_request.path_parameters['controller'])
165
+ span.set_tag('view.action', @_request.path_parameters['action'])
131
166
  end
167
+ AppPerfRpm::Utils.log_source_and_backtrace(span, :action_view)
168
+ end
169
+
170
+ render_collection_without_trace
171
+ rescue Exception => e
172
+ if span
173
+ span.set_tag('error', true)
174
+ span.log_error(e)
175
+ end
176
+ raise
177
+ ensure
178
+ span.finish if span
179
+ end
180
+ end
181
+
182
+ ::ActionView::TemplateRenderer.class_eval do
183
+ alias :render_template_without_trace :render_template
184
+
185
+ def render_template(template, layout_name = nil, locals = {})
186
+ if ::AppPerfRpm::Tracer.tracing?
187
+ layout = if layout_name.is_a?(String)
188
+ layout_name
189
+ elsif method(:find_layout).arity == 3
190
+ find_layout(layout_name, locals, [formats.first])
191
+ elsif locals
192
+ find_layout(layout_name, locals)
193
+ end
194
+ span = AppPerfRpm.tracer.start_span("render_template")
195
+ span.set_tag "view.layout", layout
196
+ span.set_tag "view.template", template.identifier
132
197
  span.set_tag "component", "ActionView"
133
198
  span.set_tag "span.kind", "client"
134
199
  AppPerfRpm::Utils.log_source_and_backtrace(span, :action_view)
135
200
  end
136
201
 
137
- render_with_layout_without_trace(path, locals, *args, &block)
202
+ render_template_without_trace(template, layout_name, locals)
138
203
  rescue Exception => e
139
204
  if span
140
205
  span.set_tag('error', true)
@@ -17,11 +17,16 @@ if ::AppPerfRpm.config.instrumentation[:active_record][:enabled] &&
17
17
  ::AppPerfRpm::Instruments::ActiveRecord::Adapters::Sqlite3
18
18
  )
19
19
  ::ActiveRecord::ConnectionAdapters::SQLite3Adapter.class_eval do
20
- alias_method :exec_query_without_trace, :exec_query
21
- alias_method :exec_query, :exec_query_with_trace
20
+ if Rails.version < "3.1"
21
+ alias_method :exec_query_without_trace, :execute
22
+ alias_method :execute, :exec_query_with_trace
23
+ else
24
+ alias_method :exec_query_without_trace, :exec_query
25
+ alias_method :exec_query, :exec_query_with_trace
22
26
 
23
- alias_method :exec_delete_without_trace, :exec_delete
24
- alias_method :exec_delete, :exec_delete_with_trace
27
+ alias_method :exec_delete_without_trace, :exec_delete
28
+ alias_method :exec_delete, :exec_delete_with_trace
29
+ end
25
30
  end
26
31
  end
27
32
 
@@ -32,11 +37,16 @@ if ::AppPerfRpm.config.instrumentation[:active_record][:enabled] &&
32
37
  )
33
38
 
34
39
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
35
- alias_method :exec_query_without_trace, :exec_query
36
- alias_method :exec_query, :exec_query_with_trace
40
+ if Rails.version < "3.1"
41
+ alias_method :exec_query_without_trace, :execute
42
+ alias_method :execute, :exec_query_with_trace
43
+ else
44
+ alias_method :exec_query_without_trace, :exec_query
45
+ alias_method :exec_query, :exec_query_with_trace
37
46
 
38
- alias_method :exec_delete_without_trace, :exec_delete
39
- alias_method :exec_delete, :exec_delete_with_trace
47
+ alias_method :exec_delete_without_trace, :exec_delete
48
+ alias_method :exec_delete, :exec_delete_with_trace
49
+ end
40
50
  end
41
51
  end
42
52
 
@@ -47,11 +57,8 @@ if ::AppPerfRpm.config.instrumentation[:active_record][:enabled] &&
47
57
  )
48
58
 
49
59
  ::ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
50
- if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR == 0) ||
51
- ::ActiveRecord::VERSION::MAJOR == 2
52
- alias_method :execute_without_trace, :execute
53
- alias_method :execute, :execute_with_trace
54
- end
60
+ alias_method :execute_without_trace, :execute
61
+ alias_method :execute, :execute_with_trace
55
62
  end
56
63
  end
57
64
  end
@@ -23,7 +23,7 @@ module AppPerfRpm
23
23
  adapter = connection_config.fetch(:adapter)
24
24
  sanitized_sql = sanitize_sql(sql, adapter)
25
25
 
26
- span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
26
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
27
27
  "component" => "ActiveRecord",
28
28
  "span.kind" => "client",
29
29
  "db.statement" => sanitized_sql,
@@ -23,7 +23,7 @@ module AppPerfRpm
23
23
  adapter = connection_config.fetch(:adapter)
24
24
  sanitized_sql = sanitize_sql(sql, adapter)
25
25
 
26
- span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
26
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
27
27
  "component" => "ActiveRecord",
28
28
  "span.kind" => "client",
29
29
  "db.statement" => sanitized_sql,
@@ -53,7 +53,7 @@ module AppPerfRpm
53
53
  adapter = connection_config.fetch(:adapter)
54
54
  sanitized_sql = sanitize_sql(sql, adapter)
55
55
 
56
- span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
56
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
57
57
  "component" => "ActiveRecord",
58
58
  "span.kind" => "client",
59
59
  "db.statement" => sanitized_sql,
@@ -83,7 +83,7 @@ module AppPerfRpm
83
83
  adapter = connection_config.fetch(:adapter)
84
84
  sanitized_sql = sanitize_sql(sql, adapter)
85
85
 
86
- span = AppPerfRpm.tracer.start_span(name || 'sql.query', tags: {
86
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
87
87
  "component" => "ActiveRecord",
88
88
  "span.kind" => "client",
89
89
  "db.statement" => sanitized_sql,
@@ -112,7 +112,7 @@ module AppPerfRpm
112
112
  adapter = connection_config.fetch(:adapter)
113
113
  sanitized_sql = sanitize_sql(sql, adapter)
114
114
 
115
- span = AppPerfRpm.tracer.start_span('sql.query', tags: {
115
+ span = AppPerfRpm.tracer.start_span('SQL', tags: {
116
116
  "component" => "ActiveRecord",
117
117
  "span.kind" => "client",
118
118
  "db.statement" => "BEGIN",
@@ -17,13 +17,13 @@ module AppPerfRpm
17
17
  name == 'ActiveRecord::SchemaMigration Load'
18
18
  end
19
19
 
20
- def exec_query_with_trace(sql, name = nil, binds = [])
20
+ def exec_query_with_trace(sql, name = nil, *args)
21
21
  if ::AppPerfRpm::Tracer.tracing?
22
22
  unless ignore_trace?(name)
23
23
  adapter = connection_config.fetch(:adapter)
24
24
  sanitized_sql = sanitize_sql(sql, adapter)
25
25
 
26
- span = AppPerfRpm.tracer.start_span('sql.query', tags: {
26
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
27
27
  "component" => "ActiveRecord",
28
28
  "span.kind" => "client",
29
29
  "db.statement" => sanitized_sql,
@@ -36,7 +36,7 @@ module AppPerfRpm
36
36
  end
37
37
  end
38
38
 
39
- exec_query_without_trace(sql, name, binds)
39
+ exec_query_without_trace(sql, name, *args)
40
40
  rescue Exception => e
41
41
  if span
42
42
  span.set_tag('error', true)
@@ -47,13 +47,13 @@ module AppPerfRpm
47
47
  span.finish if span
48
48
  end
49
49
 
50
- def exec_delete_with_trace(sql, name = nil, binds = [])
50
+ def exec_delete_with_trace(sql, name = nil, *args)
51
51
  if ::AppPerfRpm::Tracer.tracing?
52
52
  unless ignore_trace?(name)
53
53
  adapter = connection_config.fetch(:adapter)
54
54
  sanitized_sql = sanitize_sql(sql, adapter)
55
55
 
56
- span = AppPerfRpm.tracer.start_span('sql.query', tags: {
56
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
57
57
  "component" => "ActiveRecord",
58
58
  "span.kind" => "client",
59
59
  "db.statement" => sanitized_sql,
@@ -66,7 +66,7 @@ module AppPerfRpm
66
66
  end
67
67
  end
68
68
 
69
- exec_delete_without_trace(sql, name, binds)
69
+ exec_delete_without_trace(sql, name, *args)
70
70
  rescue Exception => e
71
71
  if span
72
72
  span.set_tag('error', true)
@@ -77,13 +77,13 @@ module AppPerfRpm
77
77
  span.finish if span
78
78
  end
79
79
 
80
- def exec_insert_with_trace(sql, name = nil, binds = [], *args)
80
+ def exec_insert_with_trace(sql, name = nil, *args)
81
81
  if ::AppPerfRpm::Tracer.tracing?
82
82
  unless ignore_trace?(name)
83
83
  adapter = connection_config.fetch(:adapter)
84
84
  sanitized_sql = sanitize_sql(sql, adapter)
85
85
 
86
- span = AppPerfRpm.tracer.start_span('sql.query', tags: {
86
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
87
87
  "component" => "ActiveRecord",
88
88
  "span.kind" => "client",
89
89
  "db.statement" => sanitized_sql,
@@ -111,7 +111,7 @@ module AppPerfRpm
111
111
  if ::AppPerfRpm::Tracer.tracing?
112
112
  adapter = connection_config.fetch(:adapter)
113
113
 
114
- span = AppPerfRpm.tracer.start_span('sql.query', tags: {
114
+ span = AppPerfRpm.tracer.start_span(name || 'SQL', tags: {
115
115
  "component" => "ActiveRecord",
116
116
  "span.kind" => "client",
117
117
  "db.statement" => "BEGIN",
@@ -0,0 +1,61 @@
1
+ module AppPerfRpm
2
+ module Instruments
3
+ module GrapeMiddleware
4
+
5
+ def call_with_trace(env)
6
+ req = ::Rack::Request.new(env)
7
+
8
+ if AppPerfRpm::Tracer.tracing?
9
+ request_method = req.request_method.to_s.upcase
10
+ path = req.path
11
+ endpoint = env["api.endpoint"]
12
+
13
+ if endpoint && endpoint.options
14
+ options = endpoint.options
15
+ request_method = options[:method].first.to_s.upcase
16
+ klass = options[:for]
17
+ namespace = endpoint.namespace
18
+ namespace = "" if namespace == "/"
19
+
20
+ path = options[:path].first.to_s
21
+ path = "/#{path}" if path[0] != "/"
22
+ path = "#{namespace}#{path}"
23
+ end
24
+
25
+ action = path.to_s.split("/").last
26
+ operation = "#{klass}##{action}"
27
+
28
+ span = AppPerfRpm.tracer.start_span(operation, tags: {
29
+ "component" => "Grape",
30
+ "span.kind" => "client",
31
+ "class.name" => @app.class.name,
32
+ "http.path" => path,
33
+ "http.method" => request_method
34
+ })
35
+ AppPerfRpm::Utils.log_source_and_backtrace(span, :rack)
36
+ end
37
+
38
+ begin
39
+ call_without_trace(env)
40
+ rescue Exception => e
41
+ if span
42
+ span.set_tag('error', true)
43
+ span.log_error(e)
44
+ end
45
+ raise
46
+ ensure
47
+ span.finish if span
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ if ::AppPerfRpm.config.instrumentation[:grape][:enabled] && defined?(::Grape)
55
+ ::AppPerfRpm.logger.info "Initializing grape tracer."
56
+ ::Grape::Middleware::Base.send(:include, AppPerfRpm::Instruments::GrapeMiddleware)
57
+ ::Grape::Middleware::Base.class_eval do
58
+ alias_method :call_without_trace, :call
59
+ alias_method :call, :call_with_trace
60
+ end
61
+ end
@@ -4,7 +4,7 @@ if ::AppPerfRpm.config.instrumentation[:net_http][:enabled] && defined?(Net::HTT
4
4
  Net::HTTP.class_eval do
5
5
  def request_with_trace(*args, &block)
6
6
  if ::AppPerfRpm::Tracer.tracing?
7
- span = ::AppPerfRpm.tracer.start_span("net-http", {
7
+ span = ::AppPerfRpm.tracer.start_span("net-http", tags: {
8
8
  "component" => "NetHttp",
9
9
  "span.kind" => "client"
10
10
  })
@@ -6,10 +6,10 @@ require 'base64'
6
6
  module AppPerfRpm
7
7
  module Reporters
8
8
  class JsonClient
9
- def initialize(url:, collector:, flush_interval:)
10
- @collector = collector
11
- @flush_interval = flush_interval
12
- @spans_uri = URI.parse(url)
9
+ def initialize(opts = { :url => nil, :collector => nil, :flush_interval => nil })
10
+ @collector = opts[:collector]
11
+ @flush_interval = opts[:flush_interval]
12
+ @spans_uri = URI.parse(opts[:url])
13
13
  end
14
14
 
15
15
  def start
@@ -1,5 +1,3 @@
1
- require 'opentracing'
2
-
3
1
  module AppPerfRpm
4
2
  class Tracer
5
3
  class << self
@@ -27,9 +27,11 @@ module AppPerfRpm
27
27
  end
28
28
  end
29
29
 
30
- def finish(end_time: AppPerfRpm.now)
30
+ def finish(opts = {})
31
+ opts[:end_time] ||= AppPerfRpm.now
32
+
31
33
  deactivate
32
- @span.finish(end_time: end_time)
34
+ @span.finish(end_time: opts[:end_time])
33
35
  end
34
36
  end
35
37
  end
@@ -1,6 +1,6 @@
1
1
  module AppPerfRpm
2
2
  module Tracing
3
- class ManagedTracer < OpenTracing::Tracer
3
+ class ManagedTracer
4
4
  extend Forwardable
5
5
  def_delegators :@tracer, :inject, :extract
6
6
 
@@ -23,8 +23,10 @@ module AppPerfRpm
23
23
  thread_span_stack.active_span
24
24
  end
25
25
 
26
- def start_span(operation_name, child_of: active_span, **args)
27
- span = @tracer.start_span(operation_name, child_of: child_of, **args)
26
+ def start_span(operation_name, opts = {}, *args)
27
+ opts[:child_of] ||= active_span
28
+
29
+ span = @tracer.start_span(operation_name, opts, *args)
28
30
  @thread_span_stack.set_active_span(span)
29
31
  end
30
32
  end
@@ -4,13 +4,13 @@ module AppPerfRpm
4
4
  attr_accessor :operation_name
5
5
 
6
6
  attr_reader :context, :start_time, :end_time, :tags, :log_entries
7
- def initialize(context, operation_name, collector, start_time: AppPerfRpm.now, tags: {})
7
+ def initialize(context, operation_name, collector, opts = {})
8
8
  @context = context
9
9
  @operation_name = operation_name
10
10
  @collector = collector
11
- @start_time = start_time
11
+ @start_time = opts[:start_time] || AppPerfRpm.now
12
12
  @end_time = nil
13
- @tags = tags
13
+ @tags = opts[:tags] || {}
14
14
  @log_entries = []
15
15
  end
16
16
 
@@ -32,22 +32,25 @@ module AppPerfRpm
32
32
  @context.get_baggage_item(key)
33
33
  end
34
34
 
35
- def log(event: nil, timestamp: AppPerfRpm.now, **fields)
35
+ # Original definition for ruby 2+ was this:
36
+ # def log(opts = { :event => nil, :timestamp => AppPerfRpm.now }, **fields)
37
+ # but this doesn't work in 1.9.
38
+ def log(opts = {}, *_, fields)
36
39
  entry = {
37
- "event" => event,
38
- "timestamp" => timestamp,
40
+ "event" => opts[:event] || nil,
41
+ "timestamp" => opts[:timestamp] || AppPerfRpm.now,
39
42
  }
40
43
 
41
- entry["fields"] = fields if fields
44
+ entry["fields"] = fields
42
45
  @log_entries << entry
43
46
 
44
47
  nil
45
48
  end
46
49
 
47
- def log_error(exception, timestamp: AppPerfRpm.now)
50
+ def log_error(exception, opts = {})
48
51
  log(
49
52
  event: "error",
50
- timestamp: timestamp,
53
+ timestamp: opts[:timestamp] || AppPerfRpm.now,
51
54
  message: exception.message,
52
55
  error_class: exception.class.to_s,
53
56
  backtrace: AppPerfRpm::Backtrace.clean(exception.backtrace),
@@ -55,12 +58,12 @@ module AppPerfRpm
55
58
  )
56
59
  end
57
60
 
58
- def exit(end_time: AppPerfRpm.now)
59
- @end_time = end_time
61
+ def exit(opts = {})
62
+ @end_time = opts[:end_time] || AppPerfRpm.now
60
63
  end
61
64
 
62
- def finish(end_time: AppPerfRpm.now)
63
- @collector.send_span(self, @end_time || end_time)
65
+ def finish(opts = {})
66
+ @collector.send_span(self, @end_time || opts[:end_time] || AppPerfRpm.now)
64
67
  end
65
68
  end
66
69
  end
@@ -17,12 +17,12 @@ module AppPerfRpm
17
17
 
18
18
  attr_reader :span_id, :parent_id, :trace_id, :baggage
19
19
 
20
- def initialize(span_id:, parent_id: nil, trace_id:, sampled:, baggage: {})
21
- @span_id = span_id
22
- @parent_id = parent_id
23
- @trace_id = trace_id
24
- @sampled = sampled
25
- @baggage = baggage
20
+ def initialize(opts = {})
21
+ @span_id = opts[:span_id] || nil
22
+ @parent_id = opts[:parent_id] || nil
23
+ @trace_id = opts[:trace_id] || nil
24
+ @sampled = opts[:sampled] || nil
25
+ @baggage = opts[:baggage] || {}
26
26
  end
27
27
 
28
28
  def set_baggage_item(key, value)
@@ -1,13 +1,16 @@
1
- require 'opentracing'
2
-
3
1
  module AppPerfRpm
4
2
  module Tracing
5
3
  class Tracer
6
4
  attr_reader :thread_span_stack, :collector
7
5
 
8
- def self.build(collector:, sender:, service_name:)
9
- sender.start
10
- new(collector, sender)
6
+ def self.build(opts = {})
7
+ opts[:collector] ||= nil
8
+ opts[:sender] ||= nil
9
+ opts[:service_name] ||= nil
10
+
11
+ opts[:sender].start
12
+
13
+ new(opts[:collector], opts[:sender])
11
14
  end
12
15
 
13
16
  def initialize(collector, sender)
@@ -19,7 +22,11 @@ module AppPerfRpm
19
22
  @sender.stop
20
23
  end
21
24
 
22
- def start_span(operation_name, child_of: nil, start_time: AppPerfRpm.now, tags: {}, **)
25
+ def start_span(operation_name, opts = {}, *)
26
+ child_of = opts[:child_of] || nil
27
+ opts[:start_time] ||= AppPerfRpm.now
28
+ opts[:tags] ||= {}
29
+
23
30
  context =
24
31
  if child_of
25
32
  parent_context = child_of.respond_to?(:context) ? child_of.context : child_of
@@ -29,8 +36,8 @@ module AppPerfRpm
29
36
  end
30
37
 
31
38
  span = Span.new(context, operation_name, @collector, {
32
- start_time: start_time,
33
- tags: tags
39
+ start_time: opts[:start_time],
40
+ tags: opts[:tags]
34
41
  })
35
42
  end
36
43
 
@@ -7,7 +7,7 @@ module AppPerfRpm
7
7
  end
8
8
 
9
9
  def connection_config
10
- @connection_config ||= if ::ActiveRecord::VERSION::MAJOR == 2
10
+ @connection_config ||= if ::ActiveRecord::VERSION::MAJOR == 2 || (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR < 1)
11
11
  ActiveRecord::Base.connection.instance_variable_get(:@config)
12
12
  else
13
13
  ::ActiveRecord::Base.connection_config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_perf_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy Girard
@@ -24,78 +24,50 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: opentracing
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 0.3.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 0.3.1
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 12.0.0
33
+ version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 12.0.0
40
+ version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - '='
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: 3.5.0
47
+ version: '0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - '='
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: 3.5.0
54
+ version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pry
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - '='
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: 0.10.4
61
+ version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - '='
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: 0.10.4
68
+ version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 0.12.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 0.12.0
97
- - !ruby/object:Gem::Dependency
98
- name: rails
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -123,7 +95,7 @@ dependencies:
123
95
  - !ruby/object:Gem::Version
124
96
  version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
- name: actionpack
98
+ name: appraisal
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
@@ -137,7 +109,7 @@ dependencies:
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
- name: activesupport
112
+ name: wwtd
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - ">="
@@ -170,6 +142,7 @@ files:
170
142
  - lib/app_perf_rpm/instruments/activerecord_import.rb
171
143
  - lib/app_perf_rpm/instruments/emque_consuming.rb
172
144
  - lib/app_perf_rpm/instruments/faraday.rb
145
+ - lib/app_perf_rpm/instruments/grape.rb
173
146
  - lib/app_perf_rpm/instruments/net_http.rb
174
147
  - lib/app_perf_rpm/instruments/rack.rb
175
148
  - lib/app_perf_rpm/instruments/redis.rb
@@ -218,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
191
  version: '0'
219
192
  requirements: []
220
193
  rubyforge_project:
221
- rubygems_version: 2.6.11
194
+ rubygems_version: 2.6.14
222
195
  signing_key:
223
196
  specification_version: 4
224
197
  summary: AppPerf Ruby Agent