instana 2.6.1 → 2.7.0

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: f8cd4b0e98fe6e6e7314e25e8632fd6cf148727a9fc5b411006cab2b990b037f
4
- data.tar.gz: d13279637479775cc232484244f7925185e6dc9b4d52e7f0958e5a28fb463917
3
+ metadata.gz: f74b1ab7c25266cacf29645d4c956432ded64f2eb127a0bf712d1d5e7a659ad3
4
+ data.tar.gz: 0d1747acb3f742d8e8a103a154f14a0470d908837d2c286dbbc5a096afe3e59b
5
5
  SHA512:
6
- metadata.gz: 5610b490b1f2b4499eb78b94dbf02e2bae0247ae7efeb17207a97f68f82352d320d016e8753df3ea8f3a09c70e8eac6725c9b981eab658877f1ddee6d666a550
7
- data.tar.gz: 9d5f1f0511c4ee11fe3e32c35f70caa51b0c29aefa8dd5f0149ea305dc0d5df15d57e60db80a3f90f7951a38cdae292dbebf9e16225c408c87841274197a6b27
6
+ metadata.gz: 507b17514d60c8363a510c7867fbbc4b7fd7e21ebb13310e64f6fb73af21068b11de601974240ede3e489e5165bc38def5558b0218b10cc8b9c6f10b20849c23
7
+ data.tar.gz: bc50d01dfbd66fb31a6b2958d7185047869ccb03e2f70e246254f054cf56d9f093eff00ac3db3ccf8c785e0fd701d404f261e1d2a3447ecbf28c0b340995af17
@@ -11,7 +11,7 @@ module Instana
11
11
  TRACES_DATA_URL = "/com.instana.plugin.ruby/traces.%i".freeze
12
12
  TRACE_METRICS_URL = "/tracermetrics".freeze
13
13
 
14
- attr_reader :report_timer
14
+ attr_reader :metrics_timer, :traces_timer
15
15
 
16
16
  # @param [RequestClient] client used to make requests to the backend
17
17
  # @param [Concurrent::Atom] discovery object used to store discovery response in
@@ -19,22 +19,51 @@ module Instana
19
19
  @client = client
20
20
  @discovery = discovery
21
21
  @logger = logger
22
- @report_timer = timer_class.new(execution_interval: 1, run_now: true) { report_to_backend }
22
+ @timer_class = timer_class
23
23
  @nonce = Time.now
24
24
  @processor = processor
25
+
26
+ # Initialize timers with default 1 second interval
27
+ @metrics_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_metrics_to_backend }
28
+ @traces_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_traces_to_backend }
25
29
  end
26
30
 
27
31
  def update(time, _old_version, new_version)
28
32
  return unless time > @nonce
29
33
 
30
34
  @nonce = time
31
- new_version.nil? ? @report_timer.shutdown : @report_timer.execute
35
+
36
+ if new_version.nil?
37
+ @metrics_timer&.shutdown
38
+ @traces_timer&.shutdown
39
+ else
40
+ # Read poll_rate from discovery payload - it's nested under plugin.ruby.poll_rate
41
+ discovery = @discovery.value
42
+ poll_rate = discovery&.dig('plugin', 'ruby', 'poll_rate') || 1
43
+
44
+ # Only recreate metrics_timer if poll_rate is different from current interval
45
+ if @metrics_timer.nil? || @metrics_timer.execution_interval != poll_rate
46
+ @metrics_timer&.shutdown
47
+ @metrics_timer = @timer_class.new(execution_interval: poll_rate, run_now: true) { report_metrics_to_backend }
48
+ end
49
+ @metrics_timer.execute
50
+
51
+ # Traces timer always uses 1 second interval
52
+ @traces_timer&.shutdown
53
+ @traces_timer = @timer_class.new(execution_interval: 1, run_now: true) { report_traces_to_backend }
54
+ @traces_timer.execute
55
+ end
32
56
  end
33
57
 
34
58
  private
35
59
 
36
- def report_to_backend
60
+ def report_metrics_to_backend
37
61
  report_metrics if ::Instana.config[:metrics][:enabled]
62
+ rescue StandardError => e
63
+ @logger.error(%(#{e}\n#{e.backtrace.join("\n")}))
64
+ end
65
+
66
+ def report_traces_to_backend
38
67
  report_traces if ::Instana.config[:tracing][:enabled]
39
68
  report_trace_stats if ::Instana.config[:tracing][:enabled]
40
69
  rescue StandardError => e
@@ -38,7 +38,10 @@ module Instana
38
38
  timeout = Integer(ENV.fetch('INSTANA_TIMEOUT', 500))
39
39
  @host = host
40
40
  @port = port
41
- @client = Net::HTTP.start(host, port, use_ssl: use_ssl, read_timeout: timeout)
41
+ @use_ssl = use_ssl
42
+ @timeout = timeout
43
+ @client_mutex = Mutex.new
44
+ @client = nil
42
45
  end
43
46
 
44
47
  # Send a request to the backend. If data is a {Hash},
@@ -60,7 +63,10 @@ module Instana
60
63
  data
61
64
  end
62
65
  begin
63
- response = @client.send_request(method, path, body, headers)
66
+ response = @client_mutex.synchronize do
67
+ ensure_connection
68
+ @client.send_request(method, path, body, headers)
69
+ end
64
70
  Response.new(response)
65
71
  rescue Errno::ECONNREFUSED => e
66
72
  Instana.logger.debug("Connection refused to #{@host}:#{@port} - #{e.message}")
@@ -74,6 +80,11 @@ module Instana
74
80
  rescue SocketError => e
75
81
  Instana.logger.debug("Socket error connecting to #{@host}:#{@port} - #{e.message}")
76
82
  create_error_response('502', 'Socket Error', 'Socket error', e.message)
83
+ rescue IOError => e
84
+ Instana.logger.debug("IO error sending request to #{@host}:#{@port} - #{e.message}")
85
+ # Reset connection on IO errors and retry once
86
+ @client_mutex.synchronize { reset_connection }
87
+ create_error_response('500', 'IO Error', 'IOError', e.message)
77
88
  rescue StandardError => e
78
89
  Instana.logger.debug("Error sending request to #{@host}:#{@port} - #{e.class}: #{e.message}")
79
90
  create_error_response('500', 'Internal Error', e.class.to_s, e.message)
@@ -82,6 +93,22 @@ module Instana
82
93
 
83
94
  private
84
95
 
96
+ def ensure_connection
97
+ return if @client && !@client.instance_variable_get(:@socket).nil?
98
+
99
+ reset_connection
100
+ @client = Net::HTTP.start(@host, @port, use_ssl: @use_ssl, read_timeout: @timeout)
101
+ end
102
+
103
+ def reset_connection
104
+ begin
105
+ @client&.finish
106
+ rescue
107
+ nil
108
+ end
109
+ @client = nil
110
+ end
111
+
85
112
  def encode_body(data)
86
113
  # :nocov:
87
114
  INSTANA_USE_OJ ? Oj.dump(data, mode: :strict) : JSON.dump(data)
data/lib/instana/util.rb CHANGED
@@ -27,25 +27,25 @@ module Instana
27
27
  def take_snapshot
28
28
  data = {}
29
29
 
30
- data[:sensorVersion] = ::Instana::VERSION
31
- data[:ruby_version] = RUBY_VERSION
30
+ data[:sensorVersion] = ::Instana::VERSION.dup
31
+ data[:ruby_version] = RUBY_VERSION.dup
32
32
  data[:rpl] = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
33
33
 
34
34
  # Framework Detection
35
35
  if defined?(::RailsLts::VERSION)
36
- data[:framework] = "Rails on Rails LTS-#{::RailsLts::VERSION}"
36
+ data[:framework] = "Rails on Rails LTS-#{::RailsLts::VERSION}".dup
37
37
 
38
38
  elsif defined?(::Rails.version)
39
- data[:framework] = "Ruby on Rails #{::Rails.version}"
39
+ data[:framework] = "Ruby on Rails #{::Rails.version}".dup
40
40
 
41
41
  elsif defined?(::Grape::VERSION)
42
- data[:framework] = "Grape #{::Grape::VERSION}"
42
+ data[:framework] = "Grape #{::Grape::VERSION}".dup
43
43
 
44
44
  elsif defined?(::Padrino::VERSION)
45
- data[:framework] = "Padrino #{::Padrino::VERSION}"
45
+ data[:framework] = "Padrino #{::Padrino::VERSION}".dup
46
46
 
47
47
  elsif defined?(::Sinatra::VERSION)
48
- data[:framework] = "Sinatra #{::Sinatra::VERSION}"
48
+ data[:framework] = "Sinatra #{::Sinatra::VERSION}".dup
49
49
  end
50
50
 
51
51
  # Report Bundle
@@ -53,7 +53,7 @@ module Instana
53
53
  data[:versions] = {}
54
54
 
55
55
  Gem.loaded_specs.each do |k, v|
56
- data[:versions][k] = v.version.to_s
56
+ data[:versions][k.dup] = v.version.to_s.dup
57
57
  end
58
58
  end
59
59
 
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "2.6.1"
5
+ VERSION = "2.7.0"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instana
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
@@ -362,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
362
  - !ruby/object:Gem::Version
363
363
  version: '0'
364
364
  requirements: []
365
- rubygems_version: 4.0.10
365
+ rubygems_version: 4.0.11
366
366
  specification_version: 4
367
367
  summary: Ruby Distributed Tracing & Metrics Sensor for Instana
368
368
  test_files: []