instana 1.193.6 → 1.195.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +16 -2
  3. data/Appraisals +13 -1
  4. data/docker-compose.yml +20 -0
  5. data/gemfiles/aws_30.gemfile +3 -0
  6. data/gemfiles/excon_021.gemfile +18 -0
  7. data/gemfiles/excon_079.gemfile +18 -0
  8. data/gemfiles/shoryuken_50.gemfile +19 -0
  9. data/lib/instana/activators/aws_sdk_s3.rb +20 -0
  10. data/lib/instana/activators/aws_sdk_sns.rb +20 -0
  11. data/lib/instana/activators/aws_sdk_sqs.rb +20 -0
  12. data/lib/instana/activators/excon.rb +1 -1
  13. data/lib/instana/activators/shoryuken.rb +24 -0
  14. data/lib/instana/config.rb +3 -0
  15. data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +21 -2
  16. data/lib/instana/instrumentation/aws_sdk_s3.rb +55 -0
  17. data/lib/instana/instrumentation/aws_sdk_sns.rb +29 -0
  18. data/lib/instana/instrumentation/aws_sdk_sqs.rb +98 -0
  19. data/lib/instana/instrumentation/excon.rb +17 -4
  20. data/lib/instana/instrumentation/instrumented_request.rb +64 -7
  21. data/lib/instana/instrumentation/net-http.rb +9 -2
  22. data/lib/instana/instrumentation/rack.rb +35 -15
  23. data/lib/instana/instrumentation/shoryuken.rb +44 -0
  24. data/lib/instana/secrets.rb +2 -2
  25. data/lib/instana/tracer.rb +14 -11
  26. data/lib/instana/tracing/span.rb +3 -3
  27. data/lib/instana/tracing/span_context.rb +25 -1
  28. data/lib/instana/version.rb +1 -1
  29. data/test/instrumentation/aws_test.rb +130 -2
  30. data/test/instrumentation/excon_test.rb +16 -1
  31. data/test/instrumentation/net_http_test.rb +18 -0
  32. data/test/instrumentation/rack_instrumented_request_test.rb +50 -3
  33. data/test/instrumentation/rack_test.rb +141 -0
  34. data/test/instrumentation/shoryuken_test.rb +47 -0
  35. data/test/tracing/opentracing_test.rb +3 -3
  36. metadata +16 -3
  37. data/Dockerfile +0 -16
@@ -4,6 +4,10 @@
4
4
  require 'test_helper'
5
5
 
6
6
  class AwsTest < Minitest::Test
7
+ def setup
8
+ clear_all!
9
+ end
10
+
7
11
  def test_dynamo_db
8
12
  dynamo = Aws::DynamoDB::Client.new(
9
13
  region: "local",
@@ -27,7 +31,131 @@ class AwsTest < Minitest::Test
27
31
  assert rest.empty?
28
32
  assert_equal entry_span[:s], dynamo_span[:p]
29
33
  assert_equal :dynamodb, dynamo_span[:n]
30
- assert_equal :get_item, dynamo_span[:data][:op]
31
- assert_equal 'sample_table', dynamo_span[:data][:table]
34
+ assert_equal 'get', dynamo_span[:data][:dynamodb][:op]
35
+ assert_equal 'sample_table', dynamo_span[:data][:dynamodb][:table]
36
+ end
37
+
38
+ def test_s3
39
+ dynamo = Aws::S3::Client.new(
40
+ region: "local",
41
+ access_key_id: "minioadmin",
42
+ secret_access_key: "minioadmin",
43
+ endpoint: "http://localhost:9000"
44
+ )
45
+
46
+ assert_raises Aws::S3::Errors::NoSuchBucket do
47
+ Instana::Tracer.start_or_continue_trace(:s3_test, {}) do
48
+ dynamo.get_object(
49
+ bucket: 'sample_bucket',
50
+ key: 'sample_key'
51
+ )
52
+ end
53
+ end
54
+
55
+ spans = ::Instana.processor.queued_spans
56
+ s3_span, entry_span, *rest = spans
57
+
58
+ assert rest.empty?
59
+ assert_equal entry_span[:s], s3_span[:p]
60
+ assert_equal :s3, s3_span[:n]
61
+ assert_equal 'get', s3_span[:data][:s3][:op]
62
+ assert_equal 'sample_bucket', s3_span[:data][:s3][:bucket]
63
+ assert_equal 'sample_key', s3_span[:data][:s3][:key]
64
+ end
65
+
66
+ def test_sns_publish
67
+ sns = Aws::SNS::Client.new(
68
+ region: "local",
69
+ access_key_id: "test",
70
+ secret_access_key: "test",
71
+ endpoint: "http://localhost:9911"
72
+ )
73
+
74
+ assert_raises Aws::SNS::Errors::NotFound do
75
+ Instana::Tracer.start_or_continue_trace(:sns_test, {}) do
76
+ sns.publish(
77
+ topic_arn: 'topic:arn',
78
+ target_arn: 'target:arn',
79
+ phone_number: '555-0100',
80
+ subject: 'Test Subject',
81
+ message: 'Test Message'
82
+ )
83
+ end
84
+ end
85
+
86
+ spans = ::Instana.processor.queued_spans
87
+ aws_span, entry_span, *rest = spans
88
+
89
+ assert rest.empty?
90
+ assert_equal entry_span[:s], aws_span[:p]
91
+ assert_equal :sns, aws_span[:n]
92
+ assert_equal 'topic:arn', aws_span[:data][:sns][:topic]
93
+ assert_equal 'target:arn', aws_span[:data][:sns][:target]
94
+ assert_equal '555-0100', aws_span[:data][:sns][:phone]
95
+ assert_equal 'Test Subject', aws_span[:data][:sns][:subject]
96
+ end
97
+
98
+ def test_sns_other
99
+ sns = Aws::SNS::Client.new(
100
+ region: "local",
101
+ access_key_id: "test",
102
+ secret_access_key: "test",
103
+ endpoint: "http://localhost:9911"
104
+ )
105
+
106
+ Instana::Tracer.start_or_continue_trace(:sns_test, {}) do
107
+ sns.list_subscriptions
108
+ end
109
+
110
+ spans = ::Instana.processor.queued_spans
111
+ aws_span, entry_span, *rest = spans
112
+
113
+ assert rest.empty?
114
+ assert_equal entry_span[:s], aws_span[:p]
115
+ assert_equal :"net-http", aws_span[:n]
116
+ end
117
+
118
+ def test_sqs
119
+ sqs = Aws::SQS::Client.new(
120
+ region: "local",
121
+ access_key_id: "test",
122
+ secret_access_key: "test",
123
+ endpoint: "http://localhost:9324"
124
+ )
125
+
126
+ create_response = nil
127
+ get_url_response = nil
128
+
129
+ Instana::Tracer.start_or_continue_trace(:sqs_test, {}) do
130
+ create_response = sqs.create_queue(queue_name: 'test')
131
+ get_url_response = sqs.get_queue_url(queue_name: 'test')
132
+ sqs.send_message(queue_url: create_response.queue_url, message_body: 'Sample')
133
+ end
134
+
135
+ received = sqs.receive_message(
136
+ queue_url: create_response.queue_url,
137
+ message_attribute_names: ['All']
138
+ )
139
+ sqs.delete_queue(queue_url: create_response.queue_url)
140
+ message = received.messages.first
141
+ create_span, get_span, send_span, _root = ::Instana.processor.queued_spans
142
+
143
+ assert_equal :sqs, create_span[:n]
144
+ assert_equal create_response.queue_url, create_span[:data][:sqs][:queue]
145
+ assert_equal 'exit', create_span[:data][:sqs][:sort]
146
+ assert_equal 'create.queue', create_span[:data][:sqs][:type]
147
+
148
+ assert_equal :sqs, get_span[:n]
149
+ assert_equal get_url_response.queue_url, get_span[:data][:sqs][:queue]
150
+ assert_equal 'exit', get_span[:data][:sqs][:sort]
151
+ assert_equal 'get.queue', get_span[:data][:sqs][:type]
152
+
153
+ assert_equal :sqs, send_span[:n]
154
+ assert_equal get_url_response.queue_url, send_span[:data][:sqs][:queue]
155
+ assert_equal 'exit', send_span[:data][:sqs][:sort]
156
+ assert_equal 'single.sync', send_span[:data][:sqs][:type]
157
+ assert_equal send_span[:t], message.message_attributes['X_INSTANA_T'].string_value
158
+ assert_equal send_span[:s], message.message_attributes['X_INSTANA_S'].string_value
159
+ assert_equal 'Sample', message.body
32
160
  end
33
161
  end
@@ -22,7 +22,7 @@ class ExconTest < Minitest::Test
22
22
  url = "http://127.0.0.1:6511"
23
23
 
24
24
  connection = Excon.new(url)
25
- Instana.tracer.start_or_continue_trace('excon-test') do
25
+ Instana.tracer.start_or_continue_trace(:'excon-test') do
26
26
  connection.get(:path => '/?basic_get')
27
27
  end
28
28
 
@@ -40,6 +40,7 @@ class ExconTest < Minitest::Test
40
40
  refute_nil excon_span[:data].key?(:http)
41
41
  assert_equal "http://127.0.0.1:6511/", excon_span[:data][:http][:url]
42
42
  assert_equal 200, excon_span[:data][:http][:status]
43
+ assert_equal 'basic_get', excon_span[:data][:http][:params]
43
44
 
44
45
  # excon backtrace not included by default check
45
46
  assert !excon_span.key?(:stack)
@@ -146,4 +147,18 @@ class ExconTest < Minitest::Test
146
147
  assert_equal :sdk, grandparent_span[:n]
147
148
  end
148
149
  end
150
+
151
+ def test_basic_get_no_tracing
152
+ clear_all!
153
+
154
+ # A slight hack but webmock chokes with pipelined requests.
155
+ # Delete their excon middleware
156
+ Excon.defaults[:middlewares].delete ::WebMock::HttpLibAdapters::ExconAdapter
157
+ Excon.defaults[:middlewares].delete ::Excon::Middleware::Mock
158
+
159
+ url = "http://127.0.0.1:6511"
160
+
161
+ connection = Excon.new(url)
162
+ connection.get(:path => '/?basic_get')
163
+ end
149
164
  end
@@ -11,6 +11,24 @@ class NetHTTPTest < Minitest::Test
11
11
  assert_equal true, ::Instana.config[:nethttp][:enabled]
12
12
  end
13
13
 
14
+ def test_get_with_query
15
+ clear_all!
16
+ WebMock.allow_net_connect!
17
+
18
+ Instana.tracer.start_or_continue_trace(:"net-http-test") do
19
+ Net::HTTP.get(URI('http://127.0.0.1:6511/?query_value=true'))
20
+ end
21
+
22
+ spans = ::Instana.processor.queued_spans
23
+ assert_equal 3, spans.length
24
+
25
+ http_span = find_first_span_by_name(spans, :'net-http')
26
+ assert_equal "http://127.0.0.1:6511/", http_span[:data][:http][:url]
27
+ assert_equal "query_value=true", http_span[:data][:http][:params]
28
+
29
+ WebMock.disable_net_connect!
30
+ end
31
+
14
32
  def test_block_request
15
33
  clear_all!
16
34
  WebMock.allow_net_connect!
@@ -18,7 +18,7 @@ class RackInstrumentedRequestTest < Minitest::Test
18
18
  refute req.skip_trace?
19
19
  end
20
20
 
21
- def test_incomming_context
21
+ def test_incoming_context
22
22
  id = Instana::Util.generate_id
23
23
  req = Instana::InstrumentedRequest.new(
24
24
  'HTTP_X_INSTANA_L' => '1',
@@ -33,6 +33,51 @@ class RackInstrumentedRequestTest < Minitest::Test
33
33
  }
34
34
 
35
35
  assert_equal expected, req.incoming_context
36
+ refute req.continuing_from_trace_parent?
37
+ end
38
+
39
+ def test_incoming_w3_content
40
+ req = Instana::InstrumentedRequest.new(
41
+ 'HTTP_X_INSTANA_L' => '1',
42
+ 'HTTP_TRACEPARENT' => '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'
43
+ )
44
+
45
+ expected = {
46
+ external_trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
47
+ external_state: nil,
48
+ trace_id: 'a3ce929d0e0e4736',
49
+ span_id: '00f067aa0ba902b7',
50
+ level: '1'
51
+ }
52
+
53
+ assert_equal expected, req.incoming_context
54
+ assert req.continuing_from_trace_parent?
55
+ end
56
+
57
+ def test_incoming_invalid_w3_content
58
+ req = Instana::InstrumentedRequest.new(
59
+ 'HTTP_X_INSTANA_L' => '1',
60
+ 'HTTP_TRACEPARENT' => '00-XXa3ce929d0e0e4736-00f67aa0ba902b7-01'
61
+ )
62
+
63
+ expected = {
64
+ level: '1'
65
+ }
66
+
67
+ assert_equal expected, req.incoming_context
68
+ end
69
+
70
+ def test_incoming_w3_state
71
+ req = Instana::InstrumentedRequest.new(
72
+ 'HTTP_TRACESTATE' => 'a=12345,in=123;abe,c=[+]'
73
+ )
74
+
75
+ expected = {
76
+ t: '123',
77
+ p: 'abe'
78
+ }
79
+
80
+ assert_equal expected, req.instana_ancestor
36
81
  end
37
82
 
38
83
  def test_request_tags
@@ -41,7 +86,8 @@ class RackInstrumentedRequestTest < Minitest::Test
41
86
  'HTTP_HOST' => 'example.com',
42
87
  'REQUEST_METHOD' => 'GET',
43
88
  'HTTP_X_CAPTURE_THIS' => 'that',
44
- 'PATH_INFO' => '/'
89
+ 'PATH_INFO' => '/',
90
+ 'QUERY_STRING' => 'test=true'
45
91
  )
