oboe 2.7.6.2-java → 2.7.7.1-java

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04dd4cedfddf93bfec87da8c4cc8ce567774aa8e
4
- data.tar.gz: fb4f5faf217e9182c39d5288ba011369f0f8775f
3
+ metadata.gz: 44247dad53ec61599ece5203a8fccc1063797e33
4
+ data.tar.gz: 1ae26684562b3282b90506580c0c203b4e9ce86f
5
5
  SHA512:
6
- metadata.gz: 2dcefcf8a35fe0e4bec770b9eec4a54cb00def48628c3fada333eaa28d0d38b3f3f0ef38a00bda3f60ac83e488736c70c6cf541dc203b9d9145643202d6bf1be
7
- data.tar.gz: e5d5c5998ba93f4bb21b6d7b44294291ae486edaa6959071e972f1a17cfc2bef3c4f9fdfa873da946116a2829921becd71b687d4f1a79380b947bdabd202a3ce
6
+ metadata.gz: 7cada019bdb599b445c970ebc5c66bdcdb74447c91b24c064b4821611db33fd47c930167ab4db96ab4f318cd2c2d7776b4ed763aa4f5e6ba6d62f1500c7bc023
7
+ data.tar.gz: abed2fc5e5fb5c34b661369f0c750b627143c2536c6e4d211998a03fc086a770807f05fd01a18bb6738037bf3dc0dfc5f89869ba3a15f514fc3c8bb427928e41
@@ -28,8 +28,6 @@ before_install:
28
28
  - echo "127.0.0.1 " `hostname` | sudo tee /etc/hosts
29
29
  - sudo service cassandra start
30
30
 
31
- before_script: sleep 10
32
-
33
31
  install:
34
32
  - wget https://www.tracelytics.com/install_tracelytics.sh
35
33
  - sudo sh ./install_tracelytics.sh f51e2a43-0ee5-4851-8a54-825773b3218e
@@ -38,6 +36,9 @@ install:
38
36
  before_script:
39
37
  - bundle install --without development
40
38
  - bundle exec rake compile
39
+ - psql -c 'create database travis_ci_test;' -U postgres
40
+ - mysql -e 'create database travis_ci_test;'
41
+ - sleep 10
41
42
 
42
43
  script: "bundle exec rake test"
43
44
 
data/Gemfile CHANGED
@@ -30,9 +30,20 @@ gem 'redis'
30
30
  gem 'faraday'
31
31
  gem 'excon'
32
32
  gem 'typhoeus'
33
+ gem 'sequel'
34
+
35
+ # Database adapter gems needed by sequel
36
+ if defined?(JRUBY_VERSION)
37
+ gem 'jdbc-postgresql'
38
+ gem 'jdbc-mysql'
39
+ else
40
+ gem 'mysql'
41
+ gem 'mysql2'
42
+ gem 'pg'
43
+ end
33
44
 
34
45
  if RUBY_VERSION >= '1.9'
35
- gem 'moped', '1.3.2'
46
+ gem 'moped'
36
47
  gem 'eventmachine'
37
48
  gem 'em-synchrony'
38
49
  gem 'em-http-request'
data/Rakefile CHANGED
@@ -97,6 +97,7 @@ desc "Rebuild the gem's c extension"
97
97
  task :recompile => [ :distclean, :compile ]
98
98
 
99
99
  task :console do
100
+ ENV['OBOE_GEM_VERBOSE'] = 'true'
100
101
  Bundler.require(:default, :development)
101
102
  Oboe::Config[:tracing_mode] = :always
102
103
  ARGV.clear
@@ -153,6 +153,9 @@ module Oboe
153
153
  event.addInfo('Layer', layer.to_s) if layer
154
154
  event.addInfo('Label', label.to_s)
155
155
 
156
+ Oboe.layer = layer if label == 'entry'
157
+ Oboe.layer = nil if label == 'exit'
158
+
156
159
  opts.each do |k, v|
157
160
  event.addInfo(k.to_s, v.to_s) if valid_key? k
158
161
  end if !opts.nil? && opts.any?
@@ -33,6 +33,7 @@ module OboeBase
33
33
  attr_accessor :loaded
34
34
  attr_accessor :sample_source
35
35
  attr_accessor :sample_rate
36
+ thread_local :layer
36
37
  thread_local :layer_op
37
38
 
