atatus 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5404a3f0f7c5ebac24d42dc0e52a3e039627e985d8e5fcf9473c485c33154cd2
4
- data.tar.gz: ec420ee8f2ff19f32bb3bf49c0d5ddddb106fbfec4add1c2c98a8103b455e08c
3
+ metadata.gz: acfc54c3597def60fca53e99bf249711197735e0507b9bcade319f10182cbc26
4
+ data.tar.gz: efb49084366463b5ed40d3b4c57609ada57e745f28f8ac5949456e242167ede1
5
5
  SHA512:
6
- metadata.gz: 5a595c22ae3e30caf7db053d5bc354e9c1ab11824bbc8ea9d8846aca1ad29a1ffea8fce445a76b86c0ae715a18c9f85cb4910a8a51f8461cf3b83fd653e0228e
7
- data.tar.gz: 87afe8b5bba6161baeffc5520f49ab924e0cd4c468d5f758b0f84a62e17b992403e9322a30ea17bf6a214b3829616373a23f950ef284b1eb9454bb49c07d436d
6
+ metadata.gz: e6e2af0647be02da224d11dd9a45650c0c6cae63e10dbfaf81fd2d757fe8aa3414ab82ffad9eb880fc73f3340c145a175374be77a41f646febd621bf50502dca
7
+ data.tar.gz: 170206df98d5e3b5ccf68271f9dfdb58042ce45b13129321105aac2cf4fa8a04095807e0adc4ed75589bd09b556284ea41ac5a2030565584d96640da58aac03c
@@ -4,8 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.0.1 (Wed, 13 Nov 2019)
7
8
 
8
- ## 1.0.0 (Tue, 29 October 2019)
9
+ - Fixed Instrumenting classes only when there are defined.
10
+ - Handled worker thread while exiting.
11
+
12
+
13
+ ## 1.0.0 (Tue, 29 Oct 2019)
9
14
 
10
15
  - General availability release of the Ruby agent.
11
16
 
@@ -130,6 +130,7 @@ module Atatus
130
130
  central_config.stop
131
131
  metrics.stop
132
132
  instrumenter.stop
133
+ collector.stop
133
134
  # transport.stop
134
135
 
135
136
  self
@@ -109,11 +109,24 @@ module Atatus
109
109
  end
110
110
 
111
111
  def start
112
- debug '%s: Starting Collector', pid_str
112
+ debug '%s: Starting collector', pid_str
113
113
 
114
114
  ensure_worker_running
115
115
  end
116
116
 
117
+ def stop
118
+ return unless @running
119
+ @running = false
120
+ if worker_active?
121
+ debug '%s: Waiting for collector worker to exit', pid_str
122
+ @worker.run
123
+ @worker.join(10)
124
+ end
125
+ rescue => e
126
+ error format('Failed during collector stop: [%s] %s', e.class, e.message)
127
+ error "Backtrace:\n" + e.backtrace.join("\n")
128
+ end
129
+
117
130
  def add_error(error)
118
131
  ensure_worker_running
119
132
 
@@ -241,7 +254,7 @@ module Atatus
241
254
  return if worker_active?
242
255
  @running = true
243
256
  @worker = Thread.new() do
244
- debug '%s: Starting Collector Worker', pid_str
257
+ debug '%s: Starting collector worker', pid_str
245
258
 
246
259
  while @running
247
260
  start_time = Time.now
@@ -249,13 +262,6 @@ module Atatus
249
262
  collect start_time
250
263
  end
251
264
  end
252
-
253
- at_exit do
254
- debug '%s: Waiting for Collector Worker to exit', pid_str
255
- @running = false
256
- @worker.run
257
- @worker.join(10)
258
- end
259
265
  end
260
266
 
261
267
  def worker_active?
@@ -37,7 +37,7 @@ module Atatus
37
37
  Atatus.running?
38
38
  rescue StandardError => e
39
39
  config.logger.error format('Failed to start: %s', e.message)
40
- config.logger.debug "Backtrace:\n" + e.backtrace.join("\n")
40
+ config.logger.error "Backtrace:\n" + e.backtrace.join("\n")
41
41
  end
42
42
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
43
43
  # rubocop:enable Metrics/CyclomaticComplexity
@@ -10,16 +10,21 @@ module Atatus
10
10
 
11
11
  # rubocop:disable Metrics/MethodLength
12
12
  def install
13
- ::Elasticsearch::Transport::Client.class_eval do
14
- alias perform_request_without_apm perform_request
13
+ if defined?(::Elasticsearch) &&
14
+ defined?(::Elasticsearch::Transport) &&
15
+ defined?(::Elasticsearch::Transport::Client)
15
16
 
16
- def perform_request(method, path, *args, &block)
17
- name = format(NAME_FORMAT, method, path)
18
- statement = args[0].is_a?(String) ? args[0] : args[0].to_json
19
- context = Span::Context.new(db: { statement: statement })
17
+ ::Elasticsearch::Transport::Client.class_eval do
18
+ alias perform_request_without_apm perform_request
20
19
 
21
- Atatus.with_span name, TYPE, context: context do
22
- perform_request_without_apm(method, path, *args, &block)
20
+ def perform_request(method, path, *args, &block)
21
+ name = format(NAME_FORMAT, method, path)
22
+ statement = args[0].is_a?(String) ? args[0] : args[0].to_json
23
+ context = Span::Context.new(db: { statement: statement })
24
+
25
+ Atatus.with_span name, TYPE, context: context do
26
+ perform_request_without_apm(method, path, *args, &block)
27
+ end
23
28
  end
24
29
  end
25
30
  end
@@ -20,40 +20,43 @@ module Atatus
20
20
  # rubocop:disable Metrics/BlockLength, Metrics/PerceivedComplexity
21
21
  # rubocop:disable Metrics/CyclomaticComplexity
22
22
  def install
23
- ::Faraday::Connection.class_eval do
24
- alias run_request_without_apm run_request
23
+ if defined?(::Faraday) && defined?(::Faraday::Connection)
25
24
 
26
- def run_request(method, url, body, headers, &block)
27
- unless (transaction = Atatus.current_transaction)
28
- return run_request_without_apm(method, url, body, headers, &block)
29
- end
25
+ ::Faraday::Connection.class_eval do
26
+ alias run_request_without_apm run_request
27
+
28
+ def run_request(method, url, body, headers, &block)
29
+ unless (transaction = Atatus.current_transaction)
30
+ return run_request_without_apm(method, url, body, headers, &block)
31
+ end
30
32
 
31
- host = if url_prefix.is_a?(URI) && url_prefix.host
32
- url_prefix.host
33
- elsif url.nil?
34
- tmp_request = build_request(method) do |req|
35
- yield(req) if block_given?
33
+ host = if url_prefix.is_a?(URI) && url_prefix.host
34
+ url_prefix.host
35
+ elsif url.nil?
36
+ tmp_request = build_request(method) do |req|
37
+ yield(req) if block_given?
38
+ end
39
+ URI(tmp_request.path).host
40
+ else
41
+ URI(url).host
36
42
  end
37
- URI(tmp_request.path).host
38
- else
39
- URI(url).host
40
- end
41
43
 
42
- name = "#{method.upcase} #{host}"
44
+ name = "#{method.upcase} #{host}"
43
45
 
44
- Atatus.with_span(
45
- name,
46
- TYPE,
47
- subtype: SUBTYPE,
48
- action: method.to_s
49
- ) do |span|
50
- Atatus::Spies::FaradaySpy.without_net_http do
51
- trace_context = span&.trace_context || transaction.trace_context
46
+ Atatus.with_span(
47
+ name,
48
+ TYPE,
49
+ subtype: SUBTYPE,
50
+ action: method.to_s
51
+ ) do |span|
52
+ Atatus::Spies::FaradaySpy.without_net_http do
53
+ trace_context = span&.trace_context || transaction.trace_context
52
54
 
53
- run_request_without_apm(method, url, body, headers) do |req|
54
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
55
+ run_request_without_apm(method, url, body, headers) do |req|
56
+ req['Atatus-Apm-Traceparent'] = trace_context.to_header
55
57
 
56
- yield req if block_given?
58
+ yield req if block_given?
59
+ end
57
60
  end
58
61
  end
59
62
  end
@@ -10,28 +10,31 @@ module Atatus
10
10
 
11
11
  # rubocop:disable Metrics/MethodLength
12
12
  def install
13
- ::HTTP::Client.class_eval do
14
- alias perform_without_apm perform
13
+ if defined?(::HTTP) && defined?(::HTTP::Client)
15
14
 
16
- def perform(req, options)
17
- unless (transaction = Atatus.current_transaction)
18
- return perform_without_apm(req, options)
19
- end
15
+ ::HTTP::Client.class_eval do
16
+ alias perform_without_apm perform
17
+
18
+ def perform(req, options)
19
+ unless (transaction = Atatus.current_transaction)
20
+ return perform_without_apm(req, options)
21
+ end
20
22
 