46
92
 
47
93
  expected = {
@@ -50,7 +96,8 @@ class RackInstrumentedRequestTest < Minitest::Test
50
96
  host: 'example.com',
51
97
  header: {
52
98
  "X-Capture-This": 'that'
53
- }
99
+ },
100
+ params: 'test=true'
54
101
  }
55
102
 
56
103
  assert_equal expected, req.request_tags
@@ -15,6 +15,24 @@ class RackTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
+ class ErrorApp
19
+ def call(_env)
20
+ raise 'An Error'
21
+ end
22
+ end
23
+
24
+ class FiveZeroOneApp
25
+ def call(_env)
26
+ [501, {}, ['No']]
27
+ end
28
+ end
29
+
30
+ class NoHeadersApp
31
+ def call(_env)
32
+ [501, nil, ['No']]
33
+ end
34
+ end
35
+
18
36
  def app
19
37
  @app = Rack::Builder.new do
20
38
  use Rack::CommonLogger
@@ -22,6 +40,8 @@ class RackTest < Minitest::Test
22
40
  use Instana::Rack
23
41
  map("/mrlobster") { run Rack::Lobster.new }
24
42
  map("/path_tpl") { run PathTemplateApp.new }
43
+ map("/error") { run ErrorApp.new }
44
+ map("/five_zero_one") { run FiveZeroOneApp.new }
25
45
  end
26
46
  end
27
47
 
@@ -49,6 +69,10 @@ class RackTest < Minitest::Test
49
69
  assert last_response.headers.key?("Server-Timing")
50
70
  assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
51
71
 
72
+ # W3 Trace Context
73
+ assert_equal "00-#{rack_span[:t].rjust(32, '0')}-#{rack_span[:s]}-01", last_response.headers["Traceparent"]
74
+ assert_equal "in=#{rack_span[:t]};#{rack_span[:s]}", last_response.headers["Tracestate"]
75
+
52
76
  assert rack_span.key?(:data)
53
77
  assert rack_span[:data].key?(:http)
54
78
  assert_equal "GET", rack_span[:data][:http][:method]
@@ -272,4 +296,121 @@ class RackTest < Minitest::Test
272
296
  assert_equal :rack, rack_span[:n]
273
297
  assert_equal 'sample_template', rack_span[:data][:http][:path_tpl]
274
298
  end
299
+
300
+ def test_basic_get_with_x_instana_synthetic
301
+ header 'X-INSTANA-SYNTHETIC', '1'
302
+
303
+ clear_all!
304
+ get '/mrlobster'
305
+ assert last_response.ok?
306
+
307
+ spans = ::Instana.processor.queued_spans
308
+
309
+ # Span validation
310
+ assert_equal 1, spans.count
311
+
312
+ first_span = spans.first
313
+ assert_equal true, first_span[:sy]
314
+ end
315
+
316
+ def test_basic_get_with_w3_trace
317
+ clear_all!
318
+
319
+ header 'TRACEPARENT', '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'
320
+
321
+ get '/mrlobster'
322
+ assert last_response.ok?
323
+
324
+ spans = ::Instana.processor.queued_spans
325
+ assert_equal 1, spans.count
326
+
327
+ first_span = spans.first
328
+ assert_equal :rack, first_span[:n]
329
+ assert_equal 'a3ce929d0e0e4736', first_span[:t]
330
+ assert_equal '00f067aa0ba902b7', first_span[:p]
331
+ assert_equal '4bf92f3577b34da6a3ce929d0e0e4736', first_span[:lt]
332
+ assert_nil first_span[:ia]
333
+ assert first_span[:tp]
334
+ end
335
+
336
+ def test_basic_get_with_w3_disabled
337
+ clear_all!
338
+ ::Instana.config[:w3_trace_correlation] = false
339
+
340
+ header 'TRACEPARENT', '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'
341
+
342
+ get '/mrlobster'
343
+ assert last_response.ok?
344
+
345
+ spans = ::Instana.processor.queued_spans
346
+ assert_equal 1, spans.count
347
+
348
+ first_span = spans.first
349
+ assert_equal :rack, first_span[:n]
350
+ refute first_span[:tp]
351
+ ::Instana.config[:w3_trace_correlation] = true
352
+ end
353
+
354
+ def test_skip_trace
355
+ clear_all!
356
+ header 'X_INSTANA_L', '0;junk'
357
+
358
+ get '/mrlobster'
359
+ assert last_response.ok?
360
+
361
+ spans = ::Instana.processor.queued_spans
362
+ assert_equal 0, spans.count
363
+ end
364
+
365
+ def test_disable_trace
366
+ clear_all!
367
+ ::Instana.config[:tracing][:enabled] = false
368
+
369
+ get '/mrlobster'
370
+ assert last_response.ok?
371
+
372
+ spans = ::Instana.processor.queued_spans
373
+ assert_equal 0, spans.count
374
+ ::Instana.config[:tracing][:enabled] = true
375
+ end
376
+
377
+ def test_error_trace
378
+ clear_all!
379
+
380
+ get '/error'
381
+ refute last_response.ok?
382
+
383
+ spans = ::Instana.processor.queued_spans
384
+ assert_equal 1, spans.count
385
+
386
+ first_span = spans.first
387
+ assert_equal :rack, first_span[:n]
388
+ assert_equal 1, first_span[:ec]
389
+ end
390
+
391
+ def test_disable_trace_with_error
392
+ clear_all!
393
+ ::Instana.config[:tracing][:enabled] = false
394
+
395
+ get '/error'
396
+ refute last_response.ok?
397
+
398
+ spans = ::Instana.processor.queued_spans
399
+ assert_equal 0, spans.count
400
+ ::Instana.config[:tracing][:enabled] = true
401
+ end
402
+
403
+ def test_five_zero_x_trace
404
+ clear_all!
405
+
406
+ get '/five_zero_one'
407
+ refute last_response.ok?
408
+
409
+ spans = ::Instana.processor.queued_spans
410
+ assert_equal 1, spans.count
411
+
412
+ first_span = spans.first
413
+ assert_equal :rack, first_span[:n]
414
+ assert_equal 1, first_span[:ec]
415
+ end
275
416
  end