instana 1.12.0 → 1.193.3.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +194 -133
- data/.editorconfig +10 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +5 -1147
- data/.rubocop_todo.yml +1140 -0
- data/Appraisals +96 -0
- data/Gemfile +11 -32
- data/Rakefile +15 -49
- data/bin/console +5 -4
- data/gemfiles/.bundle/config +1 -2
- data/gemfiles/cuba_30.gemfile +14 -0
- data/gemfiles/dalli_20.gemfile +14 -0
- data/gemfiles/excon_02.gemfile +14 -0
- data/gemfiles/graphql_10.gemfile +14 -0
- data/gemfiles/grpc_10.gemfile +14 -0
- data/gemfiles/net_http_01.gemfile +13 -0
- data/gemfiles/rack_16.gemfile +14 -0
- data/gemfiles/rack_20.gemfile +14 -0
- data/gemfiles/rails_42.gemfile +16 -0
- data/gemfiles/rails_50.gemfile +16 -0
- data/gemfiles/rails_52.gemfile +16 -0
- data/gemfiles/rails_60.gemfile +16 -0
- data/gemfiles/redis_40.gemfile +14 -0
- data/gemfiles/resque_122.gemfile +15 -0
- data/gemfiles/resque_20.gemfile +14 -0
- data/gemfiles/rest_client_16.gemfile +14 -0
- data/gemfiles/rest_client_20.gemfile +14 -0
- data/gemfiles/roda_20.gemfile +14 -0
- data/gemfiles/roda_30.gemfile +14 -0
- data/gemfiles/sidekiq_42.gemfile +14 -0
- data/gemfiles/sidekiq_50.gemfile +14 -0
- data/gemfiles/sinatra_14.gemfile +14 -0
- data/instana.gemspec +1 -7
- data/lib/instana/activator.rb +41 -0
- data/lib/instana/activators/cuba.rb +18 -0
- data/lib/instana/activators/dalli.rb +20 -0
- data/lib/instana/activators/excon.rb +17 -0
- data/lib/instana/activators/graphql.rb +19 -0
- data/lib/instana/activators/grpc_client.rb +17 -0
- data/lib/instana/activators/grpc_server.rb +17 -0
- data/lib/instana/activators/net_http.rb +17 -0
- data/lib/instana/activators/rack.rb +13 -0
- data/lib/instana/activators/rails.rb +15 -0
- data/lib/instana/activators/redis.rb +17 -0
- data/lib/instana/activators/resque_client.rb +18 -0
- data/lib/instana/activators/resque_worker.rb +30 -0
- data/lib/instana/activators/rest_client.rb +17 -0
- data/lib/instana/activators/roda.rb +18 -0
- data/lib/instana/activators/sidekiq_client.rb +21 -0
- data/lib/instana/activators/sidekiq_worker.rb +21 -0
- data/lib/instana/activators/sinatra.rb +18 -0
- data/lib/instana/agent.rb +6 -0
- data/lib/instana/base.rb +2 -0
- data/lib/instana/config.rb +11 -0
- data/lib/instana/frameworks/cuba.rb +6 -13
- data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +5 -7
- data/lib/instana/frameworks/instrumentation/action_view.rb +6 -10
- data/lib/instana/frameworks/instrumentation/active_record.rb +4 -4
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +17 -15
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +11 -7
- data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +33 -19
- data/lib/instana/frameworks/rails.rb +0 -1
- data/lib/instana/frameworks/roda.rb +7 -13
- data/lib/instana/frameworks/sinatra.rb +1 -8
- data/lib/instana/instrumentation/dalli.rb +7 -18
- data/lib/instana/instrumentation/excon.rb +51 -57
- data/lib/instana/instrumentation/graphql.rb +75 -0
- data/lib/instana/instrumentation/grpc.rb +70 -66
- data/lib/instana/instrumentation/instrumented_request.rb +69 -0
- data/lib/instana/instrumentation/net-http.rb +43 -45
- data/lib/instana/instrumentation/rack.rb +14 -53
- data/lib/instana/instrumentation/redis.rb +10 -18
- data/lib/instana/instrumentation/resque.rb +14 -50
- data/lib/instana/instrumentation/rest-client.rb +2 -17
- data/lib/instana/instrumentation/sidekiq-client.rb +0 -9
- data/lib/instana/instrumentation/sidekiq-worker.rb +0 -9
- data/lib/instana/secrets.rb +42 -0
- data/lib/instana/setup.rb +4 -1
- data/lib/instana/tracer.rb +6 -0
- data/lib/instana/tracing/span.rb +14 -10
- data/lib/instana/util.rb +15 -69
- data/lib/instana/version.rb +1 -1
- data/test/activator_test.rb +27 -0
- data/test/config_test.rb +1 -17
- data/test/frameworks/cuba_test.rb +38 -40
- data/test/frameworks/rails/activerecord_test.rb +86 -34
- data/test/frameworks/rails_test.rb +15 -0
- data/test/frameworks/roda_test.rb +39 -41
- data/test/frameworks/sinatra_test.rb +61 -64
- data/test/instrumentation/excon_test.rb +1 -2
- data/test/instrumentation/graphql_test.rb +116 -0
- data/test/instrumentation/grpc_test.rb +2 -1
- data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +1 -0
- data/test/instrumentation/rack_instrumented_request_test.rb +84 -0
- data/test/{frameworks → instrumentation}/rack_test.rb +32 -20
- data/test/instrumentation/redis_test.rb +10 -0
- data/test/instrumentation/resque_test.rb +3 -11
- data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +6 -0
- data/test/instrumentation/sidekiq-client_test.rb +1 -0
- data/test/instrumentation/sidekiq-worker_test.rb +1 -0
- data/test/secrets_test.rb +73 -0
- data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +1 -1
- data/test/{apps → support/apps/grpc}/grpc_server.rb +0 -0
- data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +0 -0
- data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +8 -14
- data/test/{models → support/apps/rails/models}/block.rb +1 -1
- data/test/{models → support/apps/rails/models}/block6.rb +0 -0
- data/test/support/apps/resque/boot.rb +2 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +0 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +0 -0
- data/test/support/apps/sidekiq/boot.rb +21 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +0 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +0 -0
- data/test/{servers → support/apps}/sidekiq/worker.rb +2 -2
- data/test/support/helpers.rb +94 -0
- data/test/test_helper.rb +24 -144
- data/test/tracing/id_management_test.rb +4 -66
- metadata +98 -80
- data/gemfiles/libraries.gemfile +0 -71
- data/gemfiles/rails32.gemfile +0 -51
- data/gemfiles/rails42.gemfile +0 -50
- data/gemfiles/rails50.gemfile +0 -52
- data/gemfiles/rails52.gemfile +0 -52
- data/gemfiles/rails60.gemfile +0 -72
- data/lib/instana/instrumentation.rb +0 -25
- data/lib/instana/test.rb +0 -43
- data/test/apps/cuba.rb +0 -19
- data/test/apps/roda.rb +0 -13
- data/test/apps/sinatra.rb +0 -9
- data/test/servers/helpers/sidekiq_worker_initializer.rb +0 -27
@@ -34,12 +34,3 @@ module Instana
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
if defined?(::Sidekiq) && ::Instana.config[:'sidekiq-client'][:enabled]
|
39
|
-
::Sidekiq.configure_client do |cfg|
|
40
|
-
cfg.client_middleware do |chain|
|
41
|
-
::Instana.logger.debug "Instrumenting Sidekiq client"
|
42
|
-
chain.add ::Instana::Instrumentation::SidekiqClient
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -43,12 +43,3 @@ module Instana
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
47
|
-
if defined?(::Sidekiq) && ::Instana.config[:'sidekiq-worker'][:enabled]
|
48
|
-
::Sidekiq.configure_server do |cfg|
|
49
|
-
cfg.server_middleware do |chain|
|
50
|
-
::Instana.logger.debug "Instrumenting Sidekiq worker"
|
51
|
-
chain.add ::Instana::Instrumentation::SidekiqWorker
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Instana
|
5
|
+
class Secrets
|
6
|
+
def remove_from_query(str, secret_values = Instana.agent.secret_values)
|
7
|
+
return str unless secret_values
|
8
|
+
|
9
|
+
url = URI(str)
|
10
|
+
params = CGI.parse(url.query || '')
|
11
|
+
|
12
|
+
redacted = params.map do |k, v|
|
13
|
+
needs_redaction = secret_values['list']
|
14
|
+
.any? { |t| matcher(secret_values['matcher']).(t,k) }
|
15
|
+
[k, needs_redaction ? '<redacted>' : v]
|
16
|
+
end
|
17
|
+
|
18
|
+
url.query = URI.encode_www_form(redacted)
|
19
|
+
CGI.unescape(url.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def matcher(name)
|
25
|
+
case name
|
26
|
+
when 'equals-ignore-case'
|
27
|
+
->(expected, actual) { expected.casecmp(actual) == 0 }
|
28
|
+
when 'equals'
|
29
|
+
->(expected, actual) { (expected <=> actual) == 0 }
|
30
|
+
when 'contains-ignore-case'
|
31
|
+
->(expected, actual) { actual.downcase.include?(expected) }
|
32
|
+
when 'contains'
|
33
|
+
->(expected, actual) { actual.include?(expected) }
|
34
|
+
when 'regex'
|
35
|
+
->(expected, actual) { !Regexp.new(expected).match(actual).nil? }
|
36
|
+
else
|
37
|
+
::Instana.logger.warn("Matcher #{name} is not supported.")
|
38
|
+
lambda { false }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/instana/setup.rb
CHANGED
@@ -4,12 +4,15 @@ require "instana/base"
|
|
4
4
|
require "instana/config"
|
5
5
|
require "instana/agent"
|
6
6
|
require "instana/collector"
|
7
|
+
require "instana/secrets"
|
7
8
|
require "instana/tracer"
|
8
9
|
require "instana/tracing/processor"
|
9
|
-
|
10
|
+
|
11
|
+
require 'instana/activator'
|
10
12
|
|
11
13
|
::Instana.setup
|
12
14
|
::Instana.agent.setup
|
15
|
+
::Instana::Activator.start
|
13
16
|
|
14
17
|
# Register the metric collectors
|
15
18
|
unless RUBY_PLATFORM == 'java'.freeze
|
data/lib/instana/tracer.rb
CHANGED
@@ -100,6 +100,12 @@ module Instana
|
|
100
100
|
else
|
101
101
|
self.current_span = Span.new(name)
|
102
102
|
end
|
103
|
+
|
104
|
+
if incoming_context.is_a?(Hash) && incoming_context[:correlation] && !incoming_context[:correlation].empty?
|
105
|
+
self.current_span[:crid] = incoming_context[:correlation][:id]
|
106
|
+
self.current_span[:crtp] = incoming_context[:correlation][:type]
|
107
|
+
end
|
108
|
+
|
103
109
|
self.current_span.set_tags(kvs) unless kvs.empty?
|
104
110
|
self.current_span
|
105
111
|
end
|
data/lib/instana/tracing/span.rb
CHANGED
@@ -3,8 +3,8 @@ module Instana
|
|
3
3
|
REGISTERED_SPANS = [ :actioncontroller, :actionview, :activerecord, :excon,
|
4
4
|
:memcache, :'net-http', :rack, :render, :'rpc-client',
|
5
5
|
:'rpc-server', :'sidekiq-client', :'sidekiq-worker',
|
6
|
-
:redis, :'resque-client', :'resque-worker' ].freeze
|
7
|
-
ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker' ].freeze
|
6
|
+
:redis, :'resque-client', :'resque-worker', :'graphql.server' ].freeze
|
7
|
+
ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker', :'graphql.server' ].freeze
|
8
8
|
EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'resque-client',
|
9
9
|
:'rpc-client', :'sidekiq-client', :redis ].freeze
|
10
10
|
HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
|
@@ -57,9 +57,6 @@ module Instana
|
|
57
57
|
end
|
58
58
|
|
59
59
|
if ::Instana.config[:collect_backtraces]
|
60
|
-
# For entry spans, add a backtrace fingerprint
|
61
|
-
add_stack(limit: 2) if ENTRY_SPANS.include?(name)
|
62
|
-
|
63
60
|
# Attach a backtrace to all exit spans
|
64
61
|
add_stack if EXIT_SPANS.include?(name)
|
65
62
|
end
|
@@ -76,9 +73,11 @@ module Instana
|
|
76
73
|
#
|
77
74
|
# @param limit [Integer] Limit the backtrace to the top <limit> frames
|
78
75
|
#
|
79
|
-
def add_stack(limit:
|
76
|
+
def add_stack(limit: 30, stack: Kernel.caller)
|
80
77
|
frame_count = 0
|
78
|
+
sanitized_stack = []
|
81
79
|
@data[:stack] = []
|
80
|
+
limit = 40 if limit > 40
|
82
81
|
|
83
82
|
stack.each do |i|
|
84
83
|
# If the stack has the full instana gem version in it's path
|
@@ -86,18 +85,23 @@ module Instana
|
|
86
85
|
if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
|
87
86
|
(i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
|
88
87
|
|
89
|
-
break if limit && frame_count >= limit
|
90
|
-
|
91
88
|
x = i.split(':')
|
92
89
|
|
93
|
-
|
90
|
+
sanitized_stack << {
|
94
91
|
:c => x[0],
|
95
92
|
:n => x[1],
|
96
93
|
:m => x[2]
|
97
94
|
}
|
98
|
-
frame_count = frame_count + 1 if limit
|
99
95
|
end
|
100
96
|
end
|
97
|
+
|
98
|
+
if sanitized_stack.length > limit
|
99
|
+
# (limit * -1) gives us negative form of <limit> used for
|
100
|
+
# slicing from the end of the list. e.g. stack[-30, 30]
|
101
|
+
@data[:stack] = sanitized_stack[limit*-1, limit]
|
102
|
+
else
|
103
|
+
@data[:stack] = sanitized_stack
|
104
|
+
end
|
101
105
|
end
|
102
106
|
|
103
107
|
# Log an error into the span
|
data/lib/instana/util.rb
CHANGED
@@ -2,46 +2,6 @@ module Instana
|
|
2
2
|
module Util
|
3
3
|
class << self
|
4
4
|
ID_RANGE = -2**63..2**63-1
|
5
|
-
|
6
|
-
# An agnostic approach to method aliasing.
|
7
|
-
#
|
8
|
-
# @param klass [Object] The class or module that holds the method to be alias'd.
|
9
|
-
# @param method [Symbol] The name of the method to be aliased.
|
10
|
-
#
|
11
|
-
def method_alias(klass, method)
|
12
|
-
if klass.method_defined?(method.to_sym) ||
|
13
|
-
klass.private_method_defined?(method.to_sym)
|
14
|
-
|
15
|
-
with = "#{method}_with_instana"
|
16
|
-
without = "#{method}_without_instana"
|
17
|
-
|
18
|
-
klass.class_eval do
|
19
|
-
alias_method without, method.to_s
|
20
|
-
alias_method method.to_s, with
|
21
|
-
end
|
22
|
-
else
|
23
|
-
::Instana.logger.debug "No such method (#{method}) to alias on #{klass}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Calls on target_class to 'extend' cls
|
28
|
-
#
|
29
|
-
# @param target_cls [Object] the class/module to do the 'extending'
|
30
|
-
# @param cls [Object] the class/module to be 'extended'
|
31
|
-
#
|
32
|
-
def send_extend(target_cls, cls)
|
33
|
-
target_cls.send(:extend, cls) if defined?(target_cls)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Calls on <target_cls> to include <cls> into itself.
|
37
|
-
#
|
38
|
-
# @param target_cls [Object] the class/module to do the 'including'
|
39
|
-
# @param cls [Object] the class/module to be 'included'
|
40
|
-
#
|
41
|
-
def send_include(target_cls, cls)
|
42
|
-
target_cls.send(:include, cls) if defined?(target_cls)
|
43
|
-
end
|
44
|
-
|
45
5
|
# Debugging helper method
|
46
6
|
#
|
47
7
|
def pry!
|
@@ -225,53 +185,39 @@ module Instana
|
|
225
185
|
(time.to_f * 1000).floor
|
226
186
|
end
|
227
187
|
|
228
|
-
# Generate a random 64bit ID
|
188
|
+
# Generate a random 64bit/128bit ID
|
189
|
+
#
|
190
|
+
# @param size [Integer] Number of 64 bit integers used to generate the id
|
229
191
|
#
|
230
|
-
# @return [
|
192
|
+
# @return [String] a random 64bit/128bit hex encoded string
|
231
193
|
#
|
232
|
-
def generate_id
|
233
|
-
|
234
|
-
|
194
|
+
def generate_id(size = 1)
|
195
|
+
Array.new(size) { rand(ID_RANGE) }
|
196
|
+
.pack('q>*')
|
197
|
+
.unpack('H*')
|
198
|
+
.first
|
235
199
|
end
|
236
200
|
|
237
201
|
# Convert an ID to a value appropriate to pass in a header.
|
238
202
|
#
|
239
|
-
# @param id [
|
203
|
+
# @param id [String] the id to be converted
|
240
204
|
#
|
241
205
|
# @return [String]
|
242
206
|
#
|
243
207
|
def id_to_header(id)
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
248
|
-
[id.to_i].pack('q>').unpack('H*')[0].gsub(/^0+/, '')
|
249
|
-
rescue => e
|
250
|
-
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
251
|
-
Instana.logger.debug { e.backtrace.join("\r\n") }
|
208
|
+
return '' unless id.is_a?(String)
|
209
|
+
# Only send 64bit IDs downstream for now
|
210
|
+
id.length == 32 ? id[16..-1] : id
|
252
211
|
end
|
253
212
|
|
254
213
|
# Convert a received header value into a valid ID
|
255
214
|
#
|
256
215
|
# @param header_id [String] the header value to be converted
|
257
216
|
#
|
258
|
-
# @return [
|
217
|
+
# @return [String]
|
259
218
|
#
|
260
219
|
def header_to_id(header_id)
|
261
|
-
|
262
|
-
Instana.logger.debug "header_to_id received a #{header_id.class}: returning 0"
|
263
|
-
return 0
|
264
|
-
end
|
265
|
-
if header_id.length < 16
|
266
|
-
# The header is less than 16 chars. Prepend
|
267
|
-
# zeros so we can convert correctly
|
268
|
-
missing = 16 - header_id.length
|
269
|
-
header_id = ("0" * missing) + header_id
|
270
|
-
end
|
271
|
-
[header_id].pack("H*").unpack("q>")[0]
|
272
|
-
rescue => e
|
273
|
-
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
274
|
-
Instana.logger.debug { e.backtrace.join("\r\n") }
|
220
|
+
header_id.is_a?(String) && header_id.match(/\A[a-z\d]{16,32}\z/i) ? header_id : ''
|
275
221
|
end
|
276
222
|
end
|
277
223
|
end
|
data/lib/instana/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActivatorTest < Minitest::Test
|
4
|
+
def test_start
|
5
|
+
refute_nil Instana::Activator.trace_point
|
6
|
+
assert Instana::Activator.trace_point.enabled?
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_klass_call
|
10
|
+
assert_equal [], Instana::Activator.call
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_instance_call
|
14
|
+
subject = Class.new(Instana::Activator) do
|
15
|
+
def can_instrument?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def instrument
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal 1, Instana::Activator.call.length
|
25
|
+
assert subject.call
|
26
|
+
end
|
27
|
+
end
|
data/test/config_test.rb
CHANGED
@@ -10,28 +10,12 @@ class ConfigTest < Minitest::Test
|
|
10
10
|
assert_equal '127.0.0.1', ::Instana.config[:agent_host]
|
11
11
|
assert_equal 42699, ::Instana.config[:agent_port]
|
12
12
|
|
13
|
-
assert ::Instana.config[:enabled]
|
14
13
|
assert ::Instana.config[:tracing][:enabled]
|
15
14
|
assert ::Instana.config[:metrics][:enabled]
|
16
15
|
|
17
16
|
::Instana.config[:metrics].each do |k, v|
|
17
|
+
next unless v.is_a? Hash
|
18
18
|
assert_equal true, ::Instana.config[:metrics][k].key?(:enabled)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
def test_that_global_affects_children
|
23
|
-
# Disabling the gem should explicitly disable
|
24
|
-
# metrics and tracing flags
|
25
|
-
::Instana.config[:enabled] = false
|
26
|
-
|
27
|
-
assert_equal false, ::Instana.config[:tracing][:enabled]
|
28
|
-
assert_equal false, ::Instana.config[:metrics][:enabled]
|
29
|
-
|
30
|
-
# Enabling the gem should explicitly enable
|
31
|
-
# metrics and tracing flags
|
32
|
-
::Instana.config[:enabled] = true
|
33
|
-
|
34
|
-
assert_equal ::Instana.config[:tracing][:enabled]
|
35
|
-
assert_equal ::Instana.config[:metrics][:enabled]
|
36
|
-
end
|
37
21
|
end
|
@@ -1,57 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../apps/cuba')
|
4
|
-
require 'rack/test'
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rack/test'
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
class CubaTest < Minitest::Test
|
5
|
+
include Rack::Test::Methods
|
6
|
+
APP = Rack::Builder.parse_file('test/support/apps/cuba/config.ru').first
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def app
|
9
|
+
APP
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def test_basic_get
|
13
|
+
clear_all!
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
r = get '/hello'
|
16
|
+
assert last_response.ok?
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
assert r.headers.key?("X-Instana-T")
|
19
|
+
assert r.headers.key?("X-Instana-S")
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
spans = ::Instana.processor.queued_spans
|
22
|
+
assert_equal 1, spans.count
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
first_span = spans.first
|
25
|
+
assert_equal :rack, first_span[:n]
|
26
|
+
assert first_span.key?(:data)
|
27
|
+
assert first_span[:data].key?(:http)
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
assert first_span[:data][:http].key?(:method)
|
30
|
+
assert_equal "GET", first_span[:data][:http][:method]
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
assert first_span[:data][:http].key?(:url)
|
33
|
+
assert_equal "/hello", first_span[:data][:http][:url]
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
assert first_span[:data][:http].key?(:status)
|
36
|
+
assert_equal 200, first_span[:data][:http][:status]
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
assert first_span[:data][:http].key?(:host)
|
39
|
+
assert_equal "example.org", first_span[:data][:http][:host]
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
42
|
+
def test_path_template
|
43
|
+
clear_all!
|
45
44
|
|
46
|
-
|
47
|
-
|
45
|
+
r = get '/greet/instana'
|
46
|
+
assert last_response.ok?
|
48
47
|
|
49
|
-
|
50
|
-
|
48
|
+
spans = ::Instana.processor.queued_spans
|
49
|
+
assert_equal 1, spans.count
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
51
|
+
first_span = spans.first
|
52
|
+
assert_equal :rack, first_span[:n]
|
53
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
56
54
|
end
|
57
55
|
end
|
@@ -2,14 +2,21 @@ require 'test_helper'
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
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
|
+
|
5
11
|
def test_config_defaults
|
12
|
+
assert ::Instana.config[:sanitize_sql] == true
|
6
13
|
assert ::Instana.config[:active_record].is_a?(Hash)
|
7
14
|
assert ::Instana.config[:active_record].key?(:enabled)
|
8
15
|
assert_equal true, ::Instana.config[:active_record][:enabled]
|
9
16
|
end
|
10
17
|
|
11
18
|
def test_postgresql
|
12
|
-
skip unless
|
19
|
+
skip unless has_postgres_database?
|
13
20
|
|
14
21
|
clear_all!
|
15
22
|
|
@@ -28,19 +35,14 @@ class ActiveRecordTest < Minitest::Test
|
|
28
35
|
assert span[:data][:activerecord].key?(:username)
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
found = false
|
33
38
|
if ::Rails::VERSION::MAJOR < 4
|
34
39
|
sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
|
35
40
|
else
|
36
41
|
sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
|
37
42
|
end
|
38
|
-
ar_spans
|
39
|
-
|
40
|
-
found = true
|
41
|
-
end
|
43
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
44
|
+
span[:data][:activerecord][:sql].squeeze == sql.squeeze
|
42
45
|
end
|
43
|
-
assert found
|
44
46
|
|
45
47
|
found = false
|
46
48
|
if ::Rails::VERSION::MAJOR >= 5
|
@@ -50,12 +52,9 @@ class ActiveRecordTest < Minitest::Test
|
|
50
52
|
else
|
51
53
|
sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
|
52
54
|
end
|
53
|
-
ar_spans
|
54
|
-
|
55
|
-
found = true
|
56
|
-
end
|
55
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
56
|
+
span[:data][:activerecord][:sql].squeeze == sql.squeeze
|
57
57
|
end
|
58
|
-
assert found
|
59
58
|
|
60
59
|
found = false
|
61
60
|
if ::Rails::VERSION::MAJOR == 3
|
@@ -63,16 +62,77 @@ class ActiveRecordTest < Minitest::Test
|
|
63
62
|
else
|
64
63
|
sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $?"
|
65
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
|
+
|
66
89
|
ar_spans.each do |span|
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
70
128
|
end
|
71
|
-
assert
|
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
|
72
132
|
end
|
73
133
|
|
74
134
|
def test_postgresql_lock_table
|
75
|
-
skip unless
|
135
|
+
skip unless has_postgres_database?
|
76
136
|
|
77
137
|
clear_all!
|
78
138
|
|
@@ -93,25 +153,17 @@ class ActiveRecordTest < Minitest::Test
|
|
93
153
|
assert_equal "postgres", ar_span[:data][:activerecord][:username]
|
94
154
|
end
|
95
155
|
|
96
|
-
|
97
|
-
|
98
|
-
if span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
|
99
|
-
found = true
|
100
|
-
end
|
156
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
157
|
+
span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
|
101
158
|
end
|
102
|
-
assert found
|
103
159
|
|
104
|
-
|
105
|
-
|
106
|
-
if span[:data][:activerecord][:sql] == "SELECT ?"
|
107
|
-
found = true
|
108
|
-
end
|
160
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
161
|
+
span[:data][:activerecord][:sql] == "SELECT ?"
|
109
162
|
end
|
110
|
-
assert found
|
111
163
|
end
|
112
164
|
|
113
165
|
def test_postgresql_raw_execute
|
114
|
-
skip unless
|
166
|
+
skip unless has_postgres_database?
|
115
167
|
|
116
168
|
clear_all!
|
117
169
|
|
@@ -131,7 +183,7 @@ class ActiveRecordTest < Minitest::Test
|
|
131
183
|
end
|
132
184
|
|
133
185
|
def test_postgresql_raw_execute_error
|
134
|
-
skip unless
|
186
|
+
skip unless has_postgres_database?
|
135
187
|
|
136
188
|
clear_all!
|
137
189
|
|
@@ -153,7 +205,7 @@ class ActiveRecordTest < Minitest::Test
|
|
153
205
|
end
|
154
206
|
|
155
207
|
def test_mysql2
|
156
|
-
skip unless
|
208
|
+
skip unless has_mysql2_database?
|
157
209
|
|
158
210
|
clear_all!
|
159
211
|
|
@@ -190,7 +242,7 @@ class ActiveRecordTest < Minitest::Test
|
|
190
242
|
end
|
191
243
|
|
192
244
|
def test_mysql
|
193
|
-
skip unless
|
245
|
+
skip unless has_mysql_database?
|
194
246
|
|
195
247
|
clear_all!
|
196
248
|
|