traceview 3.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +58 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +490 -0
- data/CONFIG.md +16 -0
- data/Gemfile +95 -0
- data/LICENSE +199 -0
- data/README.md +380 -0
- data/Rakefile +109 -0
- data/examples/DNT.md +35 -0
- data/examples/carrying_context.rb +225 -0
- data/examples/instrumenting_metal_controller.rb +8 -0
- data/examples/puma_on_heroku_config.rb +17 -0
- data/examples/tracing_async_threads.rb +125 -0
- data/examples/tracing_background_jobs.rb +52 -0
- data/examples/tracing_forked_processes.rb +100 -0
- data/examples/unicorn_on_heroku_config.rb +28 -0
- data/ext/oboe_metal/extconf.rb +61 -0
- data/ext/oboe_metal/noop/noop.c +7 -0
- data/ext/oboe_metal/src/bson/bson.h +221 -0
- data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
- data/ext/oboe_metal/src/oboe.h +275 -0
- data/ext/oboe_metal/src/oboe.hpp +352 -0
- data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
- data/ext/oboe_metal/tests/test.rb +11 -0
- data/gemfiles/mongo.gemfile +33 -0
- data/gemfiles/moped.gemfile +33 -0
- data/get_version.rb +5 -0
- data/init.rb +4 -0
- data/lib/joboe_metal.rb +206 -0
- data/lib/oboe/README +2 -0
- data/lib/oboe/backward_compatibility.rb +59 -0
- data/lib/oboe/inst/rack.rb +11 -0
- data/lib/oboe.rb +7 -0
- data/lib/oboe_metal.rb +151 -0
- data/lib/rails/generators/traceview/install_generator.rb +76 -0
- data/lib/rails/generators/traceview/templates/traceview_initializer.rb +159 -0
- data/lib/traceview/api/layerinit.rb +51 -0
- data/lib/traceview/api/logging.rb +209 -0
- data/lib/traceview/api/memcache.rb +31 -0
- data/lib/traceview/api/profiling.rb +50 -0
- data/lib/traceview/api/tracing.rb +135 -0
- data/lib/traceview/api/util.rb +121 -0
- data/lib/traceview/api.rb +18 -0
- data/lib/traceview/base.rb +225 -0
- data/lib/traceview/config.rb +238 -0
- data/lib/traceview/frameworks/grape.rb +97 -0
- data/lib/traceview/frameworks/padrino/templates.rb +58 -0
- data/lib/traceview/frameworks/padrino.rb +64 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
- data/lib/traceview/frameworks/rails/inst/action_controller.rb +216 -0
- data/lib/traceview/frameworks/rails/inst/action_view.rb +56 -0
- data/lib/traceview/frameworks/rails/inst/action_view_2x.rb +54 -0
- data/lib/traceview/frameworks/rails/inst/action_view_30.rb +48 -0
- data/lib/traceview/frameworks/rails/inst/active_record.rb +24 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +117 -0
- data/lib/traceview/frameworks/rails.rb +145 -0
- data/lib/traceview/frameworks/sinatra/templates.rb +56 -0
- data/lib/traceview/frameworks/sinatra.rb +95 -0
- data/lib/traceview/inst/cassandra.rb +279 -0
- data/lib/traceview/inst/dalli.rb +86 -0
- data/lib/traceview/inst/em-http-request.rb +99 -0
- data/lib/traceview/inst/excon.rb +111 -0
- data/lib/traceview/inst/faraday.rb +73 -0
- data/lib/traceview/inst/http.rb +87 -0
- data/lib/traceview/inst/httpclient.rb +173 -0
- data/lib/traceview/inst/memcache.rb +102 -0
- data/lib/traceview/inst/memcached.rb +94 -0
- data/lib/traceview/inst/mongo.rb +238 -0
- data/lib/traceview/inst/moped.rb +474 -0
- data/lib/traceview/inst/rack.rb +122 -0
- data/lib/traceview/inst/redis.rb +271 -0
- data/lib/traceview/inst/resque.rb +192 -0
- data/lib/traceview/inst/rest-client.rb +38 -0
- data/lib/traceview/inst/sequel.rb +162 -0
- data/lib/traceview/inst/typhoeus.rb +102 -0
- data/lib/traceview/instrumentation.rb +21 -0
- data/lib/traceview/loading.rb +94 -0
- data/lib/traceview/logger.rb +41 -0
- data/lib/traceview/method_profiling.rb +84 -0
- data/lib/traceview/ruby.rb +36 -0
- data/lib/traceview/support.rb +113 -0
- data/lib/traceview/thread_local.rb +26 -0
- data/lib/traceview/util.rb +250 -0
- data/lib/traceview/version.rb +16 -0
- data/lib/traceview/xtrace.rb +90 -0
- data/lib/traceview.rb +62 -0
- data/test/frameworks/apps/grape_nested.rb +30 -0
- data/test/frameworks/apps/grape_simple.rb +24 -0
- data/test/frameworks/apps/padrino_simple.rb +45 -0
- data/test/frameworks/apps/sinatra_simple.rb +24 -0
- data/test/frameworks/grape_test.rb +142 -0
- data/test/frameworks/padrino_test.rb +30 -0
- data/test/frameworks/sinatra_test.rb +30 -0
- data/test/instrumentation/cassandra_test.rb +380 -0
- data/test/instrumentation/dalli_test.rb +171 -0
- data/test/instrumentation/em_http_request_test.rb +86 -0
- data/test/instrumentation/excon_test.rb +207 -0
- data/test/instrumentation/faraday_test.rb +235 -0
- data/test/instrumentation/http_test.rb +140 -0
- data/test/instrumentation/httpclient_test.rb +296 -0
- data/test/instrumentation/memcache_test.rb +251 -0
- data/test/instrumentation/memcached_test.rb +226 -0
- data/test/instrumentation/mongo_test.rb +462 -0
- data/test/instrumentation/moped_test.rb +496 -0
- data/test/instrumentation/rack_test.rb +116 -0
- data/test/instrumentation/redis_hashes_test.rb +265 -0
- data/test/instrumentation/redis_keys_test.rb +318 -0
- data/test/instrumentation/redis_lists_test.rb +310 -0
- data/test/instrumentation/redis_misc_test.rb +160 -0
- data/test/instrumentation/redis_sets_test.rb +293 -0
- data/test/instrumentation/redis_sortedsets_test.rb +325 -0
- data/test/instrumentation/redis_strings_test.rb +333 -0
- data/test/instrumentation/resque_test.rb +62 -0
- data/test/instrumentation/rest-client_test.rb +294 -0
- data/test/instrumentation/sequel_mysql2_test.rb +326 -0
- data/test/instrumentation/sequel_mysql_test.rb +326 -0
- data/test/instrumentation/sequel_pg_test.rb +330 -0
- data/test/instrumentation/typhoeus_test.rb +285 -0
- data/test/minitest_helper.rb +187 -0
- data/test/profiling/method_test.rb +198 -0
- data/test/servers/rackapp_8101.rb +22 -0
- data/test/support/backcompat_test.rb +269 -0
- data/test/support/config_test.rb +128 -0
- data/test/support/dnt_test.rb +73 -0
- data/test/support/liboboe_settings_test.rb +104 -0
- data/test/support/xtrace_test.rb +35 -0
- data/traceview.gemspec +29 -0
- metadata +248 -0
@@ -0,0 +1,330 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
unless defined?(JRUBY_VERSION)
|
4
|
+
|
5
|
+
if ENV.key?('TRAVIS_PSQL_PASS')
|
6
|
+
PG_DB = Sequel.connect("postgres://postgres:#{ENV['TRAVIS_PSQL_PASS']}@127.0.0.1:5432/travis_ci_test")
|
7
|
+
else
|
8
|
+
PG_DB = Sequel.connect('postgres://postgres@127.0.0.1:5432/travis_ci_test')
|
9
|
+
end
|
10
|
+
|
11
|
+
unless PG_DB.table_exists?(:items)
|
12
|
+
PG_DB.create_table :items do
|
13
|
+
primary_key :id
|
14
|
+
String :name
|
15
|
+
Float :price
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Sequel (postgres)" do
|
20
|
+
before do
|
21
|
+
clear_all_traces
|
22
|
+
|
23
|
+
# These are standard entry/exit KVs that are passed up with all sequel operations
|
24
|
+
@entry_kvs = {
|
25
|
+
'Layer' => 'sequel',
|
26
|
+
'Label' => 'entry',
|
27
|
+
'Database' => 'travis_ci_test',
|
28
|
+
'RemoteHost' => '127.0.0.1',
|
29
|
+
'RemotePort' => 5432 }
|
30
|
+
|
31
|
+
@exit_kvs = { 'Layer' => 'sequel', 'Label' => 'exit' }
|
32
|
+
@collect_backtraces = TraceView::Config[:sequel][:collect_backtraces]
|
33
|
+
@sanitize_sql = TraceView::Config[:sanitize_sql]
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
TraceView::Config[:sequel][:collect_backtraces] = @collect_backtraces
|
38
|
+
TraceView::Config[:sanitize_sql] = @sanitize_sql
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Stock sequel should be loaded, defined and ready' do
|
42
|
+
defined?(::Sequel).wont_match nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sequel should have traceview methods defined' do
|
46
|
+
# Sequel::Database
|
47
|
+
::Sequel::Database.method_defined?(:run_with_traceview).must_equal true
|
48
|
+
|
49
|
+
# Sequel::Dataset
|
50
|
+
::Sequel::Dataset.method_defined?(:execute_with_traceview).must_equal true
|
51
|
+
::Sequel::Dataset.method_defined?(:execute_ddl_with_traceview).must_equal true
|
52
|
+
::Sequel::Dataset.method_defined?(:execute_dui_with_traceview).must_equal true
|
53
|
+
::Sequel::Dataset.method_defined?(:execute_insert_with_traceview).must_equal true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should obey :collect_backtraces setting when true" do
|
57
|
+
TraceView::Config[:sequel][:collect_backtraces] = true
|
58
|
+
|
59
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
60
|
+
PG_DB.run('select 1')
|
61
|
+
end
|
62
|
+
|
63
|
+
traces = get_all_traces
|
64
|
+
layer_has_key(traces, 'sequel', 'Backtrace')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should obey :collect_backtraces setting when false" do
|
68
|
+
TraceView::Config[:sequel][:collect_backtraces] = false
|
69
|
+
|
70
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
71
|
+
PG_DB.run('select 1')
|
72
|
+
end
|
73
|
+
|
74
|
+
traces = get_all_traces
|
75
|
+
layer_doesnt_have_key(traces, 'sequel', 'Backtrace')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should trace PG_DB.run insert' do
|
79
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
80
|
+
PG_DB.run("insert into items (name, price) values ('blah', '12')")
|
81
|
+
end
|
82
|
+
|
83
|
+
traces = get_all_traces
|
84
|
+
|
85
|
+
traces.count.must_equal 4
|
86
|
+
validate_outer_layers(traces, 'sequel_test')
|
87
|
+
|
88
|
+
validate_event_keys(traces[1], @entry_kvs)
|
89
|
+
traces[1]['Query'].must_equal "insert into items (name, price) values ('blah', '12')"
|
90
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
91
|
+
validate_event_keys(traces[2], @exit_kvs)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should trace PG_DB.run select' do
|
95
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
96
|
+
PG_DB.run("select 1")
|
97
|
+
end
|
98
|
+
|
99
|
+
traces = get_all_traces
|
100
|
+
|
101
|
+
traces.count.must_equal 4
|
102
|
+
validate_outer_layers(traces, 'sequel_test')
|
103
|
+
|
104
|
+
validate_event_keys(traces[1], @entry_kvs)
|
105
|
+
traces[1]['Query'].must_equal "select 1"
|
106
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
107
|
+
validate_event_keys(traces[2], @exit_kvs)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should trace a dataset insert and count' do
|
111
|
+
items = PG_DB[:items]
|
112
|
+
# Preload the primary key to avoid breaking tests with the seemingly
|
113
|
+
# random lookup (random due to random test order)
|
114
|
+
PG_DB.primary_key(:items)
|
115
|
+
|
116
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
117
|
+
items.insert(:name => 'abc', :price => 2.514)
|
118
|
+
items.count
|
119
|
+
end
|
120
|
+
|
121
|
+
traces = get_all_traces
|
122
|
+
|
123
|
+
traces.count.must_equal 6
|
124
|
+
validate_outer_layers(traces, 'sequel_test')
|
125
|
+
|
126
|
+
validate_event_keys(traces[1], @entry_kvs)
|
127
|
+
|
128
|
+
# SQL column/value order can vary between Ruby and gem versions
|
129
|
+
# Use must_include to test against one or the other
|
130
|
+
[
|
131
|
+
"INSERT INTO \"items\" (\"price\", \"name\") VALUES (2.514, 'abc') RETURNING \"id\"",
|
132
|
+
"INSERT INTO \"items\" (\"name\", \"price\") VALUES ('abc', 2.514) RETURNING \"id\""
|
133
|
+
].must_include traces[1]['Query']
|
134
|
+
|
135
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
136
|
+
traces[2]['Layer'].must_equal "sequel"
|
137
|
+
traces[2]['Label'].must_equal "exit"
|
138
|
+
traces[3]['Query'].downcase.must_equal "select count(*) as \"count\" from \"items\" limit 1"
|
139
|
+
validate_event_keys(traces[4], @exit_kvs)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should trace a dataset insert and obey query privacy' do
|
143
|
+
TraceView::Config[:sanitize_sql] = true
|
144
|
+
items = PG_DB[:items]
|
145
|
+
# Preload the primary key to avoid breaking tests with the seemingly
|
146
|
+
# random lookup (random due to random test order)
|
147
|
+
PG_DB.primary_key(:items)
|
148
|
+
|
149
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
150
|
+
items.insert(:name => 'abc', :price => 2.514461383352462)
|
151
|
+
end
|
152
|
+
|
153
|
+
traces = get_all_traces
|
154
|
+
|
155
|
+
traces.count.must_equal 4
|
156
|
+
validate_outer_layers(traces, 'sequel_test')
|
157
|
+
|
158
|
+
validate_event_keys(traces[1], @entry_kvs)
|
159
|
+
|
160
|
+
# SQL column/value order can vary between Ruby and gem versions
|
161
|
+
# Use must_include to test against one or the other
|
162
|
+
[
|
163
|
+
"INSERT INTO \"items\" (\"price\", \"name\") VALUES (?, ?) RETURNING \"id\"",
|
164
|
+
"INSERT INTO \"items\" (\"name\", \"price\") VALUES (?, ?) RETURNING \"id\""
|
165
|
+
].must_include traces[1]['Query']
|
166
|
+
|
167
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
168
|
+
validate_event_keys(traces[2], @exit_kvs)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should trace a dataset filter' do
|
172
|
+
items = PG_DB[:items]
|
173
|
+
items.count
|
174
|
+
|
175
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
176
|
+
items.filter(:name => 'abc').all
|
177
|
+
end
|
178
|
+
|
179
|
+
traces = get_all_traces
|
180
|
+
|
181
|
+
traces.count.must_equal 4
|
182
|
+
validate_outer_layers(traces, 'sequel_test')
|
183
|
+
|
184
|
+
validate_event_keys(traces[1], @entry_kvs)
|
185
|
+
traces[1]['Query'].must_equal "SELECT * FROM \"items\" WHERE (\"name\" = 'abc')"
|
186
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
187
|
+
validate_event_keys(traces[2], @exit_kvs)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should trace create table' do
|
191
|
+
# Drop the table if it already exists
|
192
|
+
PG_DB.drop_table(:fake) if PG_DB.table_exists?(:fake)
|
193
|
+
|
194
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
195
|
+
PG_DB.create_table :fake do
|
196
|
+
primary_key :id
|
197
|
+
String :name
|
198
|
+
Float :price
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
traces = get_all_traces
|
203
|
+
|
204
|
+
traces.count.must_equal 4
|
205
|
+
validate_outer_layers(traces, 'sequel_test')
|
206
|
+
|
207
|
+
validate_event_keys(traces[1], @entry_kvs)
|
208
|
+
traces[1]['Query'].must_equal "CREATE TABLE \"fake\" (\"id\" serial PRIMARY KEY, \"name\" text, \"price\" double precision)"
|
209
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
210
|
+
validate_event_keys(traces[2], @exit_kvs)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should trace add index' do
|
214
|
+
# Drop the table if it already exists
|
215
|
+
PG_DB.drop_table(:fake) if PG_DB.table_exists?(:fake)
|
216
|
+
|
217
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
218
|
+
PG_DB.create_table :fake do
|
219
|
+
primary_key :id
|
220
|
+
String :name
|
221
|
+
Float :price
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
traces = get_all_traces
|
226
|
+
|
227
|
+
traces.count.must_equal 4
|
228
|
+
validate_outer_layers(traces, 'sequel_test')
|
229
|
+
|
230
|
+
validate_event_keys(traces[1], @entry_kvs)
|
231
|
+
traces[1]['Query'].must_equal "CREATE TABLE \"fake\" (\"id\" serial PRIMARY KEY, \"name\" text, \"price\" double precision)"
|
232
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
233
|
+
validate_event_keys(traces[2], @exit_kvs)
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should capture and report exceptions' do
|
237
|
+
begin
|
238
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
239
|
+
PG_DB.run("this is bad sql")
|
240
|
+
end
|
241
|
+
rescue
|
242
|
+
# Do nothing - we're testing exception logging
|
243
|
+
end
|
244
|
+
|
245
|
+
traces = get_all_traces
|
246
|
+
|
247
|
+
traces.count.must_equal 5
|
248
|
+
validate_outer_layers(traces, 'sequel_test')
|
249
|
+
|
250
|
+
validate_event_keys(traces[1], @entry_kvs)
|
251
|
+
traces[1]['Query'].must_equal "this is bad sql"
|
252
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
253
|
+
traces[2]['Layer'].must_equal "sequel"
|
254
|
+
traces[2]['Label'].must_equal "error"
|
255
|
+
traces[2].has_key?('Backtrace').must_equal true
|
256
|
+
traces[2]['ErrorClass'].must_equal "Sequel::DatabaseError"
|
257
|
+
validate_event_keys(traces[3], @exit_kvs)
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should trace placeholder queries with bound vars' do
|
261
|
+
items = PG_DB[:items]
|
262
|
+
items.count
|
263
|
+
|
264
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
265
|
+
ds = items.where(:name=>:$n)
|
266
|
+
ds.call(:select, :n=>'abc')
|
267
|
+
ds.call(:delete, :n=>'cba')
|
268
|
+
end
|
269
|
+
|
270
|
+
traces = get_all_traces
|
271
|
+
|
272
|
+
traces.count.must_equal 6
|
273
|
+
validate_outer_layers(traces, 'sequel_test')
|
274
|
+
|
275
|
+
validate_event_keys(traces[1], @entry_kvs)
|
276
|
+
traces[1]['Query'].must_equal "SELECT * FROM \"items\" WHERE (\"name\" = $1)"
|
277
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
278
|
+
traces[3]['Query'].must_equal "DELETE FROM \"items\" WHERE (\"name\" = $1)"
|
279
|
+
traces[3].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
280
|
+
validate_event_keys(traces[2], @exit_kvs)
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'should trace prepared statements' do
|
284
|
+
ds = PG_DB[:items].filter(:name=>:$n)
|
285
|
+
ps = ds.prepare(:select, :select_by_name)
|
286
|
+
|
287
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
288
|
+
ps.call(:n=>'abc')
|
289
|
+
end
|
290
|
+
|
291
|
+
traces = get_all_traces
|
292
|
+
|
293
|
+
traces.count.must_equal 4
|
294
|
+
validate_outer_layers(traces, 'sequel_test')
|
295
|
+
|
296
|
+
validate_event_keys(traces[1], @entry_kvs)
|
297
|
+
traces[1]['Query'].must_equal "select_by_name"
|
298
|
+
if RUBY_VERSION < "1.9"
|
299
|
+
traces[1]['QueryArgs'].must_equal "abc"
|
300
|
+
else
|
301
|
+
traces[1]['QueryArgs'].must_equal "[\"abc\"]"
|
302
|
+
end
|
303
|
+
traces[1]['IsPreparedStatement'].must_equal "true"
|
304
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
305
|
+
validate_event_keys(traces[2], @exit_kvs)
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'should trace prep\'d stmnts and obey query privacy' do
|
309
|
+
TraceView::Config[:sanitize_sql] = true
|
310
|
+
ds = PG_DB[:items].filter(:name=>:$n)
|
311
|
+
ps = ds.prepare(:select, :select_by_name)
|
312
|
+
|
313
|
+
TraceView::API.start_trace('sequel_test', '', {}) do
|
314
|
+
ps.call(:n=>'abc')
|
315
|
+
end
|
316
|
+
|
317
|
+
traces = get_all_traces
|
318
|
+
|
319
|
+
traces.count.must_equal 4
|
320
|
+
validate_outer_layers(traces, 'sequel_test')
|
321
|
+
|
322
|
+
validate_event_keys(traces[1], @entry_kvs)
|
323
|
+
traces[1]['Query'].must_equal "select_by_name"
|
324
|
+
traces[1]['QueryArgs'].must_equal nil
|
325
|
+
traces[1]['IsPreparedStatement'].must_equal "true"
|
326
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:sequel][:collect_backtraces]
|
327
|
+
validate_event_keys(traces[2], @exit_kvs)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
# Copyright (c) 2015 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
require 'minitest_helper'
|
5
|
+
require 'rack'
|
6
|
+
|
7
|
+
describe "Typhoeus" do
|
8
|
+
before do
|
9
|
+
clear_all_traces
|
10
|
+
@collect_backtraces = TraceView::Config[:typhoeus][:collect_backtraces]
|
11
|
+
@log_args = TraceView::Config[:typhoeus][:log_args]
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
TraceView::Config[:typhoeus][:collect_backtraces] = @collect_backtraces
|
16
|
+
TraceView::Config[:typhoeus][:log_args] = @log_args
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Typhoeus should be defined and ready' do
|
20
|
+
defined?(::Typhoeus::Request::Operations).wont_match nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'Typhoeus should have traceview methods defined' do
|
24
|
+
[ :run_with_traceview ].each do |m|
|
25
|
+
::Typhoeus::Request::Operations.method_defined?(m).must_equal true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should trace a typhoeus request' do
|
30
|
+
TraceView::API.start_trace('typhoeus_test') do
|
31
|
+
Typhoeus.get("http://127.0.0.1:8101/")
|
32
|
+
end
|
33
|
+
|
34
|
+
traces = get_all_traces
|
35
|
+
traces.count.must_equal 8
|
36
|
+
|
37
|
+
valid_edges?(traces).must_equal true
|
38
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
39
|
+
|
40
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
41
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
42
|
+
|
43
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
44
|
+
traces[5]['Label'].must_equal 'info'
|
45
|
+
traces[5]['IsService'].must_equal 1
|
46
|
+
traces[5]['RemoteURL'].must_equal 'http://127.0.0.1:8101/'
|
47
|
+
traces[5]['HTTPMethod'].must_equal 'GET'
|
48
|
+
traces[5]['HTTPStatus'].must_equal 200
|
49
|
+
|
50
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
51
|
+
traces[6]['Label'].must_equal 'exit'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should trace a typhoeus POST request' do
|
55
|
+
TraceView::API.start_trace('typhoeus_test') do
|
56
|
+
Typhoeus.post("127.0.0.1:8101/",
|
57
|
+
:body => { :key => "traceview-ruby-fake", :content => "traceview-ruby repo test suite"})
|
58
|
+
end
|
59
|
+
|
60
|
+
traces = get_all_traces
|
61
|
+
traces.count.must_equal 8
|
62
|
+
|
63
|
+
valid_edges?(traces).must_equal true
|
64
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
65
|
+
|
66
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
67
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
68
|
+
|
69
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
70
|
+
traces[5]['Label'].must_equal 'info'
|
71
|
+
traces[5]['IsService'].must_equal 1
|
72
|
+
traces[5]['RemoteURL'].casecmp('http://127.0.0.1:8101/').must_equal 0
|
73
|
+
traces[5]['HTTPMethod'].must_equal 'POST'
|
74
|
+
traces[5]['HTTPStatus'].must_equal 200
|
75
|
+
|
76
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
77
|
+
traces[6]['Label'].must_equal 'exit'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should trace a typhoeus PUT request' do
|
81
|
+
TraceView::API.start_trace('typhoeus_test') do
|
82
|
+
Typhoeus.put("http://127.0.0.1:8101/",
|
83
|
+
:body => { :key => "traceview-ruby-fake", :content => "traceview-ruby repo test suite"})
|
84
|
+
end
|
85
|
+
|
86
|
+
traces = get_all_traces
|
87
|
+
traces.count.must_equal 8
|
88
|
+
|
89
|
+
valid_edges?(traces).must_equal true
|
90
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
91
|
+
|
92
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
93
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
94
|
+
|
95
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
96
|
+
traces[5]['Label'].must_equal 'info'
|
97
|
+
traces[5]['IsService'].must_equal 1
|
98
|
+
traces[5]['RemoteURL'].must_equal 'http://127.0.0.1:8101/'
|
99
|
+
traces[5]['HTTPMethod'].must_equal 'PUT'
|
100
|
+
traces[5]['HTTPStatus'].must_equal 200
|
101
|
+
|
102
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
103
|
+
traces[6]['Label'].must_equal 'exit'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should trace a typhoeus DELETE request' do
|
107
|
+
TraceView::API.start_trace('typhoeus_test') do
|
108
|
+
Typhoeus.delete("http://127.0.0.1:8101/")
|
109
|
+
end
|
110
|
+
|
111
|
+
traces = get_all_traces
|
112
|
+
traces.count.must_equal 8
|
113
|
+
|
114
|
+
valid_edges?(traces).must_equal true
|
115
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
116
|
+
|
117
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
118
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
119
|
+
|
120
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
121
|
+
traces[5]['Label'].must_equal 'info'
|
122
|
+
traces[5]['IsService'].must_equal 1
|
123
|
+
traces[5]['RemoteURL'].must_equal 'http://127.0.0.1:8101/'
|
124
|
+
traces[5]['HTTPMethod'].must_equal 'DELETE'
|
125
|
+
traces[5]['HTTPStatus'].must_equal 200
|
126
|
+
|
127
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
128
|
+
traces[6]['Label'].must_equal 'exit'
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should trace a typhoeus HEAD request' do
|
132
|
+
TraceView::API.start_trace('typhoeus_test') do
|
133
|
+
Typhoeus.head("http://127.0.0.1:8101/")
|
134
|
+
end
|
135
|
+
|
136
|
+
traces = get_all_traces
|
137
|
+
traces.count.must_equal 8
|
138
|
+
|
139
|
+
valid_edges?(traces).must_equal true
|
140
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
141
|
+
|
142
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
143
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
144
|
+
|
145
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
146
|
+
traces[5]['Label'].must_equal 'info'
|
147
|
+
traces[5]['IsService'].must_equal 1
|
148
|
+
traces[5]['RemoteURL'].must_equal 'http://127.0.0.1:8101/'
|
149
|
+
traces[5]['HTTPMethod'].must_equal 'HEAD'
|
150
|
+
traces[5]['HTTPStatus'].must_equal 200
|
151
|
+
|
152
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
153
|
+
traces[6]['Label'].must_equal 'exit'
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should trace a typhoeus GET request to an instr\'d app' do
|
157
|
+
TraceView::API.start_trace('typhoeus_test') do
|
158
|
+
Typhoeus.get("127.0.0.1:8101/")
|
159
|
+
end
|
160
|
+
|
161
|
+
traces = get_all_traces
|
162
|
+
traces.count.must_equal 8
|
163
|
+
|
164
|
+
valid_edges?(traces).must_equal true
|
165
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
166
|
+
|
167
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
168
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
169
|
+
|
170
|
+
traces[5]['Layer'].must_equal 'typhoeus'
|
171
|
+
traces[5]['Label'].must_equal 'info'
|
172
|
+
traces[5]['IsService'].must_equal 1
|
173
|
+
traces[5]['RemoteURL'].casecmp('http://127.0.0.1:8101/').must_equal 0
|
174
|
+
traces[5]['HTTPMethod'].must_equal 'GET'
|
175
|
+
traces[5]['HTTPStatus'].must_equal 200
|
176
|
+
|
177
|
+
traces[6]['Layer'].must_equal 'typhoeus'
|
178
|
+
traces[6]['Label'].must_equal 'exit'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should trace a typhoeus GET request with DNS error' do
|
182
|
+
TraceView::API.start_trace('typhoeus_test') do
|
183
|
+
Typhoeus.get("thisdomaindoesntexisthopefully.asdf/products/traceview/")
|
184
|
+
end
|
185
|
+
|
186
|
+
traces = get_all_traces
|
187
|
+
traces.count.must_equal 6
|
188
|
+
|
189
|
+
valid_edges?(traces).must_equal true
|
190
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
191
|
+
|
192
|
+
traces[1]['Layer'].must_equal 'typhoeus'
|
193
|
+
traces[1].key?('Backtrace').must_equal TraceView::Config[:typhoeus][:collect_backtraces]
|
194
|
+
|
195
|
+
traces[2]['Layer'].must_equal 'typhoeus'
|
196
|
+
traces[2]['Label'].must_equal 'error'
|
197
|
+
|
198
|
+
traces[3]['Layer'].must_equal 'typhoeus'
|
199
|
+
traces[3]['Label'].must_equal 'info'
|
200
|
+
traces[3]['IsService'].must_equal 1
|
201
|
+
traces[3]['RemoteURL'].casecmp('http://thisdomaindoesntexisthopefully.asdf/products/traceview/').must_equal 0
|
202
|
+
traces[3]['HTTPMethod'].must_equal 'GET'
|
203
|
+
traces[3]['HTTPStatus'].must_equal 0
|
204
|
+
|
205
|
+
traces[3]['Layer'].must_equal 'typhoeus'
|
206
|
+
traces[3]['Label'].must_equal 'info'
|
207
|
+
|
208
|
+
traces[4]['Layer'].must_equal 'typhoeus'
|
209
|
+
traces[4]['Label'].must_equal 'exit'
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should trace parallel typhoeus requests' do
|
213
|
+
TraceView::API.start_trace('typhoeus_test') do
|
214
|
+
hydra = Typhoeus::Hydra.hydra
|
215
|
+
|
216
|
+
first_request = Typhoeus::Request.new("127.0.0.1:8101/products/traceview/")
|
217
|
+
second_request = Typhoeus::Request.new("127.0.0.1:8101/products/")
|
218
|
+
third_request = Typhoeus::Request.new("127.0.0.1:8101/")
|
219
|
+
|
220
|
+
hydra.queue first_request
|
221
|
+
hydra.queue second_request
|
222
|
+
hydra.queue third_request
|
223
|
+
|
224
|
+
hydra.run
|
225
|
+
end
|
226
|
+
|
227
|
+
traces = get_all_traces
|
228
|
+
traces.count.must_equal 13
|
229
|
+
|
230
|
+
# FIXME: Until we support async tracing for Typhoeus, this won't
|
231
|
+
# work.
|
232
|
+
# valid_edges?(traces).must_equal true
|
233
|
+
validate_outer_layers(traces, 'typhoeus_test')
|
234
|
+
|
235
|
+
traces[1]['Layer'].must_equal 'typhoeus_hydra'
|
236
|
+
traces[1]['Label'].must_equal 'entry'
|
237
|
+
|
238
|
+
traces[11]['Layer'].must_equal 'typhoeus_hydra'
|
239
|
+
traces[11]['Label'].must_equal 'exit'
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should obey :log_args setting when true' do
|
243
|
+
TraceView::Config[:typhoeus][:log_args] = true
|
244
|
+
|
245
|
+
TraceView::API.start_trace('typhoeus_test') do
|
246
|
+
Typhoeus.get("127.0.0.1:8101/?blah=1")
|
247
|
+
end
|
248
|
+
|
249
|
+
traces = get_all_traces
|
250
|
+
traces[5]['RemoteURL'].casecmp('http://127.0.0.1:8101/?blah=1').must_equal 0
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should obey :log_args setting when false' do
|
254
|
+
TraceView::Config[:typhoeus][:log_args] = false
|
255
|
+
|
256
|
+
TraceView::API.start_trace('typhoeus_test') do
|
257
|
+
Typhoeus.get("127.0.0.1:8101/?blah=1")
|
258
|
+
end
|
259
|
+
|
260
|
+
traces = get_all_traces
|
261
|
+
traces[5]['RemoteURL'].casecmp('http://127.0.0.1:8101/').must_equal 0
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should obey :collect_backtraces setting when true' do
|
265
|
+
TraceView::Config[:typhoeus][:collect_backtraces] = true
|
266
|
+
|
267
|
+
TraceView::API.start_trace('typhoeus_test') do
|
268
|
+
Typhoeus.get("127.0.0.1:8101/?blah=1")
|
269
|
+
end
|
270
|
+
|
271
|
+
traces = get_all_traces
|
272
|
+
layer_has_key(traces, 'typhoeus', 'Backtrace')
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should obey :collect_backtraces setting when false' do
|
276
|
+
TraceView::Config[:typhoeus][:collect_backtraces] = false
|
277
|
+
|
278
|
+
TraceView::API.start_trace('typhoeus_test') do
|
279
|
+
Typhoeus.get("127.0.0.1:8101/")
|
280
|
+
end
|
281
|
+
|
282
|
+
traces = get_all_traces
|
283
|
+
layer_doesnt_have_key(traces, 'typhoeus', 'Backtrace')
|
284
|
+
end
|
285
|
+
end
|