instana 1.193.3.pre1 → 1.193.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +18 -12
  3. data/.gitignore +2 -1
  4. data/Appraisals +4 -0
  5. data/gemfiles/cuba_30.gemfile +1 -0
  6. data/gemfiles/dalli_20.gemfile +1 -0
  7. data/gemfiles/excon_02.gemfile +1 -0
  8. data/gemfiles/graphql_10.gemfile +1 -0
  9. data/gemfiles/grpc_10.gemfile +1 -0
  10. data/gemfiles/net_http_01.gemfile +1 -0
  11. data/gemfiles/rack_16.gemfile +1 -0
  12. data/gemfiles/rack_20.gemfile +1 -0
  13. data/gemfiles/rails_42.gemfile +2 -0
  14. data/gemfiles/rails_50.gemfile +2 -0
  15. data/gemfiles/rails_52.gemfile +2 -0
  16. data/gemfiles/rails_60.gemfile +2 -0
  17. data/gemfiles/redis_40.gemfile +1 -0
  18. data/gemfiles/resque_122.gemfile +1 -0
  19. data/gemfiles/resque_20.gemfile +1 -0
  20. data/gemfiles/rest_client_16.gemfile +1 -0
  21. data/gemfiles/rest_client_20.gemfile +1 -0
  22. data/gemfiles/roda_20.gemfile +1 -0
  23. data/gemfiles/roda_30.gemfile +1 -0
  24. data/gemfiles/sidekiq_42.gemfile +1 -0
  25. data/gemfiles/sidekiq_50.gemfile +1 -0
  26. data/gemfiles/sinatra_14.gemfile +1 -0
  27. data/lib/instana/activators/action_controller_api.rb +18 -0
  28. data/lib/instana/activators/action_controller_base.rb +18 -0
  29. data/lib/instana/activators/action_view.rb +18 -0
  30. data/lib/instana/activators/active_record.rb +18 -0
  31. data/lib/instana/frameworks/rails.rb +20 -32
  32. data/lib/instana/instrumentation/action_controller.rb +81 -0
  33. data/lib/instana/instrumentation/action_view.rb +27 -0
  34. data/lib/instana/instrumentation/active_record.rb +47 -0
  35. data/lib/instana/version.rb +1 -1
  36. data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +37 -21
  37. data/test/instrumentation/rails_action_view_test.rb +138 -0
  38. data/test/instrumentation/rails_active_record_test.rb +121 -0
  39. data/test/support/apps/active_record/active_record.rb +21 -0
  40. metadata +19 -23
  41. data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -56
  42. data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -194
  43. data/lib/instana/frameworks/instrumentation/action_view.rb +0 -39
  44. data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
  45. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -83
  46. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -60
  47. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -99
  48. data/test/frameworks/rails/actionview3_test.rb +0 -210
  49. data/test/frameworks/rails/actionview4_test.rb +0 -208
  50. data/test/frameworks/rails/actionview5_test.rb +0 -221
  51. data/test/frameworks/rails/activerecord_test.rb +0 -279
  52. data/test/frameworks/rails_test.rb +0 -15
