instana 1.7.4 → 1.7.5

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: 13bb5e402c5c26c740336cf7e2d8befcad0e51a3
4
- data.tar.gz: bc4f70fd52e2b10f9201fb8b8d76a6f50810de68
3
+ metadata.gz: 968b0d69a6812e078d8e16552798b28005fc9cf1
4
+ data.tar.gz: 23b3315b9dce25b258156e85e3eebbc221b81396
5
5
  SHA512:
6
- metadata.gz: 3a6aae1e10996b86988aa78c742cfd301b57d7afca23ef8d0361b2d6312b858517b7756d1254ff4f3e3ac6f308c3f4f8d2c7bd3c79257fe5d63d7e6985bb39fc
7
- data.tar.gz: bf262a7804ab27694c86996be1c48b413775a4c9b18211d0930ed1fd968eab9cd35be2f91ee61b8e1b40acc075714a2d6af8c51a70541ec0ed4ed15fea480945
6
+ metadata.gz: f99acdde5c0fe11ca3ef729c82f43b4f8e28647a67c7f92f3f6ff04ab3c1e3967e7a89ee0466c6fd7d57ef6bc8b18fee4706690bb69c12e33e55a84d08826afb
7
+ data.tar.gz: d48ea584fd211c9a3533654155610c2ac776ca5a852ac69b34781bca374837f28203ec66d8b17f4a20793eb91a29086e90e6acefdb60ea473edac7839bd07bc3
data/Gemfile CHANGED
@@ -21,6 +21,7 @@ end
21
21
  group :development do
22
22
  gem 'ruby-debug', :platforms => [:mri_18, :jruby]
23
23
  gem 'debugger', :platform => :mri_19
24
+ gem 'stackprof'
24
25
 
25
26
  if RUBY_VERSION > '1.8.7'
26
27
  gem 'pry'
@@ -0,0 +1,80 @@
1
+ require "bundler"
2
+
3
+ require 'rack'
4
+ require 'rack/builder'
5
+ require 'rack/handler/puma'
6
+ require 'net/http'
7
+ require "benchmark"
8
+ require "cgi"
9
+ Bundler.require(:default)
10
+ require "instana/rack"
11
+
12
+ Thread.new do
13
+ app = Rack::Builder.new {
14
+ map "/" do
15
+ run Proc.new { |env|
16
+ [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
17
+ }
18
+ end
19
+ map "/error" do
20
+ run Proc.new { |env|
21
+ [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
22
+ }
23
+ end
24
+ }
25
+
26
+ Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7011})
27
+ end
28
+
29
+ Thread.new do
30
+ app = Rack::Builder.new {
31
+ use ::Instana::Rack
32
+ map "/" do
33
+ run Proc.new { |env|
34
+ [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
35
+ }
36
+ end
37
+ map "/error" do
38
+ run Proc.new { |env|
39
+ [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
40
+ }
41
+ end
42
+ }
43
+
44
+ Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7012})
45
+ end
46
+
47
+ sleep(2)
48
+ puts "Rack server started in background thread on localhost:7011"
49
+ puts "Sleeping for 10 to allow announce"
50
+ sleep(10)
51
+
52
+
53
+ puts "Starting benchmarks"
54
+ Benchmark.bm do |x|
55
+
56
+ uri = URI.parse("http://127.0.0.1:7011/")
57
+ ::Net::HTTP.start(uri.host, uri.port) do |hc|
58
+ x.report("vanilla") {
59
+ 1_000.times {
60
+ req = Net::HTTP::Get.new(uri.request_uri)
61
+ hc.request(req)
62
+ }
63
+ }
64
+ end
65
+
66
+ uri = URI.parse("http://127.0.0.1:7012/")
67
+ ::Net::HTTP.start(uri.host, uri.port) do |hc|
68
+ x.report("traced ") {
69
+ 1_000.times {
70
+ ::Instana.tracer.start_or_continue_trace(:rack_call) do
71
+ req = Net::HTTP::Get.new(uri.request_uri)
72
+ hc.request(req)
73
+ end
74
+ }
75
+ }
76
+ end
77
+ end
78
+
79
+
80
+ sleep 10
@@ -0,0 +1,77 @@
1
+ require "bundler"
2
+ require "stackprof"
3
+ require 'rack'
4
+ require 'rack/builder'
5
+ require 'rack/handler/puma'
6
+ require 'net/http'
7
+ require "benchmark"
8
+ require "cgi"
9
+ Bundler.require(:default)
10
+ require "instana/rack"
11
+
12
+ Thread.new do
13
+ app = Rack::Builder.new {
14
+ map "/" do
15
+ run Proc.new { |env|
16
+ [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
17
+ }
18
+ end
19
+ map "/error" do
20
+ run Proc.new { |env|
21
+ [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
22
+ }
23
+ end
24
+ }
25
+
26
+ Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7011})
27
+ end
28
+
29
+ Thread.new do
30
+ app = Rack::Builder.new {
31
+ use ::Instana::Rack
32
+ map "/" do
33
+ run Proc.new { |env|
34
+ [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
35
+ }
36
+ end
37
+ map "/error" do
38
+ run Proc.new { |env|
39
+ [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
40
+ }
41
+ end
42
+ }
43
+
44
+ Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7012})
45
+ end
46
+
47
+ sleep(2)
48
+ puts "Rack server started in background thread on localhost:7011"
49
+ puts "Sleeping for 10 to allow announce"
50
+ sleep(10)
51
+
52
+ puts "Starting profile"
53
+ uri = URI.parse("http://127.0.0.1:7011/")
54
+ StackProf.run(mode: :wall, out: 'tmp/stackprof-rack-vanilla.dump') do
55
+ ::Net::HTTP.start(uri.host, uri.port) do |hc|
56
+ 5_000.times {
57
+ ::Instana.tracer.start_or_continue_trace(:rack_call) do
58
+ req = Net::HTTP::Get.new(uri.request_uri)
59
+ hc.request(req)
60
+ end
61
+ }
62
+ end
63
+ end
64
+ puts "stackprof tmp/stackprof-rack-vanilla.dump --text"
65
+
66
+ uri = URI.parse("http://127.0.0.1:7012/")
67
+ StackProf.run(mode: :wall, out: 'tmp/stackprof-rack-instrumented.dump') do
68
+ ::Net::HTTP.start(uri.host, uri.port) do |hc|
69
+ 5_000.times {
70
+ ::Instana.tracer.start_or_continue_trace(:rack_call) do
71
+ req = Net::HTTP::Get.new(uri.request_uri)
72
+ hc.request(req)
73
+ end
74
+ }
75
+ end
76
+ end
77
+ puts "stackprof tmp/stackprof-rack-instrumented.dump --text"
data/lib/instana/agent.rb CHANGED
@@ -162,6 +162,9 @@ module Instana
162
162
  end
163
163
  @timers.wait
164
164
  end
165
+ rescue Exception => e
166
+ ::Instana.logger.warn "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
167
+ ::Instana.logger.debug e.backtrace.join("\r\n")
165
168
  ensure
166
169
  if @state == :announced
167
170
  # Pause the timers so they don't fire while we are
@@ -169,7 +172,7 @@ module Instana
169
172
  @collect_timer.pause
170
173
  @announce_timer.pause
171
174
 
172
- ::Instana.logger.debug "Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
175
+ ::Instana.logger.debug "#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
173
176
  ::Instana.processor.send
174
177
  end
175
178
  end
@@ -31,7 +31,12 @@ module Instana
31
31
  @config[:eum_api_key] = nil
32
32
  @config[:eum_baggage] = {}
33
33
 
34
- # Instrumentation
34
+ # In Ruby, backtrace collection is very expensive so it's
35
+ # (unfortunately) disabled by default. If you still want
36
+ # backtraces, it can be enabled with this config option.
37
+ # ::Instana.config[:collect_backtraces] = true
38
+ @config[:collect_backtraces] = false
39
+
35
40
  @config[:action_controller] = { :enabled => true }
36
41
  @config[:action_view] = { :enabled => true }
37
42
  @config[:active_record] = { :enabled => true }
@@ -35,9 +35,9 @@ if defined?(::Net::HTTP) && ::Instana.config[:nethttp][:enabled]
35
35
  # The core call
36
36
  response = request_without_instana(*args, &block)
37
37
 
38
- # Pickup response headers; convert back to base 10 integer
38
+ # Debug only check: Pickup response headers; convert back to base 10 integer and validate
39
39
  if ::Instana.debug? && response.key?('X-Instana-T')
40
- if ::Instana.tracer.trace_id != ::Instana.tracer.header_to_id(response.header['X-Instana-T'])
40
+ if ::Instana.tracer.trace_id != ::Instana::Util.header_to_id(response.header['X-Instana-T'])
41
41
  ::Instana.logger.debug "#{Thread.current}: Trace ID mismatch on net/http response! ours: #{::Instana.tracer.trace_id} theirs: #{their_trace_id}"
42
42
  end
43
43
  end
@@ -18,6 +18,10 @@ module Instana
18
18
  # No access to the @staging_queue until this lock
19
19
  # is taken.
20
20
  @staging_lock = Mutex.new
21
+
22
+ # This is the maximum number of spans we send to the host
23
+ # agent at once.
24
+ @batch_size = 3000
21
25
  end
22
26
 
23
27
  # Adds a trace to the queue to be processed and
@@ -91,7 +95,12 @@ module Instana
91
95
  # Retrieve all spans for queued traces
92
96
  spans = queued_spans
93
97
 
94
- ::Instana.agent.report_spans(spans)
98
+ # Report spans in batches
99
+ batch = spans.shift(@batch_size)
100
+ while !batch.empty? do
101
+ ::Instana.agent.report_spans(batch)
102
+ batch = spans.shift(@batch_size)
103
+ end
95
104
  end
96
105
 
97
106
  # Retrieves all of the traces in @queue and returns
@@ -30,11 +30,13 @@ module Instana
30
30
 
31
31
  @baggage = {}
32
32
 
33
- # For entry spans, add a backtrace fingerprint
34
- add_stack(limit: 2) if ENTRY_SPANS.include?(name)
33
+ if ::Instana.config[:collect_backtraces]
34
+ # For entry spans, add a backtrace fingerprint
35
+ add_stack(limit: 2) if ENTRY_SPANS.include?(name)
35
36
 
36
- # Attach a backtrace to all exit spans
37
- add_stack if EXIT_SPANS.include?(name)
37
+ # Attach a backtrace to all exit spans
38
+ add_stack if EXIT_SPANS.include?(name)
39
+ end
38
40
 
39
41
  # Check for custom tracing
40
42
  if REGISTERED_SPANS.include?(name.to_sym)
@@ -1,4 +1,4 @@
1
1
  module Instana
2
- VERSION = "1.7.4"
2
+ VERSION = "1.7.5"
3
3
  VERSION_FULL = "instana-#{VERSION}"
4
4
  end
@@ -47,8 +47,8 @@ class ExconTest < Minitest::Test
47
47
  assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
48
48
  assert_equal 200, second_span[:data][:http][:status]
49
49
 
50
- # excon backtrace included check
51
- assert second_span.key?(:stack)
50
+ # excon backtrace not included by default check
51
+ assert !second_span.key?(:stack)
52
52
 
53
53
  # Rack server trace validation
54
54
  assert_equal 1, rs_trace.spans.count
@@ -101,7 +101,7 @@ class ExconTest < Minitest::Test
101
101
  assert_equal "http://127.0.0.1:6500/", second_span[:data][:http][:url]
102
102
  assert_equal nil, second_span[:data][:http][:status]
103
103
 
104
- # excon backtrace included check
104
+ # excon span should include an error backtrace
105
105
  assert second_span.key?(:stack)
106
106
 
107
107
  # error validation
@@ -154,18 +154,18 @@ class ExconTest < Minitest::Test
154
154
  refute_nil second_span[:data].key?(:http)
155
155
  assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
156
156
  assert_equal 200, second_span[:data][:http][:status]
157
- assert second_span.key?(:stack)
157
+ assert !second_span.key?(:stack)
158
158
 
159
159
  refute_nil third_span.key?(:data)
160
160
  refute_nil third_span[:data].key?(:http)
161
161
  assert_equal "http://127.0.0.1:6511/", third_span[:data][:http][:url]
162
162
  assert_equal 200, third_span[:data][:http][:status]
163
- assert third_span.key?(:stack)
163
+ assert !third_span.key?(:stack)
164
164
 
165
165
  refute_nil fourth_span.key?(:data)
166
166
  refute_nil fourth_span[:data].key?(:http)
167
167
  assert_equal "http://127.0.0.1:6511/", fourth_span[:data][:http][:url]
168
168
  assert_equal 200, fourth_span[:data][:http][:status]
169
- assert fourth_span.key?(:stack)
169
+ assert !fourth_span.key?(:stack)
170
170
  end
171
171
  end
@@ -46,7 +46,7 @@ class NetHTTPTest < Minitest::Test
46
46
  refute_nil second_span[:data].key?(:http)
47
47
  assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
48
48
  assert_equal "200", second_span[:data][:http][:status]
49
- assert second_span.key?(:stack)
49
+ assert !second_span.key?(:stack)
50
50
 
51
51
  # Rack server trace validation
52
52
  assert_equal 1, rs_trace.spans.count
@@ -94,7 +94,7 @@ class NetHTTPTest < Minitest::Test
94
94
  refute_nil second_span[:data].key?(:http)
95
95
  assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
96
96
  assert_equal "200", second_span[:data][:http][:status]
97
- assert second_span.key?(:stack)
97
+ assert !second_span.key?(:stack)
98
98
 
99
99
  # Rack server trace validation
100
100
  assert_equal 1, rs_trace.spans.count
@@ -161,7 +161,7 @@ class NetHTTPTest < Minitest::Test
161
161
  assert_equal "http://127.0.0.1:6511/error", http_span[:data][:http][:url]
162
162
  assert_equal "500", http_span[:data][:http][:status]
163
163
  assert_equal :'net-http', http_span.name
164
- assert http_span.key?(:stack)
164
+ assert !http_span.key?(:stack)
165
165
 
166
166
  WebMock.disable_net_connect!
167
167
  end
@@ -34,17 +34,34 @@ class TraceTest < Minitest::Test
34
34
  end
35
35
  end
36
36
 
37
- def test_entry_span_has_stack_with_limit
37
+ def test_entry_span_doesnt_have_stack_by_default
38
+ t = ::Instana::Trace.new(:rack)
39
+ first_span = t.spans.first
40
+ assert !first_span.key?(:stack)
41
+ end
42
+
43
+ def test_entry_span_has_stack_by_config
44
+ ::Instana.config[:collect_backtraces] = true
38
45
  t = ::Instana::Trace.new(:rack)
39
46
  first_span = t.spans.first
40
47
  assert first_span.key?(:stack)
41
48
  assert_equal 2, first_span[:stack].count
49
+ ::Instana.config[:collect_backtraces] = false
50
+ end
51
+
52
+ def test_exit_span_doesnt_have_stack_by_default
53
+ t = ::Instana::Trace.new(:trace_test)
54
+ t.new_span(:excon)
55
+ second_span = t.spans.to_a[1]
56
+ assert !second_span.key?(:stack)
42
57
  end
43
58
 
44
- def test_exit_span_has_stack
59
+ def test_exit_span_has_stack_by_config
60
+ ::Instana.config[:collect_backtraces] = true
45
61
  t = ::Instana::Trace.new(:trace_test)
46
62
  t.new_span(:excon)
47
63
  second_span = t.spans.to_a[1]
48
64
  assert second_span.key?(:stack)
65
+ ::Instana.config[:collect_backtraces] = false
49
66
  end
50
67
  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: 1.7.4
4
+ version: 1.7.5
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: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -173,6 +173,8 @@ files:
173
173
  - benchmarks/Gemfile.lock
174
174
  - benchmarks/id_generation.rb
175
175
  - benchmarks/opentracing.rb
176
+ - benchmarks/rack_vanilla_vs_traced.rb
177
+ - benchmarks/stackprof_rack_tracing.rb
176
178
  - benchmarks/time_processing.rb
177
179
  - bin/console
178
180
  - bin/setup
@@ -292,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
294
  version: '0'
293
295
  requirements: []
294
296
  rubyforge_project:
295
- rubygems_version: 2.6.12
297
+ rubygems_version: 2.6.11
296
298
  signing_key:
297
299
  specification_version: 4
298
300
  summary: Ruby sensor for Instana