instana 0.10.1 → 0.11.0

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: 7e188f12fcff2a78ced457b2640b460b257e5684
4
- data.tar.gz: c149e734156bf8b02ffd757cc564618c83ba7153
3
+ metadata.gz: 45d083c0409f57536ece61d39aad0bc07234f48f
4
+ data.tar.gz: 55b44b71738b9821aa79538aa184129a7fc8da54
5
5
  SHA512:
6
- metadata.gz: 46e488894d84fa5b4afd32b486ae5c4af61ce30ceee001b6395f5c4dbb7fdfe68421093d765e59ecab0c647ef63992d0ebeb9c6abc1eed7af401cd69ad742cb1
7
- data.tar.gz: 26be2c7a4a825baa23897a143ddbaabf631a1797e43716066509f984f84aa0d9c85054f7a67e3f9b8d59e3c9054f952c1769fd2b73a6d880c50df204585f46f1
6
+ metadata.gz: ebcf2e4efb164d9abc59d82e750354d3feaebd57658eb6c32dfe184a25f9c3cc7a8c976da2263a0d645c3c0b75a58af4d3d8d996b19ef0bc611426f4329f7c37
7
+ data.tar.gz: c2c486f05c4c7ae075bde638f74089e594527063c11488f9ae4ac52ed3cff4d4f3e73bc71852c89f2a8d831415e88a8ec0d81b0c1aac7ea97f2c0846f2c1ddc2
data/Configuration.md ADDED
@@ -0,0 +1,53 @@
1
+ # Configuration
2
+
3
+ ## Logging
4
+
5
+ The Instana logger is a standard Ruby logger that logs debug, warn, info
6
+ (etc.) messages and can be set as follows:
7
+
8
+ ```Ruby
9
+ require "logger"
10
+ ::Instana.logger.level = ::Logger::WARN
11
+ ```
12
+
13
+ It also allows the debug level to be configured that affects
14
+ what extra debug info it reports. It allows for:
15
+
16
+ * `:agent` - shows all agent state related debug messages
17
+ * `:agent_comm` - outputs all request/response pairs to and from the
18
+ host agent
19
+
20
+ Log messages can be generated for these channels using:
21
+
22
+ ```Ruby
23
+ ::Instana.logger.agent("agent specific log msg")
24
+ ::Instana.logger.agent_comm("agent communication specific log msg")
25
+ ```
26
+
27
+ To set the debug log level:
28
+
29
+ ```Ruby
30
+ ::Instana.logger.debug_level = [:agent, :agent_comm]
31
+ # or
32
+ ::Instana.logger.debug_level = [:agent_comm]
33
+ # or
34
+ ::Instana.logger.debug_level = :agent
35
+ ```
36
+
37
+ or to reset it:
38
+
39
+ ```Ruby
40
+ ::Instana.logger.debug_level = nil
41
+ ```
42
+
43
+ Example output:
44
+ ```bash
45
+ [2] pry(main)> Instana.logger.debug_level = :agent_comm
46
+ => :agent_comm
47
+
48
+ D, [2016-12-01T11:45:12.876527 #74127] DEBUG -- : Instana: POST Req -> -body-: http://127.0.0.1:42699/com.instana.plugin.ruby.74127 ->
49
+ -{"gc":{"heap_live":171890,"heap_free":522},"memory":{"rss_size":51212.0}}- Resp -> body:#<Net::HTTPOK:0x007faee2161078> -> -[]-
50
+
51
+ [3] pry(main)> Instana.logger.debug_level = nil
52
+ => nil
53
+ ```
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :development, :test do
4
4
  gem 'rake'
5
- gem 'minitest'
5
+ gem 'minitest', '5.9.1'
6
6
  gem 'minitest-reporters'
7
7
  gem 'minitest-debugger', :require => false
8
8
  gem 'rack-test'
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <img src="https://www.instana.com/wp-content/uploads/2016/04/stan@2x.png" height="300px"/>
2
+ <img src="http://www.instana.com/wp-content/uploads/2016/11/Instana-Infrastructure-Map-1-1024x551.png"/>
3
3
  </div>
4
4
 
5
5
  # Instana
@@ -61,6 +61,25 @@ Thread.new do
61
61
  end
