traceview 3.0.0
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 +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.rb +7 -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_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.rb +62 -0
- data/lib/traceview/api.rb +18 -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/base.rb +225 -0
- data/lib/traceview/config.rb +238 -0
- data/lib/traceview/frameworks/grape.rb +97 -0
- data/lib/traceview/frameworks/padrino.rb +64 -0
- data/lib/traceview/frameworks/padrino/templates.rb +58 -0
- data/lib/traceview/frameworks/rails.rb +145 -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/sinatra.rb +95 -0
- data/lib/traceview/frameworks/sinatra/templates.rb +56 -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/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 +250 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
module TraceView
|
|
5
|
+
module Inst
|
|
6
|
+
module Cassandra
|
|
7
|
+
def extract_trace_details(op, column_family, keys, args, options = {})
|
|
8
|
+
report_kvs = {}
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
report_kvs[:Op] = op.to_s
|
|
12
|
+
report_kvs[:Cf] = column_family.to_s if column_family
|
|
13
|
+
report_kvs[:Key] = keys.inspect if keys
|
|
14
|
+
|
|
15
|
+
# Open issue - how to handle multiple Cassandra servers
|
|
16
|
+
report_kvs[:RemoteHost], report_kvs[:RemotePort] = @servers.first.split(':')
|
|
17
|
+
|
|
18
|
+
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:cassandra][:collect_backtraces]
|
|
19
|
+
|
|
20
|
+
if options.empty? && args.is_a?(Array)
|
|
21
|
+
options = args.last if args.last.is_a?(Hash)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
unless options.empty?
|
|
25
|
+
[:start_key, :finish_key, :key_count, :batch_size, :columns, :count, :start,
|
|
26
|
+
:stop, :finish, :finished, :reversed, :consistency, :ttl].each do |k|
|
|
27
|
+
report_kvs[k.to_s.capitalize] = options[k] if options.key?(k)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if op == :get_indexed_slices
|
|
31
|
+
index_clause = columns_and_options[:index_clause] || {}
|
|
32
|
+
unless index_clause.empty?
|
|
33
|
+
[:column_name, :value, :comparison].each do |k|
|
|
34
|
+
report_kvs[k.to_s.capitalize] = index_clause[k] if index_clause.key?(k)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
rescue
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
report_kvs
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def insert_with_traceview(column_family, key, hash, options = {})
|
|
46
|
+
return insert_without_traceview(column_family, key, hash, options = {}) unless TraceView.tracing?
|
|
47
|
+
|
|
48
|
+
report_kvs = extract_trace_details(:insert, column_family, key, hash, options)
|
|
49
|
+
|
|
50
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
51
|
+
insert_without_traceview(column_family, key, hash, options = {})
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def remove_with_traceview(column_family, key, *columns_and_options)
|
|
56
|
+
return send :remove_without_traceview, *args unless TraceView.tracing?
|
|
57
|
+
|
|
58
|
+
args = [column_family, key] + columns_and_options
|
|
59
|
+
report_kvs = extract_trace_details(:remove, column_family, key, columns_and_options)
|
|
60
|
+
|
|
61
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
62
|
+
send :remove_without_traceview, *args
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def count_columns_with_traceview(column_family, key, *columns_and_options)
|
|
67
|
+
return send :count_columns_without_traceview, *args unless TraceView.tracing?
|
|
68
|
+
|
|
69
|
+
args = [column_family, key] + columns_and_options
|
|
70
|
+
report_kvs = extract_trace_details(:count_columns, column_family, key, columns_and_options)
|
|
71
|
+
|
|
72
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
73
|
+
send :count_columns_without_traceview, *args
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def get_columns_with_traceview(column_family, key, *columns_and_options)
|
|
78
|
+
args = [column_family, key] + columns_and_options
|
|
79
|
+
|
|
80
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:multi_get_columns)
|
|
81
|
+
report_kvs = extract_trace_details(:get_columns, column_family, key, columns_and_options)
|
|
82
|
+
|
|
83
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
84
|
+
send :get_columns_without_traceview, *args
|
|
85
|
+
end
|
|
86
|
+
else
|
|
87
|
+
send :get_columns_without_traceview, *args
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def multi_get_columns_with_traceview(column_family, key, *columns_and_options)
|
|
92
|
+
return send :multi_get_columns_without_traceview, *args unless TraceView.tracing?
|
|
93
|
+
|
|
94
|
+
args = [column_family, key] + columns_and_options
|
|
95
|
+
report_kvs = extract_trace_details(:multi_get_columns, column_family, key, columns_and_options)
|
|
96
|
+
|
|
97
|
+
TraceView::API.trace('cassandra', report_kvs, :multi_get_columns) do
|
|
98
|
+
send :multi_get_columns_without_traceview, *args
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def get_with_traceview(column_family, key, *columns_and_options)
|
|
103
|
+
return send :get_without_traceview, *args unless TraceView.tracing?
|
|
104
|
+
|
|
105
|
+
args = [column_family, key] + columns_and_options
|
|
106
|
+
report_kvs = extract_trace_details(:get, column_family, key, columns_and_options)
|
|
107
|
+
|
|
108
|
+
TraceView::API.trace('cassandra', report_kvs, :get) do
|
|
109
|
+
send :get_without_traceview, *args
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def multi_get_with_traceview(column_family, key, *columns_and_options)
|
|
114
|
+
args = [column_family, key] + columns_and_options
|
|
115
|
+
|
|
116
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:get)
|
|
117
|
+
report_kvs = extract_trace_details(:multi_get, column_family, key, columns_and_options)
|
|
118
|
+
|
|
119
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
120
|
+
send :multi_get_without_traceview, *args
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
send :multi_get_without_traceview, *args
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def exists_with_traceview?(column_family, key, *columns_and_options)
|
|
128
|
+
return send :exists_without_traceview?, *args unless TraceView.tracing?
|
|
129
|
+
|
|
130
|
+
args = [column_family, key] + columns_and_options
|
|
131
|
+
report_kvs = extract_trace_details(:exists?, column_family, key, columns_and_options)
|
|
132
|
+
|
|
133
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
134
|
+
send :exists_without_traceview?, *args
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def get_range_single_with_traceview(column_family, options = {})
|
|
139
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:get_range_batch)
|
|
140
|
+
report_kvs = extract_trace_details(:get_range_single, column_family, nil, nil)
|
|
141
|
+
|
|
142
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
143
|
+
get_range_single_without_traceview(column_family, options)
|
|
144
|
+
end
|
|
145
|
+
else
|
|
146
|
+
get_range_single_without_traceview(column_family, options)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def get_range_batch_with_traceview(column_family, options = {})
|
|
151
|
+
return get_range_batch_without_traceview(column_family, options) unless TraceView.tracing?
|
|
152
|
+
|
|
153
|
+
report_kvs = extract_trace_details(:get_range_batch, column_family, nil, nil)
|
|
154
|
+
|
|
155
|
+
TraceView::API.trace('cassandra', report_kvs, :get_range_batch) do
|
|
156
|
+
get_range_batch_without_traceview(column_family, options)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def get_indexed_slices_with_traceview(column_family, index_clause, *columns_and_options)
|
|
161
|
+
return send :get_indexed_slices_without_traceview, *args unless TraceView.tracing?
|
|
162
|
+
|
|
163
|
+
args = [column_family, index_clause] + columns_and_options
|
|
164
|
+
report_kvs = extract_trace_details(:get_indexed_slices, column_family, nil, columns_and_options)
|
|
165
|
+
|
|
166
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
167
|
+
send :get_indexed_slices_without_traceview, *args
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def create_index_with_traceview(keyspace, column_family, column_name, validation_class)
|
|
172
|
+
unless TraceView.tracing?
|
|
173
|
+
return create_index_without_traceview(keyspace, column_family, column_name, validation_class)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
report_kvs = extract_trace_details(:create_index, column_family, nil, nil)
|
|
177
|
+
begin
|
|
178
|
+
report_kvs[:Keyspace] = keyspace.to_s
|
|
179
|
+
report_kvs[:Column_name] = column_name.to_s
|
|
180
|
+
report_kvs[:Validation_class] = validation_class.to_s
|
|
181
|
+
rescue
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
185
|
+
create_index_without_traceview(keyspace, column_family, column_name, validation_class)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def drop_index_with_traceview(keyspace, column_family, column_name)
|
|
190
|
+
return drop_index_without_traceview(keyspace, column_family, column_name) unless TraceView.tracing?
|
|
191
|
+
|
|
192
|
+
report_kvs = extract_trace_details(:drop_index, column_family, nil, nil)
|
|
193
|
+
begin
|
|
194
|
+
report_kvs[:Keyspace] = keyspace.to_s
|
|
195
|
+
report_kvs[:Column_name] = column_name.to_s
|
|
196
|
+
rescue
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
200
|
+
drop_index_without_traceview(keyspace, column_family, column_name)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def add_column_family_with_traceview(cf_def)
|
|
205
|
+
return add_column_family_without_traceview(cf_def) unless TraceView.tracing?
|
|
206
|
+
|
|
207
|
+
report_kvs = extract_trace_details(:add_column_family, nil, nil, nil)
|
|
208
|
+
begin
|
|
209
|
+
report_kvs[:Cf] = cf_def[:name] if cf_def.is_a?(Hash) && cf_def.key?(:name)
|
|
210
|
+
rescue
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
214
|
+
add_column_family_without_traceview(cf_def)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def drop_column_family_with_traceview(column_family)
|
|
219
|
+
return drop_column_family_without_traceview(column_family) unless TraceView.tracing?
|
|
220
|
+
|
|
221
|
+
report_kvs = extract_trace_details(:drop_column_family, column_family, nil, nil)
|
|
222
|
+
|
|
223
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
224
|
+
drop_column_family_without_traceview(column_family)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def add_keyspace_with_traceview(ks_def)
|
|
229
|
+
return add_keyspace_without_traceview(ks_def) unless TraceView.tracing?
|
|
230
|
+
|
|
231
|
+
report_kvs = extract_trace_details(:add_keyspace, nil, nil, nil)
|
|
232
|
+
report_kvs[:Name] = ks_def.name rescue ''
|
|
233
|
+
|
|
234
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
235
|
+
add_keyspace_without_traceview(ks_def)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def drop_keyspace_with_traceview(keyspace)
|
|
240
|
+
return drop_keyspace_without_traceview(keyspace) unless TraceView.tracing?
|
|
241
|
+
|
|
242
|
+
report_kvs = extract_trace_details(:drop_keyspace, nil, nil, nil)
|
|
243
|
+
report_kvs[:Name] = keyspace.to_s rescue ''
|
|
244
|
+
|
|
245
|
+
TraceView::API.trace('cassandra', report_kvs) do
|
|
246
|
+
drop_keyspace_without_traceview(keyspace)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
if defined?(::Cassandra) && TraceView::Config[:cassandra][:enabled]
|
|
254
|
+
TraceView.logger.info '[traceview/loading] Instrumenting cassandra' if TraceView::Config[:verbose]
|
|
255
|
+
|
|
256
|
+
class ::Cassandra
|
|
257
|
+
include TraceView::Inst::Cassandra
|
|
258
|
+
|
|
259
|
+
[:insert, :remove, :count_columns, :get_columns, :multi_get_columns, :get,
|
|
260
|
+
:multi_get, :get_range_single, :get_range_batch, :get_indexed_slices,
|
|
261
|
+
:create_index, :drop_index, :add_column_family, :drop_column_family,
|
|
262
|
+
:add_keyspace, :drop_keyspace].each do |m|
|
|
263
|
+
if method_defined?(m)
|
|
264
|
+
class_eval "alias #{m}_without_traceview #{m}"
|
|
265
|
+
class_eval "alias #{m} #{m}_with_traceview"
|
|
266
|
+
else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument Cassandra (#{m}). Partial traces may occur."
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Special case handler for question mark methods
|
|
271
|
+
if method_defined?(:exists?)
|
|
272
|
+
alias exists_without_traceview? exists?
|
|
273
|
+
alias exists? exists_with_traceview?
|
|
274
|
+
else TraceView.logger.warn '[traceview/loading] Couldn\'t properly instrument Cassandra (exists?). Partial traces may occur.'
|
|
275
|
+
end
|
|
276
|
+
end # class Cassandra
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
module TraceView
|
|
5
|
+
module Inst
|
|
6
|
+
module Dalli
|
|
7
|
+
include TraceView::API::Memcache
|
|
8
|
+
|
|
9
|
+
def self.included(cls)
|
|
10
|
+
cls.class_eval do
|
|
11
|
+
TraceView.logger.info '[traceview/loading] Instrumenting memcache (dalli)' if TraceView::Config[:verbose]
|
|
12
|
+
if ::Dalli::Client.private_method_defined? :perform
|
|
13
|
+
alias perform_without_traceview perform
|
|
14
|
+
alias perform perform_with_traceview
|
|
15
|
+
else TraceView.logger.warn '[traceview/loading] Couldn\'t properly instrument Memcache (Dalli). Partial traces may occur.'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
if ::Dalli::Client.method_defined? :get_multi
|
|
19
|
+
alias get_multi_without_traceview get_multi
|
|
20
|
+
alias get_multi get_multi_with_traceview
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def perform_with_traceview(*all_args, &blk)
|
|
26
|
+
op, key, *args = *all_args
|
|
27
|
+
|
|
28
|
+
report_kvs = {}
|
|
29
|
+
report_kvs[:KVOp] = op
|
|
30
|
+
report_kvs[:KVKey] = key
|
|
31
|
+
if @servers.is_a?(Array) && !@servers.empty?
|
|
32
|
+
report_kvs[:RemoteHost] = @servers.join(", ")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:get_multi)
|
|
36
|
+
TraceView::API.trace('memcache', report_kvs) do
|
|
37
|
+
result = perform_without_traceview(*all_args, &blk)
|
|
38
|
+
|
|
39
|
+
# Clear the hash for a potential info event
|
|
40
|
+
report_kvs.clear
|
|
41
|
+
report_kvs[:KVHit] = memcache_hit?(result) if op == :get && key.class == String
|
|
42
|
+
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:dalli][:collect_backtraces]
|
|
43
|
+
|
|
44
|
+
TraceView::API.log('memcache', 'info', report_kvs) unless report_kvs.empty?
|
|
45
|
+
result
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
perform_without_traceview(*all_args, &blk)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_multi_with_traceview(*keys)
|
|
53
|
+
return get_multi_without_traceview(keys) unless TraceView.tracing?
|
|
54
|
+
|
|
55
|
+
info_kvs = {}
|
|
56
|
+
|
|
57
|
+
begin
|
|
58
|
+
info_kvs[:KVKeyCount] = keys.flatten.length
|
|
59
|
+
info_kvs[:KVKeyCount] = (info_kvs[:KVKeyCount] - 1) if keys.last.is_a?(Hash) || keys.last.nil?
|
|
60
|
+
if @servers.is_a?(Array) && !@servers.empty?
|
|
61
|
+
info_kvs[:RemoteHost] = @servers.join(", ")
|
|
62
|
+
end
|
|
63
|
+
rescue
|
|
64
|
+
TraceView.logger.debug "[traceview/debug] Error collecting info keys: #{e.message}"
|
|
65
|
+
TraceView.logger.debug e.backtrace
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
TraceView::API.trace('memcache', { :KVOp => :get_multi }, :get_multi) do
|
|
69
|
+
values = get_multi_without_traceview(keys)
|
|
70
|
+
|
|
71
|
+
info_kvs[:KVHitCount] = values.length
|
|
72
|
+
info_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:dalli][:collect_backtraces]
|
|
73
|
+
TraceView::API.log('memcache', 'info', info_kvs)
|
|
74
|
+
|
|
75
|
+
values
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if defined?(Dalli) && TraceView::Config[:dalli][:enabled]
|
|
83
|
+
::Dalli::Client.module_eval do
|
|
84
|
+
include TraceView::Inst::Dalli
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
module TraceView
|
|
2
|
+
module Inst
|
|
3
|
+
module EventMachine
|
|
4
|
+
module HttpConnection
|
|
5
|
+
def setup_request_with_traceview(*args, &block)
|
|
6
|
+
report_kvs = {}
|
|
7
|
+
context = TraceView::Context.toString
|
|
8
|
+
blacklisted = TraceView::API.blacklisted?(@uri)
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
report_kvs['IsService'] = 1
|
|
12
|
+
report_kvs['RemoteURL'] = @uri
|
|
13
|
+
report_kvs['HTTPMethod'] = args[0]
|
|
14
|
+
report_kvs['Blacklisted'] = true if blacklisted
|
|
15
|
+
|
|
16
|
+
if TraceView::Config[:em_http_request][:collect_backtraces]
|
|
17
|
+
report_kvs[:Backtrace] = TraceView::API.backtrace
|
|
18
|
+
end
|
|
19
|
+
rescue => e
|
|
20
|
+
TraceView.logger.debug "[traceview/debug] em-http-request KV error: #{e.inspect}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
::TraceView::API.log_entry('em-http-request', report_kvs)
|
|
24
|
+
client = setup_request_without_traceview(*args, &block)
|
|
25
|
+
client.req.headers['X-Trace'] = context unless blacklisted
|
|
26
|
+
client
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module HttpClient
|
|
31
|
+
def parse_response_header_with_traceview(*args, &block)
|
|
32
|
+
report_kvs = {}
|
|
33
|
+
xtrace = nil
|
|
34
|
+
blacklisted = TraceView::API.blacklisted?(@uri)
|
|
35
|
+
|
|
36
|
+
begin
|
|
37
|
+
report_kvs[:HTTPStatus] = args[2]
|
|
38
|
+
report_kvs[:Async] = 1
|
|
39
|
+
rescue => e
|
|
40
|
+
TraceView.logger.debug "[traceview/debug] em-http-request KV error: #{e.inspect}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
parse_response_header_without_traceview(*args, &block)
|
|
44
|
+
|
|
45
|
+
unless blacklisted
|
|
46
|
+
headers = args[0]
|
|
47
|
+
context = TraceView::Context.toString
|
|
48
|
+
task_id = TraceView::XTrace.task_id(context)
|
|
49
|
+
|
|
50
|
+
if headers.is_a?(Hash) && headers.key?('X-Trace')
|
|
51
|
+
xtrace = headers['X-Trace']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if TraceView::XTrace.valid?(xtrace) && TraceView.tracing?
|
|
55
|
+
|
|
56
|
+
# Assure that we received back a valid X-Trace with the same task_id
|
|
57
|
+
if task_id == TraceView::XTrace.task_id(xtrace)
|
|
58
|
+
TraceView::Context.fromString(xtrace)
|
|
59
|
+
else
|
|
60
|
+
TraceView.logger.debug "Mismatched returned X-Trace ID : #{xtrace}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
::TraceView::API.log_exit('em-http-request', report_kvs)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if RUBY_VERSION >= '1.9'
|
|
74
|
+
if defined?(::EventMachine::HttpConnection) && defined?(::EventMachine::HttpClient) && TraceView::Config[:em_http_request][:enabled]
|
|
75
|
+
TraceView.logger.info '[traceview/loading] Instrumenting em-http-request' if TraceView::Config[:verbose]
|
|
76
|
+
|
|
77
|
+
class ::EventMachine::HttpConnection
|
|
78
|
+
include TraceView::Inst::EventMachine::HttpConnection
|
|
79
|
+
|
|
80
|
+
if method_defined?(:setup_request)
|
|
81
|
+
class_eval 'alias :setup_request_without_traceview :setup_request'
|
|
82
|
+
class_eval 'alias :setup_request :setup_request_with_traceview'
|
|
83
|
+
else
|
|
84
|
+
TraceView.logger.warn '[traceview/loading] Couldn\'t properly instrument em-http-request (:setup_request). Partial traces may occur.'
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
class ::EventMachine::HttpClient
|
|
89
|
+
include TraceView::Inst::EventMachine::HttpClient
|
|
90
|
+
|
|
91
|
+
if method_defined?(:parse_response_header)
|
|
92
|
+
class_eval 'alias :parse_response_header_without_traceview :parse_response_header'
|
|
93
|
+
class_eval 'alias :parse_response_header :parse_response_header_with_traceview'
|
|
94
|
+
else
|
|
95
|
+
TraceView.logger.warn '[traceview/loading] Couldn\'t properly instrument em-http-request (:parse_response_header). Partial traces may occur.'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|