@@ -1,208 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActionViewTest < Minitest::Test
4
- def test_config_defaults
5
- assert ::Instana.config[:action_view].is_a?(Hash)
6
- assert ::Instana.config[:action_view].key?(:enabled)
7
- assert_equal true, ::Instana.config[:action_view][:enabled]
8
- end
9
-
10
- def test_render_view
11
- clear_all!
12
-
13
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_view'))
14
-
15
- spans = Instana.processor.queued_spans
16
- assert_equal 3, spans.length
17
- rack_span = find_first_span_by_name(spans, :rack)
18
- ac_span = find_first_span_by_name(spans, :actioncontroller)
19
- av_span = find_first_span_by_name(spans, :actionview)
20
-
21
- assert_equal :rack, rack_span[:n]
22
- assert_equal :actioncontroller, ac_span[:n]
23
- assert_equal :actionview, av_span[:n]
24
- end
25
-
26
- def test_render_nothing
27
- clear_all!
28
-
29
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_nothing'))
30
-
31
- spans = Instana.processor.queued_spans
32
- assert_equal 3, spans.length
33
- rack_span = find_first_span_by_name(spans, :rack)
34
- ac_span = find_first_span_by_name(spans, :actioncontroller)
35
- av_span = find_first_span_by_name(spans, :actionview)
36
-
37
- assert_equal :rack, rack_span[:n]
38
- assert_equal :actioncontroller, ac_span[:n]
39
- assert_equal "Nothing", av_span[:data][:actionview][:name]
40
- assert_equal :actionview, av_span[:n]
41
- end
42
-
43
- def test_render_file
44
- clear_all!
45
-
46
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_file'))
47
-
48
- spans = Instana.processor.queued_spans
49
- assert_equal 3, spans.length
50
- rack_span = find_first_span_by_name(spans, :rack)
51
- ac_span = find_first_span_by_name(spans, :actioncontroller)
52
- av_span = find_first_span_by_name(spans, :actionview)
53
-
54
- assert_equal :rack, rack_span[:n]
55
- assert_equal :actioncontroller, ac_span[:n]
56
- assert_equal "/etc/issue", av_span[:data][:actionview][:name]
57
- assert_equal :actionview, av_span[:n]
58
- end
59
-
60
- def test_render_json
61
- clear_all!
62
-
63
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_json'))
64
-
65
- spans = Instana.processor.queued_spans
66
- assert_equal 3, spans.length
67
- rack_span = find_first_span_by_name(spans, :rack)
68
- ac_span = find_first_span_by_name(spans, :actioncontroller)
69
- av_span = find_first_span_by_name(spans, :actionview)
70
-
71
- assert_equal :rack, rack_span[:n]
72
- assert_equal :actioncontroller, ac_span[:n]
73
- assert_equal "JSON", av_span[:data][:actionview][:name]
74
- assert_equal :actionview, av_span[:n]
75
- end
76
-
77
- def test_render_xml
78
- clear_all!
79
-
80
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_xml'))
81
-
82
- spans = Instana.processor.queued_spans
83
- assert_equal 3, spans.length
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
- assert_equal :rack, rack_span[:n]
89
- assert_equal :actioncontroller, ac_span[:n]
90
- assert_equal "XML", av_span[:data][:actionview][:name]
91
- assert_equal :actionview, av_span[:n]
92
- end
93
-
94
- def test_render_body
95
- clear_all!
96
-
97
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_rawbody'))
98
-
99
- spans = Instana.processor.queued_spans
100
- assert_equal 3, spans.length
101
- rack_span = find_first_span_by_name(spans, :rack)
102
- ac_span = find_first_span_by_name(spans, :actioncontroller)
103
- av_span = find_first_span_by_name(spans, :actionview)
104
-
105
- assert_equal :rack, rack_span[:n]
106
- assert_equal :actioncontroller, ac_span[:n]
107
- assert_equal "Raw", av_span[:data][:actionview][:name]
108
- assert_equal :actionview, av_span[:n]
109
- end
110
-
111
- def test_render_js
112
- clear_all!
113
-
114
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_js'))
115
-
116
- spans = Instana.processor.queued_spans
117
- assert_equal 3, spans.length
118
- rack_span = find_first_span_by_name(spans, :rack)
119
- ac_span = find_first_span_by_name(spans, :actioncontroller)
120
- av_span = find_first_span_by_name(spans, :actionview)
121
-
122
- assert_equal :rack, rack_span[:n]
123
- assert_equal :actioncontroller, ac_span[:n]
124
- assert_equal "Javascript", av_span[:data][:actionview][:name]
125
- assert_equal :actionview, av_span[:n]
126
- end
127
-
128
- def test_render_alternate_layout
129
- clear_all!
130
-
131
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_alternate_layout'))
132
-
133
- spans = Instana.processor.queued_spans
134
- assert_equal 3, spans.length
135
- rack_span = find_first_span_by_name(spans, :rack)
136
- ac_span = find_first_span_by_name(spans, :actioncontroller)
137
- av_span = find_first_span_by_name(spans, :actionview)
138
-
139
- assert_equal :rack, rack_span[:n]
140
- assert_equal :actioncontroller, ac_span[:n]
141
- assert_equal "layouts/mobile", av_span[:data][:actionview][:name]
142
- assert_equal :actionview, av_span[:n]
143
- end
144
-
145
- def test_render_partial
146
- clear_all!
147
-
148
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_partial'))
149
-
150
- spans = Instana.processor.queued_spans
151
- assert_equal 4, spans.length
152
- rack_span = find_first_span_by_name(spans, :rack)
153
- ac_span = find_first_span_by_name(spans, :actioncontroller)
154
- av_span = find_first_span_by_name(spans, :actionview)
155
- render_span = find_first_span_by_name(spans, :render)
156
-
157
- assert_equal :rack, rack_span[:n]
158
- assert_equal :actioncontroller, ac_span[:n]
159
- assert_equal :partial, render_span[:data][:render][:type]
160
- assert_equal 'message', render_span[:data][:render][:name]
161
- end
162
-
163
- def test_render_partial_that_errors
164
- clear_all!
165
-
166
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_partial_that_errors'))
167
-
168
- spans = Instana.processor.queued_spans
169
- assert_equal 4, spans.length
170
- rack_span = find_first_span_by_name(spans, :rack)
171
- ac_span = find_first_span_by_name(spans, :actioncontroller)
172
- av_span = find_first_span_by_name(spans, :actionview)
173
- render_span = find_first_span_by_name(spans, :render)
174
-
175
- assert_equal :rack, rack_span[:n]
176
- assert_equal :actioncontroller, ac_span[:n]
177
- assert_equal :actionview, av_span[:n]
178
- assert_equal :render, render_span[:n]
179
- assert_equal :partial, render_span[:data][:render][:type]
180
- assert_equal 'syntax_error', render_span[:data][:render][:name]
181
- assert render_span[:data][:log].key?(:message)
182
- assert_equal "SyntaxError", render_span[:data][:log][:parameters]
183
- assert render_span[:error]
184
- assert render_span[:stack]
185
- end
186
-
187
- def test_render_collection
188
- clear_all!
189
-
190
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_collection'))
191
-
192
- spans = Instana.processor.queued_spans
193
- assert_equal 5, spans.length
194
- rack_span = find_first_span_by_name(spans, :rack)
195
- ac_span = find_first_span_by_name(spans, :actioncontroller)
196
- av_span = find_first_span_by_name(spans, :actionview)
197
- ar_span = find_first_span_by_name(spans, :activerecord)
198
- render_span = find_first_span_by_name(spans, :render)
199
-
200
- assert_equal :rack, rack_span[:n]
201
- assert_equal :actioncontroller, ac_span[:n]
202
- assert_equal :actionview, av_span[:n]
203
- assert_equal :activerecord, ar_span[:n]
204
- assert_equal :render, render_span[:n]
205
- assert_equal :collection, render_span[:data][:render][:type]
206
- assert_equal 'blocks/block', render_span[:data][:render][:name]
207
- end
208
- end
@@ -1,221 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActionViewTest < Minitest::Test
4
- def test_config_defaults
5
- assert ::Instana.config[:action_view].is_a?(Hash)
6
- assert ::Instana.config[:action_view].key?(:enabled)
7
- assert_equal true, ::Instana.config[:action_view][:enabled]
8
- end
9
-
10
- def test_render_view
11
- clear_all!
12
-
13
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_view'))
14
-
15
- spans = ::Instana.processor.queued_spans
16
- assert_equal 3, spans.length
17
-
18
- first_span = spans[2]
19
- second_span = spans[1]
20
- third_span = spans[0]
21
-
22
- assert_equal :rack, first_span[:n]
23
- assert_equal :actioncontroller, second_span[:n]
24
- assert_equal :actionview, third_span[:n]
25
- end
26
-
27
- def test_render_nothing
28
- clear_all!
29
-
30
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_nothing'))
31
-
32
- spans = ::Instana.processor.queued_spans
33
- assert_equal 3, spans.length
34
-
35
- first_span = spans[2]
36
- second_span = spans[1]
37
- third_span = spans[0]
38
-
39
- assert_equal :rack, first_span[:n]
40
- assert_equal :actioncontroller, second_span[:n]
41
- assert_equal "Nothing", third_span[:data][:actionview][:name]
42
- assert_equal :actionview, third_span[:n]
43
- end
44
-
45
- def test_render_file
46
- clear_all!
47
-
48
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_file'))
49
-
50
- spans = ::Instana.processor.queued_spans
51
- assert_equal 3, spans.length
52
-
53
- first_span = spans[2]
54
- second_span = spans[1]
55
- third_span = spans[0]
56
-
57
- assert_equal :rack, first_span[:n]
58
- assert_equal :actioncontroller, second_span[:n]
59
- assert_equal "/etc/issue", third_span[:data][:actionview][:name]
60
- assert_equal :actionview, third_span[:n]
61
- end
62
-
63
- def test_render_json
64
- clear_all!
65
-
66
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_json'))
67
-
68
- spans = ::Instana.processor.queued_spans
69
- assert_equal 3, spans.length
70
-
71
- first_span = spans[2]
72
- second_span = spans[1]
73
- third_span = spans[0]
74
-
75
- assert_equal :rack, first_span[:n]
76
- assert_equal :actioncontroller, second_span[:n]
77
- assert_equal "JSON", third_span[:data][:actionview][:name]
78
- assert_equal :actionview, third_span[:n]
79
- end
80
-
81
- def test_render_xml
82
- clear_all!
83
-
84
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_xml'))
85
-
86
- spans = ::Instana.processor.queued_spans
87
- assert_equal 3, spans.length
88
-
89
- first_span = spans[2]
90
- second_span = spans[1]
91
- third_span = spans[0]
92
-
93
- assert_equal :rack, first_span[:n]
94
- assert_equal :actioncontroller, second_span[:n]
95
- assert_equal "XML", third_span[:data][:actionview][:name]
96
- assert_equal :actionview, third_span[:n]
97
- end
98
-
99
- def test_render_body
100
- clear_all!
101
-
102
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_rawbody'))
103
-
104
- spans = ::Instana.processor.queued_spans
105
- assert_equal 3, spans.length
106
-
107
- rack_span = find_first_span_by_name(spans, :rack)
108
- ac_span = find_first_span_by_name(spans, :actioncontroller)
109
- av_span = find_first_span_by_name(spans, :actionview)
110
-
111
- assert_equal :actioncontroller, ac_span[:n]
112
- assert_equal "Raw", av_span[:data][:actionview][:name]
113
- assert_equal :actionview, av_span[:n]
114
- end
115
-
116
- def test_render_js
117
- clear_all!
118
-
119
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_js'))
120
-
121
- spans = ::Instana.processor.queued_spans
122
- assert_equal 3, spans.length
123
-
124
- first_span = spans[2]
125
- second_span = spans[1]
126
- third_span = spans[0]
127
-
128
- assert_equal :rack, first_span[:n]
129
- assert_equal :actioncontroller, second_span[:n]
130
- assert_equal "Javascript", third_span[:data][:actionview][:name]
131
- assert_equal :actionview, third_span[:n]
132
- end
133
-
134
- def test_render_alternate_layout
135
- clear_all!
136
-
137
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_alternate_layout'))
138
-
139
- spans = ::Instana.processor.queued_spans
140
- assert_equal 3, spans.length
141
-
142
- first_span = spans[2]
143
- second_span = spans[1]
144
- third_span = spans[0]
145
-
146
- assert_equal :rack, first_span[:n]
147
- assert_equal :actioncontroller, second_span[:n]
148
- assert_equal "layouts/mobile", third_span[:data][:actionview][:name]
149
- assert_equal :actionview, third_span[:n]
150
- end
151
-
152
- def test_render_partial
153
- clear_all!
154
-
155
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_partial'))
156
-
157
- spans = ::Instana.processor.queued_spans
158
- assert_equal 4, spans.length
159
-
160
- first_span = spans[3]
161
- second_span = spans[2]
162
- third_span = spans[1]
163
- fourth_span = spans[0]
164
-
165
- assert_equal :rack, first_span[:n]
166
- assert_equal :actioncontroller, second_span[:n]
167
- assert_equal :actionview, third_span[:n]
168
- assert_equal :render, fourth_span[:n]
169
- assert_equal :partial, fourth_span[:data][:render][:type]
170
- assert_equal 'message', fourth_span[:data][:render][:name]
171
- end
172
-
173
- def test_render_partial_that_errors
174
- clear_all!
175
-
176
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_partial_that_errors'))
177
-
178
- spans = ::Instana.processor.queued_spans
179
- assert_equal 4, spans.length
180
-
181
- first_span = spans[3]
182
- second_span = spans[2]
183
- third_span = spans[1]
184
- fourth_span = spans[0]
185
-
186
- assert_equal :rack, first_span[:n]
187
- assert_equal :actioncontroller, second_span[:n]
188
- assert_equal :actionview, third_span[:n]
189
- assert_equal :render, fourth_span[:n]
190
- assert_equal :partial, fourth_span[:data][:render][:type]
191
- assert_equal 'syntax_error', fourth_span[:data][:render][:name]
192
- assert fourth_span[:data][:log].key?(:message)
193
- assert(fourth_span[:data][:log][:parameters].include?("SyntaxError"))
194
- assert fourth_span[:error]
195
- assert fourth_span[:stack]
196
- end
197
-
198
- def test_render_collection
199
- clear_all!
200
-
201
- Net::HTTP.get(URI.parse('http://localhost:3205/test/render_collection'))
202
-
203
- spans = ::Instana.processor.queued_spans
204
- assert_equal 5, spans.length
205
-
206
- rack_span = find_first_span_by_name(spans, :rack)
207
- ac_span = find_first_span_by_name(spans, :actioncontroller)
208
- ar_span = find_first_span_by_name(spans, :activerecord)
209
- av_span = find_first_span_by_name(spans, :actionview)
210
- render_span = find_first_span_by_name(spans, :render)
211
-
212
- assert_equal render_span[:p], av_span[:s]
213
- assert_equal av_span[:p], ac_span[:s]
214
- assert_equal ar_span[:p], av_span[:s]
215
- assert_equal ac_span[:p], rack_span[:s]
216
-
217
- assert_equal :render, render_span[:n]
218
- assert_equal :collection, render_span[:data][:render][:type]
219
- assert_equal 'blocks/block', render_span[:data][:render][:name]
220
- end
221
- end
@@ -1,279 +0,0 @@
1
- require 'test_helper'
2
- require 'active_record'
3
-
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
-
11
- def test_config_defaults
12
- assert ::Instana.config[:sanitize_sql] == true
13
- assert ::Instana.config[:active_record].is_a?(Hash)
14
- assert ::Instana.config[:active_record].key?(:enabled)
15
- assert_equal true, ::Instana.config[:active_record][:enabled]
16
- end
17
-
18
- def test_postgresql
19
- skip unless has_postgres_database?
20
-
21
- clear_all!
22
-
23
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
24
-
25
- spans = Instana.processor.queued_spans
26
- assert_equal 6, spans.length
27
- rack_span = find_first_span_by_name(spans, :rack)
28
-
29
- ar_spans = find_spans_by_name(spans, :activerecord)
30
- assert_equal 3, ar_spans.length
31
-
32
- ar_spans.each do |span|
33
- assert_equal "postgresql", span[:data][:activerecord][:adapter]
34
- assert span[:data][:activerecord].key?(:host)
35
- assert span[:data][:activerecord].key?(:username)
36
- end
37
-
38
- if ::Rails::VERSION::MAJOR < 4
39
- sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
40
- else
41
- sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
42
- end
43
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
44
- span[:data][:activerecord][:sql].squeeze == sql.squeeze
45
- end
46
-
47
- found = false
48
- if ::Rails::VERSION::MAJOR >= 5
49
- sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT $?"
50
- elsif ::Rails::VERSION::MAJOR == 4
51
- sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT ?"
52
- else
53
- sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
54
- end
55
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
56
- span[:data][:activerecord][:sql].squeeze == sql.squeeze
57
- end
58
-
59
- found = false
60
- if ::Rails::VERSION::MAJOR == 3
61
- sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = ?"
62
- else
63
- sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $?"
64
- end
65
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
66
- span[:data][:activerecord][:sql].squeeze == sql.squeeze
67
- end
68
- end
69
-
70
- def test_postgresql_without_sanitize
71
- skip unless has_postgres_database?
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
-
89
- ar_spans.each do |span|
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\""
99
- end
100
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
101
- span[:data][:activerecord][:sql].squeeze == sql.squeeze
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].squeeze == sql.squeeze
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].squeeze == sql.squeeze
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
132
- end
133
-
134
- def test_postgresql_lock_table
135
- skip unless has_postgres_database?
136
-
137
- clear_all!
138
-
139
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db_lock_table'))
140
-
141
- spans = Instana.processor.queued_spans
142
- assert_equal 5, spans.length
143
-
144
- rack_span = find_first_span_by_name(spans, :rack)
145
- ac_span = find_first_span_by_name(spans, :actioncontroller)
146
- av_span = find_first_span_by_name(spans, :actionview)
147
-
148
- ar_spans = find_spans_by_name(spans, :activerecord)
149
- assert_equal 2, ar_spans.length
150
-
151
- ar_spans.each do |ar_span|
152
- assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
153
- assert_equal "postgres", ar_span[:data][:activerecord][:username]
154
- end
155
-
156
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
157
- span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
158
- end
159
-
160
- ar_span = find_first_span_by_qualifier(ar_spans) do |span|
161
- span[:data][:activerecord][:sql] == "SELECT ?"
162
- end
163
- end
164
-
165
- def test_postgresql_raw_execute
166
- skip unless has_postgres_database?
167
-
168
- clear_all!
169
-
170
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db_raw_execute'))
171
-
172
- spans = Instana.processor.queued_spans
173
-
174
- assert_equal 4, spans.length
175
- rack_span = find_first_span_by_name(spans, :rack)
176
- ac_span = find_first_span_by_name(spans, :actioncontroller)
177
- av_span = find_first_span_by_name(spans, :actionview)
178
- ar_span = find_first_span_by_name(spans, :activerecord)
179
-
180
- assert_equal "SELECT ?", ar_span[:data][:activerecord][:sql]
181
- assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
182
- assert_equal "postgres", ar_span[:data][:activerecord][:username]
183
- end
184
-
185
- def test_postgresql_raw_execute_error
186
- skip unless has_postgres_database?
187
-
188
- clear_all!
189
-
190
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db_raw_execute_error'))
191
-
192
- spans = Instana.processor.queued_spans
193
-
194
- assert_equal 3, spans.length
195
- rack_span = find_first_span_by_name(spans, :rack)
196
- ac_span = find_first_span_by_name(spans, :actioncontroller)
197
- ar_span = find_first_span_by_name(spans, :activerecord)
198
-
199
- assert ar_span.key?(:stack)
200
- assert ar_span[:data][:activerecord].key?(:error)
201
- assert ar_span[:data][:activerecord][:error].include?("syntax error")
202
- assert_equal "This is not real SQL but an intended error", ar_span[:data][:activerecord][:sql]
203
- assert_equal "postgresql", ar_span[:data][:activerecord][:adapter]
204
- assert_equal "postgres", ar_span[:data][:activerecord][:username]
205
- end
206
-
207
- def test_mysql2
208
- skip unless has_mysql2_database?
209
-
210
- clear_all!
211
-
212
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
213
-
214
- spans = Instana.processor.queued_spans
215
- assert_equal 6, spans.length
216
- rack_span = find_first_span_by_name(spans, :rack)
217
-
218
- ar_spans = find_spans_by_name(spans, :activerecord)
219
- assert_equal 3, ar_spans.length
220
-
221
- ar_spans.each do |span|
222
- assert_equal "mysql2", span[:data][:activerecord][:adapter]
223
- assert span[:data][:activerecord].key?(:host)
224
- assert span[:data][:activerecord].key?(:username)
225
- end
226
-
227
- queries = [
228
- "INSERT INTO `blocks` (`name`, `color`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?)",
229
- "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? ORDER BY `blocks`.`id` ASC LIMIT ?",
230
- "DELETE FROM `blocks` WHERE `blocks`.`id` = ?"
231
- ]
232
-
233
- queries.each do |sql|
234
- found = false
235
- ar_spans.each do |span|
236
- if span[:data][:activerecord][:sql] = sql
237
- found = true
238
- end
239
- end
240
- assert found
241
- end
242
- end
243
-
244
- def test_mysql
245
- skip unless has_mysql_database?
246
-
247
- clear_all!
248
-
249
- Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
250
-
251
- spans = Instana.processor.queued_spans
252
- assert_equal 6, spans.length
253
- first_span = spans[0]
254
- second_span = spans[2]
255
- third_span = spans[3]
256
- fourth_span = spans[4]
257
-
258
- assert_equal :rack, first_span[:n]
259
- assert_equal :activerecord, second_span[:n]
260
- assert_equal :activerecord, third_span[:n]
261
- assert_equal :activerecord, fourth_span[:n]
262
-
263
- assert_equal "INSERT INTO `blocks` (`name`, `color`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?)", second_span[:data][:activerecord][:sql]
264
- assert_equal "SELECT `blocks`.* FROM `blocks` WHERE `blocks`.`name` = ? ORDER BY `blocks`.`id` ASC LIMIT ?", third_span[:data][:activerecord][:sql]
265
- assert_equal "DELETE FROM `blocks` WHERE `blocks`.`id` = ?", fourth_span[:data][:activerecord][:sql]
266
-
267
- assert_equal "mysql", second_span[:data][:activerecord][:adapter]
268
- assert_equal "mysql", third_span[:data][:activerecord][:adapter]
269
- assert_equal "mysql", fourth_span[:data][:activerecord][:adapter]
270
-
271
- assert_equal ENV['TRAVIS_MYSQL_HOST'], second_span[:data][:activerecord][:host]
272
- assert_equal ENV['TRAVIS_MYSQL_HOST'], third_span[:data][:activerecord][:host]
273
- assert_equal ENV['TRAVIS_MYSQL_HOST'], fourth_span[:data][:activerecord][:host]
274
-
275
- assert_equal ENV['TRAVIS_MYSQL_USER'], second_span[:data][:activerecord][:username]
276
- assert_equal ENV['TRAVIS_MYSQL_USER'], third_span[:data][:activerecord][:username]
277
- assert_equal ENV['TRAVIS_MYSQL_USER'], fourth_span[:data][:activerecord][:username]
278
- end
279
- end