38
39
  # The following accessors indicate the incoming tracing state received
@@ -99,6 +100,17 @@ module OboeBase
99
100
  end
100
101
  end
101
102
 
103
+ ##
104
+ # tracing_layer?
105
+ #
106
+ # Queries the thread local variable about the current
107
+ # layer being traced. This is used in cases of recursive
108
+ # operation tracing or one instrumented operation calling another.
109
+ #
110
+ def tracing_layer?(layer)
111
+ return Oboe.layer == layer
112
+ end
113
+
102
114
  ##
103
115
  # tracing_layer_op?
104
116
  #
@@ -13,7 +13,7 @@ module Oboe
13
13
 
14
14
  @@instrumentation = [:action_controller, :action_view, :active_record,
15
15
  :cassandra, :dalli, :em_http_request, :faraday, :nethttp, :memcached,
16
- :memcache, :mongo, :moped, :rack, :redis, :resque, :typhoeus]
16
+ :memcache, :mongo, :moped, :rack, :redis, :resque, :sequel, :typhoeus]
17
17
  ##
18
18
  # Return the raw nested hash.
19
19
  #
@@ -48,6 +48,7 @@ module Oboe
48
48
  Oboe::Config[:nethttp][:collect_backtraces] = true
49
49
  Oboe::Config[:redis][:collect_backtraces] = false
50
50
  Oboe::Config[:resque][:collect_backtraces] = true
51
+ Oboe::Config[:sequel][:collect_backtraces] = true
51
52
  Oboe::Config[:typhoeus][:collect_backtraces] = false
52
53
 
53
54
  # Special instrument specific flags