62
62
  ```
63
63
 
64
+ #### Caveat
65
+
66
+ In the case of forking webservers such as Unicorn or Puma in clustered mode, the agent detects the pid change and re-spawns the background thread. If you are managing the background thread yourself with the steps above _and_ you are using a forking webserver (or anything else that may fork the original process), you should also do the following.
67
+
68
+ When a fork is detected, the agent handles the re-initialization and then calls `::Agent.instana.spawn_background_thread`. This by default uses the standard `Thread.new`. If you wish to control this, you should override this method by re-defining that method. For example:
69
+
70
+ ```ruby
71
+ # This method can be overridden with the following:
72
+ #
73
+ module Instana
74
+ class Agent
75
+ def spawn_background_thread
76
+ # start/identify custom thread
77
+ ::Instana.agent.start
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
64
83
  ### Components
65
84
 
66
85
  Individual components can be disabled with a local config.
@@ -97,3 +116,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
97
116
 
98
117
  Bug reports and pull requests are welcome on GitHub at https://github.com/instana/ruby-sensor.
99
118
 
119
+ ## More
120
+
121
+ Want Chef change visibility for your deploys? Checkout [instana-chef](https://github.com/instana/instana-chef).
122
+
data/lib/instana/agent.rb CHANGED
@@ -94,7 +94,7 @@ module Instana
94
94
  # the host agent.
95
95
  #
96
96
  def after_fork
97
- ::Instana.logger.debug "after_fork hook called. Falling back to unannounced state and spawning a new background agent thread."
97
+ ::Instana.logger.agent "after_fork hook called. Falling back to unannounced state and spawning a new background agent thread."
98
98
 
99
99
  # Re-collect process information post fork
100
100
  @pid = Process.pid
@@ -137,7 +137,7 @@ module Instana
137
137
  # In case of failure, we try again in 30 seconds.
138
138
  @announce_timer = @timers.now_and_every(30) do
139
139
  if host_agent_ready? && announce_sensor
140
- ::Instana.logger.debug "Announce successful. Switching to metrics collection. pid: #{Process.pid}"
140
+ ::Instana.logger.debug "Announce successful. Switching to metrics collection."
141
141
  transition_to(:announced)
142
142
  end
143
143
  end
@@ -165,6 +165,7 @@ module Instana
165
165
  # called from an already initialized background thread.
166
166
  #
167
167
  def start
168
+ ::Instana.logger.warn "Host agent not available. Will retry periodically." unless host_agent_ready?
168
169
  loop do
169
170
  if @state == :unannounced
170
171
  @collect_timer.pause
@@ -176,7 +177,15 @@ module Instana
176
177
  @timers.wait
177
178
  end
178
179
  ensure
179
- Instana.logger.debug "Agent start method exiting. state: #{@state} pid: #{Process.pid}"
180
+ if @state == :announced
181
+ # Pause the timers so they don't fire while we are
182
+ # reporting traces
183
+ @collect_timer.pause
184
+ @announce_timer.pause
185
+
186
+ ::Instana.logger.debug "Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
187
+ ::Instana.processor.send
188
+ end
180
189
  end
181
190
 
182
191
  # Indicates if the agent is ready to send metrics
@@ -187,7 +196,7 @@ module Instana
187
196
  return true if ENV['INSTANA_GEM_TEST']
188
197
 
189
198
  if forked?
190
- ::Instana.logger.debug "Instana: detected fork. Calling after_fork"
199
+ ::Instana.logger.agent "Instana: detected fork. Calling after_fork"
191
200
  after_fork
192
201
  end
193
202
 
@@ -216,7 +225,7 @@ module Instana
216
225
  req = Net::HTTP::Put.new(uri)
217
226
  req.body = announce_payload.to_json
218
227
 
219
- # ::Instana.logger.debug "Announce: http://#{@host}:#{@port}/#{DISCOVERY_PATH} - payload: #{req.body}"
228
+ ::Instana.logger.agent "Announce: http://#{@host}:#{@port}/#{DISCOVERY_PATH} - payload: #{req.body}"
220
229
 
221
230
  response = make_host_agent_request(req)
222
231
 
@@ -263,8 +272,6 @@ module Instana
263
272
  if response
264
273
  last_entity_response = response.code.to_i
265
274
 
266
- #::Instana.logger.debug "entity http://#{@host}:#{@port}/#{path}: response=#{last_entity_response}: #{payload.to_json}"
267
-
268
275
  if last_entity_response == 200
269
276
  @entity_last_seen = Time.now
270
277
  @last_snapshot = Time.now if with_snapshot
@@ -296,8 +303,6 @@ module Instana
296
303
  if response
297
304
  last_trace_response = response.code.to_i
298
305
 
299
- #::Instana.logger.debug "traces response #{last_trace_response}: #{spans.to_json}"
300
-
301
306
  if [200, 204].include?(last_trace_response)
302
307
  return true
303
308
  end
@@ -354,6 +359,7 @@ module Instana
354
359
  # `:announced`, `:unannounced`
355
360
  #
356
361
  def transition_to(state)
362
+ ::Instana.logger.agent("Transitioning to #{state}")
357
363
  case state
358
364
  when :announced
359
365
  # announce successful; set state
@@ -391,6 +397,7 @@ module Instana
391
397
  Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
392
398
  response = http.request(req)
393
399
  end
400
+ ::Instana.logger.agent_comm "#{req.method} Req -> -body-: #{req.uri} -> -#{req.body}- Resp -> body:#{response} -> -#{response.body}-"
394
401
  response
395
402
  rescue Errno::ECONNREFUSED => e
396
403
  return nil
data/lib/instana/base.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'logger'
2
1
  require "instana/version"
2
+ require 'instana/logger'
3
3
  require "instana/util"
4
4
 
5
5
  module Instana
@@ -19,7 +19,7 @@ module Instana
19
19
  # to run" state.
20
20
  #
21
21
  def setup
22
- @logger = Logger.new(STDOUT)
22
+ @logger = ::Instana::XLogger.new(STDOUT)
23
23
  if ENV.key?('INSTANA_GEM_TEST') || ENV.key?('INSTANA_GEM_DEV')
24
24
  @logger.level = Logger::DEBUG
25
25
  else
@@ -0,0 +1,58 @@
1
+ require "logger"
2
+
3
+ module Instana
4
+ class XLogger < Logger
5
+ LEVELS = [:agent, :agent_comm].freeze
6
+ STAMP = "Instana: ".freeze
7
+
8
+ def initialize(*args)
9
+ if ENV['INSTANA_GEM_DEV']
10
+ self.debug_level=:agent
11
+ end
12
+ super(*args)
13
+ end
14
+
15
+ def debug_level=(levels)
16
+ LEVELS.each do |l|
17
+ instance_variable_set("@level_#{l}", false)
18
+ end
19
+
20
+ levels = [ levels ] unless levels.is_a?(Array)
21
+ levels.each do |l|
22
+ next unless LEVELS.include?(l)
23
+ instance_variable_set("@level_#{l}", true)
24
+ end
25
+ end
26
+
27
+ def agent(msg)
28
+ return unless @level_agent
29
+ self.debug(msg)
30
+ end
31
+
32
+ def agent_comm(msg)
33
+ return unless @level_agent_comm
34
+ self.debug(msg)
35
+ end
36
+
37
+ def error(msg)
38
+ super(STAMP + msg)
39
+ end
40
+
41
+ def warn(msg)
42
+ super(STAMP + msg)
43
+ end
44
+
45
+ def info(msg)
46
+ super(STAMP + msg)
47
+ end
48
+
49
+ def debug(msg)
50
+ super(STAMP + msg)
51
+ end
52
+
53
+ def unkown(msg)
54
+ super(STAMP + msg)
55
+ end
56
+ end
57
+ end
58
+
@@ -30,7 +30,7 @@ module Instana
30
30
  return if @queue.empty?
31
31
 
32
32
  size = @queue.size
33
- if size > 10
33
+ if size > 100
34
34
  Instana.logger.debug "Trace queue is #{size}"
35
35
  end
36
36
 
@@ -1,3 +1,3 @@
1
1
  module Instana
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".travis.yml"
120
+ - Configuration.md
120
121
  - Gemfile
121
122
  - README.md
122
123
  - Rakefile
@@ -136,6 +137,7 @@ files:
136
137
  - lib/instana/instrumentation.rb
137
138
  - lib/instana/instrumentation/net-http.rb
138
139
  - lib/instana/instrumentation/rack.rb
140
+ - lib/instana/logger.rb
139
141
  - lib/instana/rack.rb
140
142
  - lib/instana/setup.rb
141
143
  - lib/instana/thread_local.rb