instana 1.193.0 → 1.193.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of instana might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fa2d34630db364163860954f67e65c38f76b6534e34b857cacaa2bc5fb06697
4
- data.tar.gz: d458b50ec707675d06c5891b92af7e2efe1bb7c60d19713721e439a158060be9
3
+ metadata.gz: e0c2b0b0e44a5aa72f401d7ab7009125c25d182c01aa01aade80a8ca9f9fc55b
4
+ data.tar.gz: d147f265753ba3397773197b366f8a24f53a4e928ca8e08a929664c7d5029a1e
5
5
  SHA512:
6
- metadata.gz: f6ac5ae188ddd4217d2f378690b88080c7cb3dd92375eac1feae16cd37dd9607b9332dce11c2df1408a7f0b4a24a5f79b6f3a26057a539ccb2a8c37963f900b7
7
- data.tar.gz: e27dd436e1d4e0f7fdfdec35c1dcb252e32dce84d3eb8a06143d03bbb49dd839179da8d056c46080167cc9b9d940474a8678b341667c723006b1a9528a8c4b53
6
+ metadata.gz: 5bb4b908097b92adf0169f9ca71a43f82df4349b3257cc30cdbc2b8ba3ec13b62171e9c3ed14c1233421801795ebaba4c697c43776e9e31983af900db95d56ff
7
+ data.tar.gz: f7d415705c052ab4c85d446da325569a9940c1d7bfdeb782f17d263d78152585364203120e50c91737d29e992a146710df434874c46c58ce0107df14b5bc7cab
@@ -42,6 +42,16 @@ module Instana
42
42
  # ::Instana.config[:collect_backtraces] = true
43
43
  @config[:collect_backtraces] = false
44
44
 
45
+ # By default, collected SQL will be sanitized to remove potentially sensitive bind params such as:
46
+ # > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = "Mr. Smith"
47
+ #
48
+ # ...would be sanitized to be:
49
+ # > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = ?
50
+ #
51
+ # This sanitization step can be disabled by setting the following value to false.
52
+ # ::Instana.config[:sanitize_sql] = false
53
+ @config[:sanitize_sql] = true
54
+
45
55
  @config[:action_controller] = { :enabled => true }
46
56
  @config[:action_view] = { :enabled => true }
47
57
  @config[:active_record] = { :enabled => true }
@@ -24,7 +24,13 @@ module Instana
24
24
  #
25
25
  def collect(sql)
26
26
  payload = { :activerecord => {} }
27
- payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
27
+
28
+ if ::Instana.config[:sanitize_sql]
29
+ payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
30
+ else
31
+ payload[:activerecord][:sql] = sql
32
+ end
33
+
28
34
  payload[:activerecord][:adapter] = @config[:adapter]
29
35
  payload[:activerecord][:host] = @config[:host]
30
36
  payload[:activerecord][:db] = @config[:database]
@@ -21,7 +21,13 @@ module Instana
21
21
  #
22
22
  def collect(sql)
23
23
  payload = { :activerecord => {} }
24
- payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
24
+
25
+ if ::Instana.config[:sanitize_sql]
26
+ payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
27
+ else
28
+ payload[:activerecord][:sql] = sql
29
+ end
30
+
25
31
  payload[:activerecord][:adapter] = @config[:adapter]
26
32
  payload[:activerecord][:host] = @config[:host]
27
33
  payload[:activerecord][:db] = @config[:database]
@@ -17,7 +17,6 @@ module Instana
17
17
  Instana::Util.method_alias(klass, :exec_delete)
18
18
  Instana::Util.method_alias(klass, :execute)
19
19
 
20
-
21
20
  @@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
22
21
  end
23
22
  end
@@ -27,14 +26,33 @@ module Instana
27
26
  # @param sql [String]
28
27
  # @return [Hash] Hash of collected KVs
29
28
  #
30
- def collect(sql)
29
+ def collect(sql, binds = nil)
31
30
  payload = { :activerecord => {} }
32
- payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
31
+
33
32
  payload[:activerecord][:adapter] = @config[:adapter]
34
33
  payload[:activerecord][:host] = @config[:host]
35
34
  payload[:activerecord][:db] = @config[:database]
36
35
  payload[:activerecord][:username] = @config[:username]
36
+
37
+ if ::Instana.config[:sanitize_sql]
38
+ payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
39
+ else
40
+ # No sanitization so raw SQL and collect up binds
41
+ payload[:activerecord][:sql] = sql
42
+
43
+ # FIXME: Only works on Rails 5 as the bind format varied in previous versions of Rails
44
+ if binds.is_a?(Array)
45
+ raw_binds = []
46
+ binds.each { |x| raw_binds << x.value_before_type_cast }
47
+ payload[:activerecord][:binds] = raw_binds
48
+ end
49
+ end
50
+
37
51
  payload
52
+ rescue Exception => e
53
+ ::Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
54
+ ensure
55
+ return payload
38
56
  end
39
57
 
40
58
  # In the spirit of ::ActiveRecord::ExplainSubscriber.ignore_payload? There are
@@ -53,7 +71,7 @@ module Instana
53
71
  return exec_query_without_instana(sql, name, binds, *args)
54
72
  end
55
73
 
56
- kv_payload = collect(sql)
74
+ kv_payload = collect(sql, binds)
57
75
  ::Instana.tracer.trace(:activerecord, kv_payload) do
58
76
  exec_query_without_instana(sql, name, binds, *args)
59
77
  end
@@ -64,7 +82,7 @@ module Instana
64
82
  return exec_delete_without_instana(sql, name, binds)
65
83
  end
66
84
 
67
- kv_payload = collect(sql)
85
+ kv_payload = collect(sql, binds)
68
86
  ::Instana.tracer.trace(:activerecord, kv_payload) do
69
87
  exec_delete_without_instana(sql, name, binds)
70
88
  end
@@ -57,9 +57,6 @@ module Instana
57
57
  end
58
58
 
59
59
  if ::Instana.config[:collect_backtraces]
60
- # For entry spans, add a backtrace fingerprint
61
- add_stack(limit: 2) if ENTRY_SPANS.include?(name)
62
-
63
60
  # Attach a backtrace to all exit spans
64
61
  add_stack if EXIT_SPANS.include?(name)
65
62
  end
@@ -76,9 +73,11 @@ module Instana
76
73
  #
77
74
  # @param limit [Integer] Limit the backtrace to the top <limit> frames
78
75
  #
79
- def add_stack(limit: nil, stack: Kernel.caller)
76
+ def add_stack(limit: 30, stack: Kernel.caller)
80
77
  frame_count = 0
78
+ sanitized_stack = []
81
79
  @data[:stack] = []
80
+ limit = 40 if limit > 40
82
81
 
83
82
  stack.each do |i|
84
83
  # If the stack has the full instana gem version in it's path
@@ -86,18 +85,23 @@ module Instana
86
85
  if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
87
86
  (i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
88
87
 
89
- break if limit && frame_count >= limit
90
-
91
88
  x = i.split(':')
92
89
 
93
- @data[:stack] << {
90
+ sanitized_stack << {
94
91
  :c => x[0],
95
92
  :n => x[1],
96
93
  :m => x[2]
97
94
  }
98
- frame_count = frame_count + 1 if limit
99
95
  end
100
96
  end
97
+
98
+ if sanitized_stack.length > limit
99
+ # (limit * -1) gives us negative form of <limit> used for
100
+ # slicing from the end of the list. e.g. stack[-30, 30]
101
+ @data[:stack] = sanitized_stack[limit*-1, limit]
102
+ else
103
+ @data[:stack] = sanitized_stack
104
+ end
101
105
  end
102
106
 
103
107
  # Log an error into the span
@@ -1,4 +1,4 @@
1
1
  module Instana
2
- VERSION = "1.193.0"
2
+ VERSION = "1.193.1"
3
3
  VERSION_FULL = "instana-#{VERSION}"
4
4
  end
@@ -57,11 +57,7 @@ class RackTest < Minitest::Test
57
57
  assert rack_span[:f].key?(:e)
58
58
  assert rack_span[:f].key?(:h)
59
59
  assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
60
-
61
- # Backtrace fingerprint validation
62
- assert rack_span.key?(:stack)
63
- assert_equal 2, rack_span[:stack].count
64
- refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
60
+ assert !rack_span.key?(:stack)
65
61
 
66
62
  # Restore to default
67
63
  ::Instana.config[:collect_backtraces] = false
@@ -233,11 +229,7 @@ class RackTest < Minitest::Test
233
229
  assert rack_span[:data][:http][:header].key?(:"X-Capture-This")
234
230
  assert !rack_span[:data][:http][:header].key?(:"X-Capture-That")
235
231
  assert_equal "ThereYouGo", rack_span[:data][:http][:header][:"X-Capture-This"]
236
-
237
- # Backtrace fingerprint validation
238
- assert rack_span.key?(:stack)
239
- assert_equal 2, rack_span[:stack].count
240
- refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
232
+ assert !rack_span.key?(:stack)
241
233
 
242
234
  # Restore to default
243
235
  ::Instana.config[:collect_backtraces] = false
@@ -2,7 +2,14 @@ require 'test_helper'
2
2
  require 'active_record'
3
3
 
4
4
  class ActiveRecordTest < Minitest::Test
5
+
6
+ def teardown
7
+ # Make sure defaults are back in place
8
+ ::Instana.config[:sanitize_sql] = true
9
+ end
10
+
5
11
  def test_config_defaults
12
+ assert ::Instana.config[:sanitize_sql] == true
6
13
  assert ::Instana.config[:active_record].is_a?(Hash)
7
14
  assert ::Instana.config[:active_record].key?(:enabled)
8
15
  assert_equal true, ::Instana.config[:active_record][:enabled]
@@ -28,19 +35,14 @@ class ActiveRecordTest < Minitest::Test
28
35
  assert span[:data][:activerecord].key?(:username)
29
36
  end
30
37
 
31
-
32
- found = false
33
38
  if ::Rails::VERSION::MAJOR < 4
34
39
  sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
35
40
  else
36
41
  sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
37
42
  end
38
- ar_spans.each do |span|
39
- if span[:data][:activerecord][:sql] ==
40
- found = true
41
- end
43
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
44
+ span[:data][:activerecord][:sql] == sql
42
45
  end
43
- assert found
44
46
 
45
47
  found = false
46
48
  if ::Rails::VERSION::MAJOR >= 5
@@ -50,12 +52,9 @@ class ActiveRecordTest < Minitest::Test
50
52
  else
51
53
  sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
52
54
  end
53
- ar_spans.each do |span|
54
- if span[:data][:activerecord][:sql] == sql
55
- found = true
56
- end
55
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
56
+ span[:data][:activerecord][:sql] == sql
57
57
  end
58
- assert found
59
58
 
60
59
  found = false
61
60
  if ::Rails::VERSION::MAJOR == 3
@@ -63,12 +62,73 @@ class ActiveRecordTest < Minitest::Test
63
62
  else
64
63
  sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $?"
65
64
  end
65
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
66
+ span[:data][:activerecord][:sql] == sql
67
+ end
68
+ end
69
+
70
+ def test_postgresql_without_sanitize
71
+ skip unless ::Instana::Test.postgresql?
72
+
73
+ # Shut SQL sanitization off
74
+ ::Instana.config[:sanitize_sql] = false
75
+ # Pause so the thread can syncronize values
76
+ sleep 1
77
+
78
+ clear_all!
79
+
80
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
81
+
82
+ spans = Instana.processor.queued_spans
83
+ assert_equal 6, spans.length
84
+ rack_span = find_first_span_by_name(spans, :rack)
85
+
86
+ ar_spans = find_spans_by_name(spans, :activerecord)
87
+ assert_equal 3, ar_spans.length
88
+
66
89
  ar_spans.each do |span|
67
- if span[:data][:activerecord][:sql] == sql
68
- found = true
69
- end
90
+ assert_equal "postgresql", span[:data][:activerecord][:adapter]
91
+ assert span[:data][:activerecord].key?(:host)
92
+ assert span[:data][:activerecord].key?(:username)
93
+ end
94
+
95
+ if ::Rails::VERSION::MAJOR < 4
96
+ sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($1, $2, $3, $4) RETURNING \"id\""
97
+ else
98
+ sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($1, $2, $3, $4) RETURNING \"id\""
70
99
  end
71
- assert found
100
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
101
+ span[:data][:activerecord][:sql] == sql
102
+ end
103
+ assert ar_span[:data][:activerecord].key?(:binds)
104
+ assert ar_span[:data][:activerecord][:binds].is_a?(Array)
105
+ assert_equal 4, ar_span[:data][:activerecord][:binds].length
106
+
107
+ if ::Rails::VERSION::MAJOR >= 5
108
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $1 ORDER BY \"blocks\".\"id\" ASC LIMIT $2"
109
+ elsif ::Rails::VERSION::MAJOR == 4
110
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT ?"
111
+ else
112
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
113
+ end
114
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
115
+ span[:data][:activerecord][:sql] == sql
116
+ end
117
+ assert ar_span[:data][:activerecord].key?(:binds)
118
+ assert ar_span[:data][:activerecord][:binds].is_a?(Array)
119
+ assert_equal 2, ar_span[:data][:activerecord][:binds].length
120
+
121
+ if ::Rails::VERSION::MAJOR == 3
122
+ sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = 1"
123
+ else
124
+ sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $1"
125
+ end
126
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
127
+ span[:data][:activerecord][:sql] == sql
128
+ end
129
+ assert ar_span[:data][:activerecord].key?(:binds)
130
+ assert ar_span[:data][:activerecord][:binds].is_a?(Array)
131
+ assert_equal 1, ar_span[:data][:activerecord][:binds].length
72
132
  end
73
133
 
74
134
  def test_postgresql_lock_table
@@ -93,21 +153,13 @@ class ActiveRecordTest < Minitest::Test
93
153
  assert_equal "postgres", ar_span[:data][:activerecord][:username]
94
154
  end
95
155
 
96
- found = false
97
- ar_spans.each do |span|
98
- if span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
99
- found = true
100
- end
156
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
157
+ span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
101
158
  end
102
- assert found
103
159
 
104
- found = false
105
- ar_spans.each do |span|
106
- if span[:data][:activerecord][:sql] == "SELECT ?"
107
- found = true
108
- end
160
+ ar_span = find_first_span_by_qualifier(ar_spans) do |span|
161
+ span[:data][:activerecord][:sql] == "SELECT ?"
109
162
  end
110
- assert found
111
163
  end
112
164
 
113
165
  def test_postgresql_raw_execute
@@ -116,8 +116,6 @@ class ExconTest < Minitest::Test
116
116
  assert_equal 3, rack_spans.length
117
117
  assert_equal 3, excon_spans.length
118
118
 
119
- # ::Instana::Util.pry!
120
-
121
119
  for rack_span in rack_spans
122
120
  # data keys/values
123
121
  refute_nil rack_span.key?(:data)
@@ -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
 
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: 1.193.0
4
+ version: 1.193.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo