instana 1.11.7 → 1.192.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +10 -0
  3. data/Rakefile +26 -37
  4. data/gemfiles/libraries.gemfile +2 -0
  5. data/lib/instana/agent.rb +6 -0
  6. data/lib/instana/base.rb +2 -0
  7. data/lib/instana/config.rb +11 -0
  8. data/lib/instana/frameworks/cuba.rb +33 -0
  9. data/lib/instana/frameworks/instrumentation/action_controller.rb +11 -0
  10. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +7 -1
  11. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +7 -1
  12. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +23 -5
  13. data/lib/instana/frameworks/roda.rb +41 -0
  14. data/lib/instana/frameworks/sinatra.rb +17 -0
  15. data/lib/instana/instrumentation/excon.rb +1 -1
  16. data/lib/instana/instrumentation/graphql.rb +77 -0
  17. data/lib/instana/instrumentation/instrumented_request.rb +68 -0
  18. data/lib/instana/instrumentation/net-http.rb +2 -0
  19. data/lib/instana/instrumentation/rack.rb +17 -52
  20. data/lib/instana/secrets.rb +42 -0
  21. data/lib/instana/setup.rb +1 -0
  22. data/lib/instana/tracer.rb +6 -0
  23. data/lib/instana/tracing/span.rb +23 -10
  24. data/lib/instana/util.rb +15 -29
  25. data/lib/instana/version.rb +1 -1
  26. data/test/apps/cuba.rb +4 -0
  27. data/test/apps/roda.rb +3 -0
  28. data/test/apps/sinatra.rb +4 -0
  29. data/test/config_test.rb +1 -17
  30. data/test/frameworks/cuba_test.rb +14 -1
  31. data/test/frameworks/rack_test.rb +52 -19
  32. data/test/frameworks/rails/actioncontroller_test.rb +12 -0
  33. data/test/frameworks/rails/activerecord_test.rb +80 -28
  34. data/test/frameworks/roda_test.rb +14 -0
  35. data/test/frameworks/sinatra_test.rb +14 -0
  36. data/test/instrumentation/excon_test.rb +0 -2
  37. data/test/instrumentation/graphql_test.rb +116 -0
  38. data/test/instrumentation/instrumented_request_test.rb +84 -0
  39. data/test/instrumentation/redis_test.rb +10 -0
  40. data/test/secrets_test.rb +73 -0
  41. data/test/tracing/id_management_test.rb +4 -66
  42. data/test/tracing/tracer_test.rb +31 -1
  43. metadata +16 -8
  44. data/test/tracing/trace_test.rb +0 -67
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+
3
+ class InstrumentedRequestTest < Minitest::Test
4
+ def test_skip_trace_with_header
5
+ req = Instana::InstrumentedRequest.new(
6
+ 'HTTP_X_INSTANA_L' => '0;sample-data'
7
+ )
8
+
9
+ assert req.skip_trace?
10
+ end
11
+
12
+ def test_skip_trace_without_header
13
+ req = Instana::InstrumentedRequest.new({})
14
+
15
+ refute req.skip_trace?
16
+ end
17
+
18
+ def test_incomming_context
19
+ id = Instana::Util.generate_id
20
+ req = Instana::InstrumentedRequest.new(
21
+ 'HTTP_X_INSTANA_L' => '1',
22
+ 'HTTP_X_INSTANA_T' => id,
23
+ 'HTTP_X_INSTANA_S' => id
24
+ )
25
+
26
+ expected = {
27
+ trace_id: id,
28
+ span_id: id,
29
+ level: '1'
30
+ }
31
+
32
+ assert_equal expected, req.incoming_context
33
+ end
34
+
35
+ def test_request_tags
36
+ ::Instana.agent.extra_headers = %w[X-Capture-This]
37
+ req = Instana::InstrumentedRequest.new(
38
+ 'HTTP_HOST' => 'example.com',
39
+ 'REQUEST_METHOD' => 'GET',
40
+ 'HTTP_X_CAPTURE_THIS' => 'that',
41
+ 'PATH_INFO' => '/'
42
+ )
43
+
44
+ expected = {
45
+ method: 'GET',
46
+ url: '/',
47
+ host: 'example.com',
48
+ header: {
49
+ "X-Capture-This": 'that'
50
+ }
51
+ }
52
+
53
+ assert_equal expected, req.request_tags
54
+ ::Instana.agent.extra_headers = nil
55
+ end
56
+
57
+ def test_correlation_data_valid
58
+ req = Instana::InstrumentedRequest.new(
59
+ 'HTTP_X_INSTANA_L' => '1,correlationType=web ;correlationId=1234567890abcdef'
60
+ )
61
+ expected = {
62
+ type: 'web',
63
+ id: '1234567890abcdef'
64
+ }
65
+
66
+ assert_equal expected, req.correlation_data
67
+ end
68
+
69
+ def test_correlation_data_invalid
70
+ req = Instana::InstrumentedRequest.new(
71
+ 'HTTP_X_INSTANA_L' => '0;sample-data'
72
+ )
73
+
74
+ assert_equal({}, req.correlation_data)
75
+ end
76
+
77
+ def test_correlation_data_legacy
78
+ req = Instana::InstrumentedRequest.new(
79
+ 'HTTP_X_INSTANA_L' => '1'
80
+ )
81
+
82
+ assert_equal({}, req.correlation_data)
83
+ end
84
+ end
@@ -20,6 +20,16 @@ class RedisTest < Minitest::Test
20
20
  assert_redis_trace('SET')
21
21
  end
22
22
 
23
+ def test_georadius
24
+ clear_all!
25
+
26
+ Instana.tracer.start_or_continue_trace(:redis_test) do
27
+ @redis_client.georadius('Sicily', '15', '37', '200', 'km', 'WITHCOORD', 'WITHDIST')
28
+ end
29
+
30
+ assert_redis_trace('GEORADIUS')
31
+ end
32
+
23
33
  def test_normal_call_with_error
24
34
  clear_all!
25
35
 
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class SecretsTest < Minitest::Test
4
+ def setup
5
+ @subject = Instana::Secrets.new
6
+ end
7
+
8
+ def test_equals_ignore_case
9
+ sample_config = {
10
+ "matcher"=>"equals-ignore-case",
11
+ "list"=>["key"]
12
+ }
13
+
14
+ url = url_for(%w(key Str kEy KEY))
15
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy KEY)
16
+ end
17
+
18
+ def test_equals
19
+ sample_config = {
20
+ "matcher"=>"equals",
21
+ "list"=>["key", "kEy"]
22
+ }
23
+
24
+ url = url_for(%w(key Str kEy KEY))
25
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy)
26
+ end
27
+
28
+ def test_contains_ignore_case
29
+ sample_config = {
30
+ "matcher"=>"contains-ignore-case",
31
+ "list"=>["stan"]
32
+ }
33
+
34
+ url = url_for(%w(instantiate conTESTant sample))
35
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate conTESTant)
36
+ end
37
+
38
+ def test_contains
39
+ sample_config = {
40
+ "matcher"=>"contains",
41
+ "list"=>["stan"]
42
+ }
43
+
44
+ url = url_for(%w(instantiate conTESTant sample))
45
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
46
+
47
+ end
48
+
49
+ def test_regexp
50
+ sample_config = {
51
+ "matcher"=>"regex",
52
+ "list"=>["l{2}"]
53
+ }
54
+
55
+ url = url_for(%w(ball foot move))
56
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(ball)
57
+ end
58
+
59
+ private
60
+
61
+ def url_for(keys)
62
+ url = URI('http://example.com')
63
+ url.query = URI.encode_www_form(keys.map { |k| [k, rand(1..100)]})
64
+ url.to_s
65
+ end
66
+
67
+ def assert_redacted(str, keys)
68
+ url = URI(str)
69
+ params = CGI.parse(url.query)
70
+
71
+ assert_equal keys, params.select { |_, v| v == %w(<redacted>) }.keys, 'to be redacted'
72
+ end
73
+ end
@@ -49,82 +49,20 @@ class TracerIDMgmtTest < Minitest::Test
49
49
  converted_id = Instana::Util.header_to_id(header_id)
50
50
 
51
51
  # Assert that it is an Integer
52
- assert converted_id.is_a?(Integer)
52
+ assert converted_id.is_a?(String)
53
53
  end
54
54
 
55
55
  def test_header_to_id_conversion_with_bogus_header
56
56
  # Bogus nil arg
57
57
  bogus_result = Instana::Util.header_to_id(nil)
58
- assert_equal 0, bogus_result
58
+ assert_equal '', bogus_result
59
59
 
60
60
  # Bogus Integer arg
61
61
  bogus_result = Instana::Util.header_to_id(1234)
62
- assert_equal 0, bogus_result
62
+ assert_equal '', bogus_result
63
63
 
64
64
  # Bogus Array arg
65
65
  bogus_result = Instana::Util.header_to_id([1234])
66
- assert_equal 0, bogus_result
67
- end
68
-
69
- def test_id_conversion_back_and_forth
70
- # id --> header --> id
71
- original_id = ::Instana::Util.generate_id
72
- header_id = Instana::Util.id_to_header(original_id)
73
- converted_back_id = Instana::Util.header_to_id(header_id)
74
- assert original_id == converted_back_id
75
-
76
- # header --> id --> header
77
- original_header_id = "c025ee93b1aeda7b"
78
- id = Instana::Util.header_to_id(original_header_id)
79
- converted_back_header_id = Instana::Util.id_to_header(id)
80
- assert_equal original_header_id, converted_back_header_id
81
-
82
- # Test a random value
83
- id = -7815363404733516491
84
- header = "938a406416457535"
85
-
86
- result = Instana::Util.header_to_id(header)
87
- assert_equal id, result
88
-
89
- result = Instana::Util.id_to_header(id)
90
- assert_equal header, result
91
-
92
- 10000.times do
93
- original_id = ::Instana::Util.generate_id
94
- header_id = Instana::Util.id_to_header(original_id)
95
- converted_back_id = Instana::Util.header_to_id(header_id)
96
- assert original_id == converted_back_id
97
- end
98
- end
99
-
100
- def test_id_max_value_and_conversion
101
- max_id = 9223372036854775807
102
- min_id = -9223372036854775808
103
- max_hex = "7fffffffffffffff"
104
- min_hex = "8000000000000000"
105
-
106
- assert_equal max_hex, Instana::Util.id_to_header(max_id)
107
- assert_equal min_hex, Instana::Util.id_to_header(min_id)
108
-
109
- assert_equal max_id, Instana::Util.header_to_id(max_hex)
110
- assert_equal min_id, Instana::Util.header_to_id(min_hex)
111
- end
112
-
113
- def test_that_leading_zeros_handled_correctly
114
-
115
- header = ::Instana::Util.id_to_header(16)
116
- assert_equal "10", header
117
-
118
- id = ::Instana::Util.header_to_id("10")
119
- assert_equal 16, id
120
-
121
- id = ::Instana::Util.header_to_id("0000000000000010")
122
- assert_equal 16, id
123
-
124
- id = ::Instana::Util.header_to_id("88b6c735206ca42")
125
- assert_equal 615705016619420226, id
126
-
127
- id = ::Instana::Util.header_to_id("088b6c735206ca42")
128
- assert_equal 615705016619420226, id
66
+ assert_equal '', bogus_result
129
67
  end
130
68
  end
@@ -46,6 +46,37 @@ class TracerTest < Minitest::Test
46
46
  assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
47
47
  end
48
48
 
49
+ def test_exotic_tag_types
50
+ clear_all!
51
+
52
+ assert_equal false, ::Instana.tracer.tracing?
53
+
54
+ require 'resolv'
55
+ r = Resolv::DNS.new
56
+ ipv4 = r.getaddress("www.pwpush.com")
57
+
58
+ ::Instana.tracer.start_or_continue_trace(:rack, {:ipaddr => ipv4}) do
59
+ assert_equal true, ::Instana.tracer.tracing?
60
+ sleep 0.1
61
+ end
62
+
63
+ spans = ::Instana.processor.queued_spans
64
+ assert_equal 1, spans.length
65
+
66
+ first_span = spans.first
67
+ assert_equal :rack, first_span[:n]
68
+ assert first_span[:ts].is_a?(Integer)
69
+ assert first_span[:d].is_a?(Integer)
70
+ assert first_span[:d].between?(100, 130)
71
+ assert first_span.key?(:data)
72
+ assert first_span[:data].key?(:ipaddr)
73
+ assert first_span[:data][:ipaddr].is_a?(String)
74
+ assert first_span.key?(:f)
75
+ assert first_span[:f].key?(:e)
76
+ assert first_span[:f].key?(:h)
77
+ assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
78
+ end
79
+
49
80
  def test_errors_are_properly_propagated
50
81
  clear_all!
51
82
  exception_raised = false
@@ -198,7 +229,6 @@ class TracerTest < Minitest::Test
198
229
  assert_equal sdk_span[:k], 3
199
230
  assert_equal sdk_span[:data][:sdk][:custom][:tags][:sub_task_info], 1
200
231
  assert_equal sdk_span[:data][:sdk][:custom][:tags][:sub_task_exit_info], 1
201
-
202
232
  end
203
233
 
204
234
  def test_block_tracing_error_capture
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.11.7
4
+ version: 1.192.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-23 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -175,6 +175,7 @@ extra_rdoc_files: []
175
175
  files:
176
176
  - ".circleci/config.yml"
177
177
  - ".codeclimate.yml"
178
+ - ".editorconfig"
178
179
  - ".fasterer.yml"
179
180
  - ".gitignore"
180
181
  - ".rubocop.yml"
@@ -231,7 +232,9 @@ files:
231
232
  - lib/instana/instrumentation.rb
232
233
  - lib/instana/instrumentation/dalli.rb
233
234
  - lib/instana/instrumentation/excon.rb
235
+ - lib/instana/instrumentation/graphql.rb
234
236
  - lib/instana/instrumentation/grpc.rb
237
+ - lib/instana/instrumentation/instrumented_request.rb
235
238
  - lib/instana/instrumentation/net-http.rb
236
239
  - lib/instana/instrumentation/rack.rb
237
240
  - lib/instana/instrumentation/redis.rb
@@ -242,6 +245,7 @@ files:
242
245
  - lib/instana/opentracing/carrier.rb
243
246
  - lib/instana/opentracing/tracer.rb
244
247
  - lib/instana/rack.rb
248
+ - lib/instana/secrets.rb
245
249
  - lib/instana/setup.rb
246
250
  - lib/instana/test.rb
247
251
  - lib/instana/thread_local.rb
@@ -274,7 +278,9 @@ files:
274
278
  - test/instana_test.rb
275
279
  - test/instrumentation/dalli_test.rb
276
280
  - test/instrumentation/excon_test.rb
281
+ - test/instrumentation/graphql_test.rb
277
282
  - test/instrumentation/grpc_test.rb
283
+ - test/instrumentation/instrumented_request_test.rb
278
284
  - test/instrumentation/net-http_test.rb
279
285
  - test/instrumentation/redis_test.rb
280
286
  - test/instrumentation/resque_test.rb
@@ -287,6 +293,7 @@ files:
287
293
  - test/jobs/sidekiq_job_2.rb
288
294
  - test/models/block.rb
289
295
  - test/models/block6.rb
296
+ - test/secrets_test.rb
290
297
  - test/servers/grpc_50051.rb
291
298
  - test/servers/helpers/sidekiq_worker_initializer.rb
292
299
  - test/servers/rackapp_6511.rb
@@ -296,7 +303,6 @@ files:
296
303
  - test/tracing/custom_test.rb
297
304
  - test/tracing/id_management_test.rb
298
305
  - test/tracing/opentracing_test.rb
299
- - test/tracing/trace_test.rb
300
306
  - test/tracing/tracer_async_test.rb
301
307
  - test/tracing/tracer_test.rb
302
308
  homepage: https://www.instana.com/
@@ -307,7 +313,7 @@ metadata:
307
313
  documentation_uri: https://docs.instana.io/ecosystem/ruby/
308
314
  homepage_uri: https://www.instana.com/
309
315
  source_code_uri: https://github.com/instana/ruby-sensor
310
- post_install_message:
316
+ post_install_message:
311
317
  rdoc_options: []
312
318
  require_paths:
313
319
  - lib
@@ -322,8 +328,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
328
  - !ruby/object:Gem::Version
323
329
  version: '0'
324
330
  requirements: []
325
- rubygems_version: 3.0.6
326
- signing_key:
331
+ rubygems_version: 3.2.6
332
+ signing_key:
327
333
  specification_version: 4
328
334
  summary: Ruby Distributed Tracing & Metrics Sensor for Instana
329
335
  test_files:
@@ -332,11 +338,12 @@ test_files:
332
338
  - test/tracing/tracer_test.rb
333
339
  - test/tracing/custom_test.rb
334
340
  - test/tracing/opentracing_test.rb
335
- - test/tracing/trace_test.rb
336
341
  - test/tracing/tracer_async_test.rb
337
342
  - test/agent/agent_test.rb
338
343
  - test/models/block.rb
339
344
  - test/models/block6.rb
345
+ - test/secrets_test.rb
346
+ - test/instrumentation/graphql_test.rb
340
347
  - test/instrumentation/sidekiq-client_test.rb
341
348
  - test/instrumentation/resque_test.rb
342
349
  - test/instrumentation/sidekiq-worker_test.rb
@@ -344,6 +351,7 @@ test_files:
344
351
  - test/instrumentation/rest-client_test.rb
345
352
  - test/instrumentation/dalli_test.rb
346
353
  - test/instrumentation/excon_test.rb
354
+ - test/instrumentation/instrumented_request_test.rb
347
355
  - test/instrumentation/grpc_test.rb
348
356
  - test/instrumentation/net-http_test.rb
349
357
  - test/benchmarks/bench_opentracing.rb
@@ -1,67 +0,0 @@
1
- # require 'test_helper'
2
- #
3
- # class TraceTest < Minitest::Test
4
- # def test_trace_spans_count
5
- # t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 })
6
- # t.new_span(:sub_span, { :sub_four => 4 })
7
- # t.end_span(:sub_five => 5)
8
- # t.end_span(:three => 3)
9
- # assert t.spans.size == 2
10
- # end
11
- #
12
- # def test_trace_with_incoming_context
13
- # incoming_context = { :trace_id => "1234", :span_id => "4321" }
14
- # t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 }, incoming_context)
15
- # first_span = t.spans.first
16
- # assert_equal "1234", first_span[:t]
17
- # assert_equal "4321", first_span[:p]
18
- # assert t.spans.size == 1
19
- # end
20
- #
21
- # def test_max_value_of_generated_id
22
- # # Max is the maximum value for a Java signed long
23
- # max_value = 9223372036854775807
24
- # 1000.times do
25
- # assert ::Instana::Util.generate_id <= max_value
26
- # end
27
- # end
28
- #
29
- # def test_min_value_of_generated_id
30
- # # Max is the maximum value for a Java signed long
31
- # max_value = -9223372036854775808
32
- # 1000.times do
33
- # assert ::Instana::Util.generate_id >= max_value
34
- # end
35
- # end
36
- #
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
45
- # t = ::Instana::Trace.new(:rack)
46
- # first_span = t.spans.first
47
- # assert first_span.key?(:stack)
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)
57
- # end
58
- #
59
- # def test_exit_span_has_stack_by_config
60
- # ::Instana.config[:collect_backtraces] = true
61
- # t = ::Instana::Trace.new(:trace_test)
62
- # t.new_span(:excon)
63
- # second_span = t.spans.to_a[1]
64
- # assert second_span.key?(:stack)
65
- # ::Instana.config[:collect_backtraces] = false
66
- # end
67
- # end