21
- method = req.verb.to_s.upcase
22
- host = req.uri.host
23
+ method = req.verb.to_s.upcase
24
+ host = req.uri.host
23
25
 
24
- name = "#{method} #{host}"
26
+ name = "#{method} #{host}"
25
27
 
26
- Atatus.with_span(
27
- name,
28
- TYPE,
29
- subtype: SUBTYPE,
30
- action: method
31
- ) do |span|
32
- trace_context = span&.trace_context || transaction.trace_context
33
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
34
- perform_without_apm(req, options)
28
+ Atatus.with_span(
29
+ name,
30
+ TYPE,
31
+ subtype: SUBTYPE,
32
+ action: method
33
+ ) do |span|
34
+ trace_context = span&.trace_context || transaction.trace_context
35
+ req['Atatus-Apm-Traceparent'] = trace_context.to_header
36
+ perform_without_apm(req, options)
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -8,11 +8,14 @@ module Atatus
8
8
  # @api private
9
9
  class JSONSpy
10
10
  def install
11
- ::JSON.class_eval do
12
- include SpanHelpers
13
- span_class_method :parse, 'JSON#parse', 'json.parse'
14
- span_class_method :parse!, 'JSON#parse!', 'json.parse'
15
- span_class_method :generate, 'JSON#generate', 'json.generate'
11
+ if defined?(::JSON)
12
+
13
+ ::JSON.class_eval do
14
+ include SpanHelpers
15
+ span_class_method :parse, 'JSON#parse', 'json.parse'
16
+ span_class_method :parse!, 'JSON#parse!', 'json.parse'
17
+ span_class_method :generate, 'JSON#generate', 'json.generate'
18
+ end
16
19
  end
17
20
  end
18
21
  end
@@ -31,33 +31,35 @@ module Atatus
31
31
  end
32
32
 
33
33
  def install
34
- Net::HTTP.class_eval do
35
- alias request_without_apm request
34
+ if defined?(::Net) && defined?(::Net::HTTP)
35
+ ::Net::HTTP.class_eval do
36
+ alias request_without_apm request
36
37
 
37
- def request(req, body = nil, &block)
38
- unless (transaction = Atatus.current_transaction)
39
- return request_without_apm(req, body, &block)
40
- end
41
- if Atatus::Spies::NetHTTPSpy.disabled?
42
- return request_without_apm(req, body, &block)
43
- end
38
+ def request(req, body = nil, &block)
39
+ unless (transaction = Atatus.current_transaction)
40
+ return request_without_apm(req, body, &block)
41
+ end
42
+ if Atatus::Spies::NetHTTPSpy.disabled?
43
+ return request_without_apm(req, body, &block)
44
+ end
44
45
 
45
- host, = req['host'] && req['host'].split(':')
46
- method = req.method
46
+ host, = req['host'] && req['host'].split(':')
47
+ method = req.method
47
48
 
48
- host ||= address
49
+ host ||= address
49
50
 
50
- name = "#{method} #{host}"
51
+ name = "#{method} #{host}"
51
52
 
52
- Atatus.with_span(
53
- name,
54
- TYPE,
55
- subtype: SUBTYPE,
56
- action: method.to_s
57
- ) do |span|
58
- trace_context = span&.trace_context || transaction.trace_context
59
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
60
- request_without_apm(req, body, &block)
53
+ Atatus.with_span(
54
+ name,
55
+ TYPE,
56
+ subtype: SUBTYPE,
57
+ action: method.to_s
58
+ ) do |span|
59
+ trace_context = span&.trace_context || transaction.trace_context
60
+ req['Atatus-Apm-Traceparent'] = trace_context.to_header
61
+ request_without_apm(req, body, &block)
62
+ end
61
63
  end
62
64
  end
63
65
  end
@@ -6,16 +6,18 @@ module Atatus
6
6
  # @api private
7
7
  class RedisSpy
8
8
  def install
9
- ::Redis::Client.class_eval do
10
- alias call_without_apm call
9
+ if defined?(::Redis) && defined?(::Redis::Client)
10
+ ::Redis::Client.class_eval do
11
+ alias call_without_apm call
11
12
 
12
- def call(command, &block)
13
- name = command[0].upcase
13
+ def call(command, &block)
14
+ name = command[0].upcase
14
15
 
15
- return call_without_apm(command, &block) if command[0] == :auth
16
+ return call_without_apm(command, &block) if command[0] == :auth
16
17
 
17
- Atatus.with_span(name.to_s, 'db.redis') do
18
- call_without_apm(command, &block)
18
+ Atatus.with_span(name.to_s, 'db.redis') do
19
+ call_without_apm(command, &block)
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -23,19 +23,21 @@ module Atatus
23
23
  def install
24
24
  require 'sequel/database/logging'
25
25
 
26
- ::Sequel::Database.class_eval do
27
- alias log_connection_yield_without_apm log_connection_yield
26
+ if defined?(::Sequel) && defined?(::Sequel::Database)
27
+ ::Sequel::Database.class_eval do
28
+ alias log_connection_yield_without_apm log_connection_yield
28
29
 
29
- def log_connection_yield(sql, *args, &block)
30
- unless Atatus.current_transaction
31
- return log_connection_yield_without_apm(sql, *args, &block)
32
- end
30
+ def log_connection_yield(sql, *args, &block)
31
+ unless Atatus.current_transaction
32
+ return log_connection_yield_without_apm(sql, *args, &block)
33
+ end
33
34
 
34
- summarizer = Atatus::Spies::SequelSpy.summarizer
35
- name = summarizer.summarize sql
36
- context = Atatus::Spies::SequelSpy.build_context(sql, opts)
35
+ summarizer = Atatus::Spies::SequelSpy.summarizer
36
+ name = summarizer.summarize sql
37
+ context = Atatus::Spies::SequelSpy.build_context(sql, opts)
37
38
 
38
- Atatus.with_span(name, TYPE, context: context, &block)
39
+ Atatus.with_span(name, TYPE, context: context, &block)
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -7,27 +7,33 @@ module Atatus
7
7
  class SinatraSpy
8
8
  # rubocop:disable Metrics/MethodLength
9
9
  def install
10
- ::Sinatra::Base.class_eval do
11
- alias dispatch_without_apm! dispatch!
12
- alias compile_template_without_apm compile_template
10
+ if defined?(::Sinatra) &&
11
+ defined?(::Sinatra::Base) &&
12
+ ::Sinatra::Base.private_method_defined?(:dispatch!) &&
13
+ ::Sinatra::Base.private_method_defined?(:compile_template)
13
14
 
14
- def dispatch!(*args, &block)
15
- dispatch_without_apm!(*args, &block).tap do
16
- next unless (transaction = Atatus.current_transaction)
17
- next unless (route = env['sinatra.route'])
15
+ ::Sinatra::Base.class_eval do
16
+ alias dispatch_without_apm! dispatch!
17
+ alias compile_template_without_apm compile_template
18
18
 
19
- transaction.name = route
20
- end
21
- end
19
+ def dispatch!(*args, &block)
20
+ dispatch_without_apm!(*args, &block).tap do
21
+ next unless (transaction = Atatus.current_transaction)
22
+ next unless (route = env['sinatra.route'])
22
23
 
23
- def compile_template(engine, data, opts, *args, &block)
24
- opts[:__atatus_template_name] =
25
- case data
26
- when Symbol then data.to_s
27
- else format('Inline %s', engine)
24
+ transaction.name = route
28
25
  end
26
+ end
29
27
 
30
- compile_template_without_apm(engine, data, opts, *args, &block)
28
+ def compile_template(engine, data, opts, *args, &block)
29
+ opts[:__atatus_template_name] =
30
+ case data
31
+ when Symbol then data.to_s
32
+ else format('Inline %s', engine)
33
+ end
34
+
35
+ compile_template_without_apm(engine, data, opts, *args, &block)
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -8,14 +8,16 @@ module Atatus
8
8
  TYPE = 'template.tilt'
9
9
 
10
10
  def install
11
- ::Tilt::Template.class_eval do
12
- alias render_without_apm render
11
+ if defined?(::Tilt) && defined?(::Tilt::Template)
12
+ ::Tilt::Template.class_eval do
13
+ alias render_without_apm render
13
14
 
14
- def render(*args, &block)
15
- name = options[:__atatus_template_name] || 'Unknown template'
15
+ def render(*args, &block)
16
+ name = options[:__atatus_template_name] || 'Unknown template'
16
17
 
17
- Atatus.with_span name, TYPE do
18
- render_without_apm(*args, &block)
18
+ Atatus.with_span name, TYPE do
19
+ render_without_apm(*args, &block)
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Atatus
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atatus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby