instana 1.10.8-java → 1.10.9-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,227 @@
1
+ require 'test_helper'
2
+ require 'active_record'
3
+
4
+ class ActiveRecordTest < Minitest::Test
5
+ def test_config_defaults
6
+ assert ::Instana.config[:active_record].is_a?(Hash)
7
+ assert ::Instana.config[:active_record].key?(:enabled)
8
+ assert_equal true, ::Instana.config[:active_record][:enabled]
9
+ end
10
+
11
+ def test_postgresql
12
+ skip unless ::Instana::Test.postgresql?
13
+
14
+ clear_all!
15
+
16
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
17
+
18
+ spans = Instana.processor.queued_spans
19
+ assert_equal 6, spans.length
20
+ rack_span = find_first_span_by_name(spans, :rack)
21
+
22
+ ar_spans = find_spans_by_name(spans, :activerecord)
23
+ assert_equal 3, ar_spans.length
24
+
25
+ ar_spans.each do |span|
26
+ assert_equal "postgresql", span[:data][:activerecord][:adapter]
27
+ assert span[:data][:activerecord].key?(:host)
28
+ assert span[:data][:activerecord].key?(:username)
29
+ end
30
+
31
+
32
+ found = false
33
+ if ::Rails::VERSION::MAJOR < 4
34
+ sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
35
+ else
36
+ sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
37
+ end
38
+ ar_spans.each do |span|
39
+ if span[:data][:activerecord][:sql] ==
40
+ found = true
41
+ end
42
+ end
43
+ assert found
44
+
45
+ found = false
46
+ if ::Rails::VERSION::MAJOR >= 5
47
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT $?"
48
+ elsif ::Rails::VERSION::MAJOR == 4
49
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT ?"
50
+ else
51
+ sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
52
+ end
53
+ ar_spans.each do |span|
54
+ if span[:data][:activerecord][:sql] == sql
55
+ found = true
56
+ end
57
+ end
58
+ assert found
59
+
60
+ found = false
61
+ if ::Rails::VERSION::MAJOR == 3
62
+ sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = ?"
63
+ else
64
+ sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $?"
65
+ end
66
+ ar_spans.each do |span|
67
+ if span[:data][:activerecord][:sql] == sql
68
+ found = true
69
+ end
70
+ end
71
+ assert found
72
+ end
73
+
74
+ def test_postgresql_lock_table
75
+ skip unless ::Instana::Test.postgresql?
76
+
77
+ clear_all!
78
+
79
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db_lock_table'))
80
+
81
+ spans = Instana.processor.queued_spans
82
+ assert_equal 5, spans.length
83
+
84
+ rack_span = find_first_span_by_name(spans, :rack)
85
+ ac_span = find_first_span_by_name(spans, :actioncontroller)
86
+ av_span = find_first_span_by_name(spans, :actionview)
87
+
88
+ ar_spans = find_spans_by_name(spans, :activerecord)
89
+ assert_equal 2, ar_spans.length
90
+
91
+ ar_spans.each do |ar_span|
92
+ assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
93
+ assert_equal "postgres", ar_span[:data][:activerecord][:username]
94
+ end
95
+
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
101
+ end
102
+ assert found
103
+
104
+ found = false
105
+ ar_spans.each do |span|
106
+ if span[:data][:activerecord][:sql] == "SELECT ?"
107
+ found = true
108
+ end
109
+ end
110
+ assert found
111
+ end
112
+
113
+ def test_postgresql_raw_execute
114
+ skip unless ::Instana::Test.postgresql?
115
+
116
+ clear_all!
117
+
118
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db_raw_execute'))
119
+
120
+ spans = Instana.processor.queued_spans
121
+
122
+ assert_equal 4, spans.length
123
+ rack_span = find_first_span_by_name(spans, :rack)
124
+ ac_span = find_first_span_by_name(spans, :actioncontroller)
125
+ av_span = find_first_span_by_name(spans, :actionview)
126
+ ar_span = find_first_span_by_name(spans, :activerecord)
127
+
128
+ assert_equal "SELECT ?", ar_span[:data][:activerecord][:sql]
129
+ assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
130
+ assert_equal "postgres", ar_span[:data][:activerecord][:username]
131
+ end
132
+
133
+ def test_postgresql_raw_execute_error
134
+ skip unless ::Instana::Test.postgresql?
135
+
136
+ clear_all!
137
+
138
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db_raw_execute_error'))
139
+
140
+ spans = Instana.processor.queued_spans
141
+
142
+ assert_equal 3, spans.length
143
+ rack_span = find_first_span_by_name(spans, :rack)
144
+ ac_span = find_first_span_by_name(spans, :actioncontroller)
145
+ ar_span = find_first_span_by_name(spans, :activerecord)
146
+
147
+ assert ar_span.key?(:stack)
148
+ assert ar_span[:data][:activerecord].key?(:error)
149
+ assert ar_span[:data][:activerecord][:error].include?("syntax error")
150
+ assert_equal "This is not real SQL but an intended error", ar_span[:data][:activerecord][:sql]
151
+ assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
152
+ assert_equal "postgres", ar_span[:data][:activerecord][:username]
153
+ end
154
+
155
+ def test_mysql2
156
+ skip unless ::Instana::Test.mysql2?
157
+
158
+ clear_all!
159
+
160
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
161
+
162
+ spans = Instana.processor.queued_spans
163
+ assert_equal 6, spans.length
164
+ rack_span = find_first_span_by_name(spans, :rack)
165
+
166
+ ar_spans = find_spans_by_name(spans, :activerecord)
167
+ assert_equal 3, ar_spans.length
168
+
169
+ ar_spans.each do |span|
170
+ assert_equal "mysql2", span[:data][:activerecord][:adapter]
171
+ assert span[:data][:activerecord].key?(:host)
172
+ assert span[:data][:activerecord].key?(:username)
173
+ end
174
+
175
+ queries = [
176
+ "INSERT INTO `blocks` (`name`, `color`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?)",
177
+ "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? ORDER BY `blocks`.`id` ASC LIMIT ?",
178
+ "DELETE FROM `blocks` WHERE `blocks`.`id` = ?"
179
+ ]
180
+
181
+ queries.each do |sql|
182
+ found = false
183
+ ar_spans.each do |span|
184
+ if span[:data][:activerecord][:sql] = sql
185
+ found = true
186
+ end
187
+ end
188
+ assert found
189
+ end
190
+ end
191
+
192
+ def test_mysql
193
+ skip unless ::Instana::Test.mysql?
194
+
195
+ clear_all!
196
+
197
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
198
+
199
+ spans = Instana.processor.queued_spans
200
+ assert_equal 6, spans.length
201
+ first_span = spans[0]
202
+ second_span = spans[2]
203
+ third_span = spans[3]
204
+ fourth_span = spans[4]
205
+
206
+ assert_equal :rack, first_span[:n]
207
+ assert_equal :activerecord, second_span[:n]
208
+ assert_equal :activerecord, third_span[:n]
209
+ assert_equal :activerecord, fourth_span[:n]
210
+
211
+ assert_equal "INSERT INTO `blocks` (`name`, `color`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?)", second_span[:data][:activerecord][:sql]
212
+ assert_equal "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? ORDER BY `blocks`.`id` ASC LIMIT ?", third_span[:data][:activerecord][:sql]
213
+ assert_equal "DELETE FROM `blocks` WHERE `blocks`.`id` = ?", fourth_span[:data][:activerecord][:sql]
214
+
215
+ assert_equal "mysql", second_span[:data][:activerecord][:adapter]
216
+ assert_equal "mysql", third_span[:data][:activerecord][:adapter]
217
+ assert_equal "mysql", fourth_span[:data][:activerecord][:adapter]
218
+
219
+ assert_equal ENV['TRAVIS_MYSQL_HOST'], second_span[:data][:activerecord][:host]
220
+ assert_equal ENV['TRAVIS_MYSQL_HOST'], third_span[:data][:activerecord][:host]
221
+ assert_equal ENV['TRAVIS_MYSQL_HOST'], fourth_span[:data][:activerecord][:host]
222
+
223
+ assert_equal ENV['TRAVIS_MYSQL_USER'], second_span[:data][:activerecord][:username]
224
+ assert_equal ENV['TRAVIS_MYSQL_USER'], third_span[:data][:activerecord][:username]
225
+ assert_equal ENV['TRAVIS_MYSQL_USER'], fourth_span[:data][:activerecord][:username]
226
+ end
227
+ end
@@ -22,18 +22,21 @@ end
22
22
 
23
23
  class RailsTestApp < Rails::Application
24
24
  routes.append do
25
- get "/test/world" => "test#world"
26
- get "/test/db" => "test#db"
27
- get "/test/error" => "test#error"
28
- get "/test/render_view" => "test#render_view"
29
- get "/test/render_partial" => "test#render_partial"
30
- get "/test/render_collection" => "test#render_collection"
31
- get "/test/render_file" => "test#render_file"
32
- get "/test/render_nothing" => "test#render_nothing"
33
- get "/test/render_json" => "test#render_json"
34
- get "/test/render_xml" => "test#render_xml"
35
- get "/test/render_rawbody" => "test#render_rawbody"
36
- get "/test/render_js" => "test#render_js"
25
+ get "/test/world" => "test#world"
26
+ get "/test/db" => "test#db"
27
+ get "/test/db_lock_table" => "test#db_lock_table"
28
+ get "/test/db_raw_execute" => "test#db_raw_execute"
29
+ get "/test/db_raw_execute_error" => "test#db_raw_execute_error"
30
+ get "/test/error" => "test#error"
31
+ get "/test/render_view" => "test#render_view"
32
+ get "/test/render_partial" => "test#render_partial"
33
+ get "/test/render_collection" => "test#render_collection"
34
+ get "/test/render_file" => "test#render_file"
35
+ get "/test/render_nothing" => "test#render_nothing"
36
+ get "/test/render_json" => "test#render_json"
37
+ get "/test/render_xml" => "test#render_xml"
38
+ get "/test/render_rawbody" => "test#render_rawbody"
39
+ get "/test/render_js" => "test#render_js"
37
40
  get "/test/render_alternate_layout" => "test#render_alternate_layout"
38
41
  get "/test/render_partial_that_errors" => "test#render_partial_that_errors"
39
42
 
@@ -82,6 +85,39 @@ class TestController < ActionController::Base
82
85
  end
83
86
  end
84
87
 
88
+ def db_raw_execute
89
+ ActiveRecord::Base.connection.execute("SELECT 1")
90
+
91
+ if ::Rails::VERSION::MAJOR > 4
92
+ render :plain => "Hello test db!"
93
+ else
94
+ render :text => "Hello test db!"
95
+ end
96
+ end
97
+
98
+ def db_raw_execute_error
99
+ ActiveRecord::Base.connection.execute("This is not real SQL but an intended error")
100
+
101
+ if ::Rails::VERSION::MAJOR > 4
102
+ render :plain => "Hello test db!"
103
+ else
104
+ render :text => "Hello test db!"
105
+ end
106
+ end
107
+
108
+ def db_lock_table
109
+ ActiveRecord::Base.transaction do
110
+ ActiveRecord::Base.connection.execute('LOCK blocks IN ACCESS EXCLUSIVE MODE')
111
+ ActiveRecord::Base.connection.execute("SELECT 1")
112
+ end
113
+
114
+ if ::Rails::VERSION::MAJOR > 4
115
+ render :plain => "Hello test db!"
116
+ else
117
+ render :text => "Hello test db!"
118
+ end
119
+ end
120
+
85
121
  def render_view
86
122
  @message = "Hello Instana!"
87
123
  end
@@ -142,4 +142,23 @@ def find_span_by_id(spans, id)
142
142
  end
143
143
  end
144
144
  raise Exception.new("Span with id (#{id}) not found")
145
+ end
146
+
147
+ # Finds the first span in +spans+ for which +block+ returns true
148
+ #
149
+ # ar_span = find_first_span_by_qualifier(ar_spans) do |span|
150
+ # span[:data][:activerecord][:sql] == sql
151
+ # end
152
+ #
153
+ # This helper will raise an exception if no span evaluates to true against he provided block.
154
+ #
155
+ # +spans+: +Array+ of spans to search
156
+ # +block+: The Ruby block to evaluate against each span
157
+ def find_first_span_by_qualifier(spans, &block)
158
+ spans.each do |span|
159
+ if block.call(span)
160
+ return span
161
+ end
162
+ end
163
+ raise Exception.new("Span with qualifier not found")
145
164
  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.10.8
4
+ version: 1.10.9
5
5
  platform: java
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +152,7 @@ files:
152
152
  - bin/setup
153
153
  - examples/opentracing.rb
154
154
  - examples/tracing.rb
155
+ - gemfiles/.bundle/config
155
156
  - gemfiles/libraries.gemfile
156
157
  - gemfiles/rails32.gemfile
157
158
  - gemfiles/rails42.gemfile
@@ -223,9 +224,7 @@ files:
223
224
  - test/frameworks/rails/actionview3_test.rb
224
225
  - test/frameworks/rails/actionview4_test.rb
225
226
  - test/frameworks/rails/actionview5_test.rb
226
- - test/frameworks/rails/activerecord3_test.rb
227
- - test/frameworks/rails/activerecord4_test.rb
228
- - test/frameworks/rails/activerecord5_test.rb
227
+ - test/frameworks/rails/activerecord_test.rb
229
228
  - test/frameworks/roda_test.rb
230
229
  - test/frameworks/sinatra_test.rb
231
230
  - test/instana_test.rb
@@ -310,12 +309,10 @@ test_files:
310
309
  - test/frameworks/roda_test.rb
311
310
  - test/frameworks/sinatra_test.rb
312
311
  - test/frameworks/rails/actionview4_test.rb
313
- - test/frameworks/rails/activerecord3_test.rb
312
+ - test/frameworks/rails/activerecord_test.rb
314
313
  - test/frameworks/rails/actioncontroller_test.rb
315
314
  - test/frameworks/rails/actionview5_test.rb
316
315
  - test/frameworks/rails/actionview3_test.rb
317
- - test/frameworks/rails/activerecord5_test.rb
318
- - test/frameworks/rails/activerecord4_test.rb
319
316
  - test/apps/sinatra.rb
320
317
  - test/apps/roda.rb
321
318
  - test/apps/cuba.rb
@@ -1,134 +0,0 @@
1
- require 'test_helper'
2
- require 'active_record'
3
-
4
- class ActiveRecordTest < Minitest::Test
5
- def test_config_defaults
6
- assert ::Instana.config[:active_record].is_a?(Hash)
7
- assert ::Instana.config[:active_record].key?(:enabled)
8
- assert_equal true, ::Instana.config[:active_record][:enabled]
9
- end
10
-
11
- def test_postgresql
12
- # Make one call to warm up the Rails stack and allow it to load
13
- # relations
14
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
15
-
16
- skip unless ::Instana::Test.postgresql?
17
-
18
- clear_all!
19
-
20
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
21
-
22
- traces = Instana.processor.queued_traces
23
- assert_equal 1, traces.length
24
- trace = traces.first
25
-
26
- assert_equal 6, trace.spans.length
27
- spans = trace.spans.to_a
28
- first_span = spans[0]
29
- second_span = spans[2]
30
- third_span = spans[3]
31
- fourth_span = spans[4]
32
-
33
- assert_equal :rack, first_span.name
34
- assert_equal :activerecord, second_span.name
35
- assert_equal :activerecord, third_span.name
36
- assert_equal :activerecord, fourth_span.name
37
-
38
- assert_equal "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\"", second_span[:data][:activerecord][:sql]
39
- assert_equal "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?", third_span[:data][:activerecord][:sql]
40
- assert_equal "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = ?", fourth_span[:data][:activerecord][:sql]
41
-
42
- assert_equal "postgresql", second_span[:data][:activerecord][:adapter]
43
- assert_equal "postgresql", third_span[:data][:activerecord][:adapter]
44
- assert_equal "postgresql", fourth_span[:data][:activerecord][:adapter]
45
-
46
- assert_equal ENV['TRAVIS_PSQL_HOST'], second_span[:data][:activerecord][:host]
47
- assert_equal ENV['TRAVIS_PSQL_HOST'], third_span[:data][:activerecord][:host]
48
- assert_equal ENV['TRAVIS_PSQL_HOST'], fourth_span[:data][:activerecord][:host]
49
-
50
- assert_equal "postgres", second_span[:data][:activerecord][:username]
51
- assert_equal "postgres", third_span[:data][:activerecord][:username]
52
- assert_equal "postgres", fourth_span[:data][:activerecord][:username]
53
- end
54
-
55
- def test_mysql2
56
- skip unless ::Instana::Test.mysql2?
57
-
58
- clear_all!
59
-
60
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
61
-
62
- traces = Instana.processor.queued_traces
63
- assert_equal 1, traces.length
64
- trace = traces.first
65
-
66
- assert_equal 6, trace.spans.length
67
- spans = trace.spans.to_a
68
- first_span = spans[0]
69
- second_span = spans[2]
70
- third_span = spans[3]
71
- fourth_span = spans[4]
72
-
73
- assert_equal :rack, first_span.name
74
- assert_equal :activerecord, second_span.name
75
- assert_equal :activerecord, third_span.name
76
- assert_equal :activerecord, fourth_span.name
77
-
78
- assert_equal "INSERT INTO `blocks` (`color`, `created_at`, `name`, `updated_at`) VALUES (?, ?, ?, ?)", second_span[:data][:activerecord][:sql]
79
- assert_equal "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? LIMIT ?", third_span[:data][:activerecord][:sql]
80
- assert_equal "DELETE FROM `blocks` WHERE `blocks`.`id` = ?", fourth_span[:data][:activerecord][:sql]
81
-
82
- assert_equal "mysql2", second_span[:data][:activerecord][:adapter]
83
- assert_equal "mysql2", third_span[:data][:activerecord][:adapter]
84
- assert_equal "mysql2", fourth_span[:data][:activerecord][:adapter]
85
-
86
- assert_equal ENV['TRAVIS_MYSQL_HOST'], second_span[:data][:activerecord][:host]
87
- assert_equal ENV['TRAVIS_MYSQL_HOST'], third_span[:data][:activerecord][:host]
88
- assert_equal ENV['TRAVIS_MYSQL_HOST'], fourth_span[:data][:activerecord][:host]
89
-
90
- assert_equal ENV['TRAVIS_MYSQL_USER'], second_span[:data][:activerecord][:username]
91
- assert_equal ENV['TRAVIS_MYSQL_USER'], third_span[:data][:activerecord][:username]
92
- assert_equal ENV['TRAVIS_MYSQL_USER'], fourth_span[:data][:activerecord][:username]
93
- end
94
-
95
- def test_mysql
96
- skip unless ::Instana::Test.mysql?
97
-
98
- clear_all!
99
-
100
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
101
-
102
- traces = Instana.processor.queued_traces
103
- assert_equal 1, traces.length
104
- trace = traces.first
105
-
106
- assert_equal 6, trace.spans.length
107
- spans = trace.spans.to_a
108
- first_span = spans[0]
109
- second_span = spans[2]
110
- third_span = spans[3]
111
- fourth_span = spans[4]
112
-
113
- assert_equal :rack, first_span.name
114
- assert_equal :activerecord, second_span.name
115
- assert_equal :activerecord, third_span.name
116
- assert_equal :activerecord, fourth_span.name
117
-
118
- assert_equal "INSERT INTO `blocks` (`color`, `created_at`, `name`, `updated_at`) VALUES (?, ?, ?, ?)", second_span[:data][:activerecord][:sql]
119
- assert_equal "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? LIMIT ?", third_span[:data][:activerecord][:sql]
120
- assert_equal "DELETE FROM `blocks` WHERE `blocks`.`id` = ?", fourth_span[:data][:activerecord][:sql]
121
-
122
- assert_equal "mysql", second_span[:data][:activerecord][:adapter]
123
- assert_equal "mysql", third_span[:data][:activerecord][:adapter]
124
- assert_equal "mysql", fourth_span[:data][:activerecord][:adapter]
125
-
126
- assert_equal ENV['TRAVIS_MYSQL_HOST'], second_span[:data][:activerecord][:host]
127
- assert_equal ENV['TRAVIS_MYSQL_HOST'], third_span[:data][:activerecord][:host]
128
- assert_equal ENV['TRAVIS_MYSQL_HOST'], fourth_span[:data][:activerecord][:host]
129
-
130
- assert_equal ENV['TRAVIS_MYSQL_USER'], second_span[:data][:activerecord][:username]
131
- assert_equal ENV['TRAVIS_MYSQL_USER'], third_span[:data][:activerecord][:username]
132
- assert_equal ENV['TRAVIS_MYSQL_USER'], fourth_span[:data][:activerecord][:username]
133
- end
134
- end