@@ -0,0 +1,159 @@
1
+ module Oboe
2
+ module Inst
3
+ module Sequel
4
+ def extract_trace_details(sql, opts)
5
+ kvs = {}
6
+
7
+ if Oboe::Config[:sanitize_sql]
8
+ # Sanitize SQL and don't report binds
9
+ if sql.is_a?(Symbol)
10
+ kvs[:Query] = sql
11
+ else
12
+ kvs[:Query] = sql.gsub(/('[\s\S][^\']*\'|\d*\.\d*)/, '?')
13
+ end
14
+ else
15
+ # Report raw SQL and any binds if they exist
16
+ kvs[:Query] = sql.to_s
17
+ kvs[:QueryArgs] = opts[:arguments] if opts.is_a?(Hash) and opts.key?(:arguments)
18
+ end
19
+ kvs[:IsPreparedStatement] = true if sql.is_a?(Symbol)
20
+
21
+ kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:sequel][:collect_backtraces]
22
+
23
+ if ::Sequel::VERSION < '3.41.0' && !(self.class.to_s =~ /Dataset$/)
24
+ db_opts = @opts
25
+ elsif @pool
26
+ db_opts = @pool.db.opts
27
+ else
28
+ db_opts = @db.opts
29
+ end
30
+
31
+ kvs[:Database] = db_opts[:database]
32
+ kvs[:RemoteHost] = db_opts[:host]
33
+ kvs[:RemotePort] = db_opts[:port] if db_opts.key?(:port)
34
+ kvs[:Flavor] = db_opts[:adapter]
35
+ rescue => e
36
+ Oboe.logger.debug "[oboe/debug Error capturing Sequel KVs: #{e.message}" if Oboe::Config[:verbose]
37
+ ensure
38
+ return kvs
39
+ end
40
+ end
41
+
42
+ module SequelDatabase
43
+ def self.included(klass)
44
+ ::Oboe::Util.method_alias(klass, :run, ::Sequel::Database)
45
+ ::Oboe::Util.method_alias(klass, :execute_ddl, ::Sequel::Database)
46
+ ::Oboe::Util.method_alias(klass, :execute_dui, ::Sequel::Database)
47
+ ::Oboe::Util.method_alias(klass, :execute_insert, ::Sequel::Database)
48
+ end
49
+
50
+ def run_with_oboe(sql, opts=::Sequel::OPTS)
51
+ kvs = extract_trace_details(sql, opts)
52
+
53
+ Oboe::API.log_entry('sequel', kvs)
54
+
55
+ run_without_oboe(sql, opts)
56
+ rescue => e
57
+ Oboe::API.log_exception('sequel', e)
58
+ raise e
59
+ ensure
60
+ Oboe::API.log_exit('sequel')
61
+ end
62
+
63
+ def exec_with_oboe(method, sql, opts=::Sequel::OPTS, &block)
64
+ kvs = extract_trace_details(sql, opts)
65
+
66
+ Oboe::API.log_entry('sequel', kvs)
67
+
68
+ send(method, sql, opts, &block)
69
+ rescue => e
70
+ Oboe::API.log_exception('sequel', e)
71
+ raise e
72
+ ensure
73
+ Oboe::API.log_exit('sequel')
74
+ end
75
+
76
+ def execute_ddl_with_oboe(sql, opts=::Sequel::OPTS, &block)
77
+ # If we're already tracing a sequel operation, then this call likely came
78
+ # from Sequel::Dataset. In this case, just pass it on.
79
+ return execute_ddl_without_oboe(sql, opts, &block) if Oboe.tracing_layer?('sequel')
80
+
81
+ exec_with_oboe(:execute_ddl_without_oboe, sql, opts, &block)
82
+ end
83
+
84
+ def execute_dui_with_oboe(sql, opts=::Sequel::OPTS, &block)
85
+ # If we're already tracing a sequel operation, then this call likely came
86
+ # from Sequel::Dataset. In this case, just pass it on.
87
+ return execute_dui_without_oboe(sql, opts, &block) if Oboe.tracing_layer?('sequel')
88
+
89
+ exec_with_oboe(:execute_dui_without_oboe, sql, opts, &block)
90
+ end
91
+
92
+ def execute_insert_with_oboe(sql, opts=::Sequel::OPTS, &block)
93
+ # If we're already tracing a sequel operation, then this call likely came
94
+ # from Sequel::Dataset. In this case, just pass it on.
95
+ return execute_insert_without_oboe(sql, opts, &block) if Oboe.tracing_layer?('sequel')
96
+
97
+ exec_with_oboe(:execute_insert_without_oboe, sql, opts, &block)
98
+ end
99
+ end # module SequelDatabase
100
+
101
+ module SequelDataset
102
+
103
+ def self.included(klass)
104
+ ::Oboe::Util.method_alias(klass, :execute, ::Sequel::Dataset)
105
+ ::Oboe::Util.method_alias(klass, :execute_ddl, ::Sequel::Dataset)
106
+ ::Oboe::Util.method_alias(klass, :execute_dui, ::Sequel::Dataset)
107
+ ::Oboe::Util.method_alias(klass, :execute_insert, ::Sequel::Dataset)
108
+ end
109
+
110
+ def exec_with_oboe(method, sql, opts=::Sequel::OPTS, &block)
111
+ kvs = extract_trace_details(sql, opts)
112
+
113
+ Oboe::API.log_entry('sequel', kvs)
114
+
115
+ send(method, sql, opts, &block)
116
+ rescue => e
117
+ Oboe::API.log_exception('sequel', e)
118
+ raise e
119
+ ensure
120
+ Oboe::API.log_exit('sequel')
121
+ end
122
+
123
+ def execute_with_oboe(sql, opts=::Sequel::OPTS, &block)
124
+ exec_with_oboe(:execute_without_oboe, sql, opts, &block)
125
+ end
126
+
127
+ def execute_ddl_with_oboe(sql, opts=::Sequel::OPTS, &block)
128
+ exec_with_oboe(:execute_ddl_without_oboe, sql, opts, &block)
129
+ end
130
+
131
+ def execute_dui_with_oboe(sql, opts=::Sequel::OPTS, &block)
132
+ exec_with_oboe(:execute_dui_without_oboe, sql, opts, &block)
133
+ end
134
+
135
+ def execute_insert_with_oboe(sql, opts=::Sequel::OPTS, &block)
136
+ exec_with_oboe(:execute_insert_without_oboe, sql, opts, &block)
137
+ end
138
+
139
+ end # module SequelDataset
140
+ end # module Inst
141
+ end # module Oboe
142
+
143
+ if Oboe::Config[:sequel][:enabled]
144
+ if defined?(::Sequel) && ::Sequel::VERSION < "4.0.0"
145
+ # For versions before 4.0.0, Sequel::OPTS wasn't defined.
146
+ # Define it as an empty hash for backwards compatibility.
147
+ module ::Sequel
148
+ OPTS = {}
149
+ end
150
+ end
151
+
152
+ if defined?(::Sequel)
153
+ Oboe.logger.info '[oboe/loading] Instrumenting sequel' if Oboe::Config[:verbose]
154
+ ::Oboe::Util.send_include(::Sequel::Database, ::Oboe::Inst::Sequel)
155
+ ::Oboe::Util.send_include(::Sequel::Database, ::Oboe::Inst::SequelDatabase)
156
+ ::Oboe::Util.send_include(::Sequel::Dataset, ::Oboe::Inst::Sequel)
157
+ ::Oboe::Util.send_include(::Sequel::Dataset, ::Oboe::Inst::SequelDataset)
158
+ end
159
+ end
@@ -46,7 +46,8 @@ module Oboe
46
46
  alias_method "#{method}", with_oboe
47
47
  end
48
48
  end
49
- else Oboe.logger.warn "[oboe/loading] Couldn't properly instrument #{name}. Partial traces may occur."
49
+ else
50
+ Oboe.logger.warn "[oboe/loading] Couldn't properly instrument #{name}.#{method}. Partial traces may occur."
50
51
  end
51
52
  end
52
53
 
@@ -8,8 +8,8 @@ module Oboe
8
8
  module Version
9
9
  MAJOR = 2
10
10
  MINOR = 7
11
- PATCH = 6
12
- BUILD = 2
11
+ PATCH = 7
12
+ BUILD = 1
13
13
 
14
14
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
15
15
  end
@@ -0,0 +1,320 @@
1
+ require 'minitest_helper'
2
+
3
+ unless defined?(JRUBY_VERSION)
4
+
5
+ if ENV.key?('TRAVIS_MYSQL_PASS')
6
+ MYSQL2_DB = Sequel.connect("mysql2://root:#{ENV['TRAVIS_MYSQL_PASS']}@127.0.0.1:3306/travis_ci_test")
7
+ else
8
+ MYSQL2_DB = Sequel.connect('mysql2://root@127.0.0.1:3306/travis_ci_test')
9
+ end
10
+
11
+ unless MYSQL2_DB.table_exists?(:items)
12
+ MYSQL2_DB.create_table :items do
13
+ primary_key :id
14
+ String :name
15
+ Float :price
16
+ end
17
+ end
18
+
19
+ describe "Oboe::Inst::Sequel (mysql2)" 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' => '3306' }
30
+
31
+ @exit_kvs = { 'Layer' => 'sequel', 'Label' => 'exit' }
32
+ @collect_backtraces = Oboe::Config[:sequel][:collect_backtraces]
33
+ @sanitize_sql = Oboe::Config[:sanitize_sql]
34
+ end
35
+
36
+ after do
37
+ Oboe::Config[:sequel][:collect_backtraces] = @collect_backtraces
38
+ Oboe::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 oboe methods defined' do
46
+ # Sequel::Database
47
+ ::Sequel::Database.method_defined?(:run_with_oboe).must_equal true
48
+
49
+ # Sequel::Dataset
50
+ ::Sequel::Dataset.method_defined?(:execute_with_oboe).must_equal true
51
+ ::Sequel::Dataset.method_defined?(:execute_ddl_with_oboe).must_equal true
52
+ ::Sequel::Dataset.method_defined?(:execute_dui_with_oboe).must_equal true
53
+ ::Sequel::Dataset.method_defined?(:execute_insert_with_oboe).must_equal true
54
+ end
55
+
56
+ it "should obey :collect_backtraces setting when true" do
57
+ Oboe::Config[:sequel][:collect_backtraces] = true
58
+
59
+ Oboe::API.start_trace('sequel_test', '', {}) do
60
+ MYSQL2_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
+ Oboe::Config[:sequel][:collect_backtraces] = false
69
+
70
+ Oboe::API.start_trace('sequel_test', '', {}) do
71
+ MYSQL2_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 MYSQL2_DB.run insert' do
79
+ Oboe::API.start_trace('sequel_test', '', {}) do
80
+ MYSQL2_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 Oboe::Config[:sequel][:collect_backtraces]
91
+ validate_event_keys(traces[2], @exit_kvs)
92
+ end
93
+
94
+ it 'should trace MYSQL2_DB.run select' do
95
+ Oboe::API.start_trace('sequel_test', '', {}) do
96
+ MYSQL2_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 Oboe::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 = MYSQL2_DB[:items]
112
+ items.count
113
+
114
+ Oboe::API.start_trace('sequel_test', '', {}) do
115
+ items.insert(:name => 'abc', :price => 2.514461383352462)
116
+ items.count
117
+ end
118
+
119
+ traces = get_all_traces
120
+
121
+ traces.count.must_equal 6
122
+ validate_outer_layers(traces, 'sequel_test')
123
+
124
+ validate_event_keys(traces[1], @entry_kvs)
125
+ if RUBY_VERSION < "1.9"
126
+ traces[1]['Query'].must_equal "INSERT INTO `items` (`price`, `name`) VALUES (2.51446138335246, 'abc')"
127
+ else
128
+ traces[1]['Query'].must_equal "INSERT INTO `items` (`name`, `price`) VALUES ('abc', 2.514461383352462)"
129
+ end
130
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
131
+ traces[2]['Layer'].must_equal "sequel"
132
+ traces[2]['Label'].must_equal "exit"
133
+ traces[3]['Query'].downcase.must_equal "select count(*) as `count` from `items` limit 1"
134
+ validate_event_keys(traces[4], @exit_kvs)
135
+ end
136
+
137
+ it 'should trace a dataset insert and obey query privacy' do
138
+ Oboe::Config[:sanitize_sql] = true
139
+ items = MYSQL2_DB[:items]
140
+ items.count
141
+
142
+ Oboe::API.start_trace('sequel_test', '', {}) do
143
+ items.insert(:name => 'abc', :price => 2.514461383352462)
144
+ end
145
+
146
+ traces = get_all_traces
147
+
148
+ traces.count.must_equal 4
149
+ validate_outer_layers(traces, 'sequel_test')
150
+
151
+ validate_event_keys(traces[1], @entry_kvs)
152
+ if RUBY_VERSION < "1.9"
153
+ traces[1]['Query'].must_equal "INSERT INTO `items` (`price`, `name`) VALUES (?, ?)"
154
+ else
155
+ traces[1]['Query'].must_equal "INSERT INTO `items` (`name`, `price`) VALUES (?, ?)"
156
+ end
157
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
158
+ validate_event_keys(traces[2], @exit_kvs)
159
+ end
160
+
161
+ it 'should trace a dataset filter' do
162
+ items = MYSQL2_DB[:items]
163
+ items.count
164
+
165
+ Oboe::API.start_trace('sequel_test', '', {}) do
166
+ items.filter(:name => 'abc').all
167
+ end
168
+
169
+ traces = get_all_traces
170
+
171
+ traces.count.must_equal 4
172
+ validate_outer_layers(traces, 'sequel_test')
173
+
174
+ validate_event_keys(traces[1], @entry_kvs)
175
+ traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = 'abc')"
176
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
177
+ validate_event_keys(traces[2], @exit_kvs)
178
+ end
179
+
180
+ it 'should trace create table' do
181
+ # Drop the table if it already exists
182
+ MYSQL2_DB.drop_table(:fake) if MYSQL2_DB.table_exists?(:fake)
183
+
184
+ Oboe::API.start_trace('sequel_test', '', {}) do
185
+ MYSQL2_DB.create_table :fake do
186
+ primary_key :id
187
+ String :name
188
+ Float :price
189
+ end
190
+ end
191
+
192
+ traces = get_all_traces
193
+
194
+ traces.count.must_equal 4
195
+ validate_outer_layers(traces, 'sequel_test')
196
+
197
+ validate_event_keys(traces[1], @entry_kvs)
198
+ traces[1]['Query'].must_equal "CREATE TABLE `fake` (`id` integer PRIMARY KEY AUTO_INCREMENT, `name` varchar(255), `price` double precision)"
199
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
200
+ validate_event_keys(traces[2], @exit_kvs)
201
+ end
202
+
203
+ it 'should trace add index' do
204
+ # Drop the table if it already exists
205
+ MYSQL2_DB.drop_table(:fake) if MYSQL2_DB.table_exists?(:fake)
206
+
207
+ Oboe::API.start_trace('sequel_test', '', {}) do
208
+ MYSQL2_DB.create_table :fake do
209
+ primary_key :id
210
+ String :name
211
+ Float :price
212
+ end
213
+ end
214
+
215
+ traces = get_all_traces
216
+
217
+ traces.count.must_equal 4
218
+ validate_outer_layers(traces, 'sequel_test')
219
+
220
+ validate_event_keys(traces[1], @entry_kvs)
221
+ traces[1]['Query'].must_equal "CREATE TABLE `fake` (`id` integer PRIMARY KEY AUTO_INCREMENT, `name` varchar(255), `price` double precision)"
222
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
223
+ validate_event_keys(traces[2], @exit_kvs)
224
+ end
225
+
226
+ it 'should capture and report exceptions' do
227
+ begin
228
+ Oboe::API.start_trace('sequel_test', '', {}) do
229
+ MYSQL2_DB.run("this is bad sql")
230
+ end
231
+ rescue
232
+ # Do nothing - we're testing exception logging
233
+ end
234
+
235
+ traces = get_all_traces
236
+
237
+ traces.count.must_equal 5
238
+ validate_outer_layers(traces, 'sequel_test')
239
+
240
+ validate_event_keys(traces[1], @entry_kvs)
241
+ traces[1]['Query'].must_equal "this is bad sql"
242
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
243
+ traces[2]['Layer'].must_equal "sequel"
244
+ traces[2]['Label'].must_equal "error"
245
+ traces[2].has_key?('Backtrace').must_equal true
246
+ traces[2]['ErrorClass'].must_equal "Sequel::DatabaseError"
247
+ validate_event_keys(traces[3], @exit_kvs)
248
+ end
249
+
250
+ it 'should trace placeholder queries with bound vars' do
251
+ items = MYSQL2_DB[:items]
252
+ items.count
253
+
254
+ Oboe::API.start_trace('sequel_test', '', {}) do
255
+ ds = items.where(:name=>:$n)
256
+ ds.call(:select, :n=>'abc')
257
+ ds.call(:delete, :n=>'cba')
258
+ end
259
+
260
+ traces = get_all_traces
261
+
262
+ traces.count.must_equal 6
263
+ validate_outer_layers(traces, 'sequel_test')
264
+
265
+ validate_event_keys(traces[1], @entry_kvs)
266
+ traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = 'abc')"
267
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
268
+ traces[3]['Query'].must_equal "DELETE FROM `items` WHERE (`name` = 'cba')"
269
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
270
+ validate_event_keys(traces[2], @exit_kvs)
271
+ end
272
+
273
+ it 'should trace prepared statements' do
274
+ ds = MYSQL2_DB[:items].filter(:name=>:$n)
275
+ ps = ds.prepare(:select, :select_by_name)
276
+
277
+ Oboe::API.start_trace('sequel_test', '', {}) do
278
+ ps.call(:n=>'abc')
279
+ end
280
+
281
+ traces = get_all_traces
282
+
283
+ traces.count.must_equal 4
284
+ validate_outer_layers(traces, 'sequel_test')
285
+
286
+ validate_event_keys(traces[1], @entry_kvs)
287
+ traces[1]['Query'].must_equal "select_by_name"
288
+ if RUBY_VERSION < "1.9"
289
+ traces[1]['QueryArgs'].must_equal "abc"
290
+ else
291
+ traces[1]['QueryArgs'].must_equal "[\"abc\"]"
292
+ end
293
+ traces[1]['IsPreparedStatement'].must_equal "true"
294
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
295
+ validate_event_keys(traces[2], @exit_kvs)
296
+ end
297
+
298
+ it 'should trace prep\'d stmnts and obey query privacy' do
299
+ Oboe::Config[:sanitize_sql] = true
300
+ ds = MYSQL2_DB[:items].filter(:name=>:$n)
301
+ ps = ds.prepare(:select, :select_by_name)
302
+
303
+ Oboe::API.start_trace('sequel_test', '', {}) do
304
+ ps.call(:n=>'abc')
305
+ end
306
+
307
+ traces = get_all_traces
308
+
309
+ traces.count.must_equal 4
310
+ validate_outer_layers(traces, 'sequel_test')
311
+
312
+ validate_event_keys(traces[1], @entry_kvs)
313
+ traces[1]['Query'].must_equal "select_by_name"
314
+ traces[1]['QueryArgs'].must_equal nil
315
+ traces[1]['IsPreparedStatement'].must_equal "true"
316
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:sequel][:collect_backtraces]
317
+ validate_event_keys(traces[2], @exit_kvs)
318
+ end
319
+ end
320
+ end