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
@@ -0,0 +1,17 @@
|
|
1
|
+
module Instana
|
2
|
+
module Activators
|
3
|
+
class RestClient < Activator
|
4
|
+
def can_instrument?
|
5
|
+
defined?(::RestClient::Request) && ::Instana.config[:'rest-client'][:enabled]
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
require 'instana/instrumentation/rest-client'
|
10
|
+
|
11
|
+
::RestClient::Request.prepend ::Instana::Instrumentation::RestClientRequest
|
12
|
+
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Instana
|
2
|
+
module Activators
|
3
|
+
class Roda < Activator
|
4
|
+
def can_instrument?
|
5
|
+
defined?(::Instana::Rack) && defined?(::Roda)
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
require 'instana/frameworks/roda'
|
10
|
+
|
11
|
+
::Roda.use ::Instana::Rack
|
12
|
+
::Roda.plugin ::Instana::RodaPathTemplateExtractor
|
13
|
+
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Instana
|
2
|
+
module Activators
|
3
|
+
class SidekiqClient < Activator
|
4
|
+
def can_instrument?
|
5
|
+
defined?(::Sidekiq) && ::Instana.config[:'sidekiq-client'][:enabled]
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
require 'instana/instrumentation/sidekiq-client'
|
10
|
+
|
11
|
+
::Sidekiq.configure_client do |cfg|
|
12
|
+
cfg.client_middleware do |chain|
|
13
|
+
chain.add ::Instana::Instrumentation::SidekiqClient
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Instana
|
2
|
+
module Activators
|
3
|
+
class SidekiqWorker < Activator
|
4
|
+
def can_instrument?
|
5
|
+
defined?(::Sidekiq) && ::Instana.config[:'sidekiq-worker'][:enabled]
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
require 'instana/instrumentation/sidekiq-worker'
|
10
|
+
|
11
|
+
::Sidekiq.configure_server do |cfg|
|
12
|
+
cfg.server_middleware do |chain|
|
13
|
+
chain.add ::Instana::Instrumentation::SidekiqWorker
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Instana
|
2
|
+
module Activators
|
3
|
+
class Sinatra < Activator
|
4
|
+
def can_instrument?
|
5
|
+
defined?(::Instana::Rack) && defined?(::Sinatra)
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
require 'instana/frameworks/sinatra'
|
10
|
+
|
11
|
+
::Sinatra::Base.use ::Instana::Rack
|
12
|
+
::Sinatra::Base.register ::Instana::SinatraPathTemplateExtractor
|
13
|
+
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/instana/agent.rb
CHANGED
@@ -25,6 +25,7 @@ module Instana
|
|
25
25
|
attr_accessor :collect_thread
|
26
26
|
attr_accessor :thread_spawn_lock
|
27
27
|
attr_accessor :extra_headers
|
28
|
+
attr_reader :secret_values
|
28
29
|
|
29
30
|
attr_accessor :testmode
|
30
31
|
|
@@ -83,6 +84,10 @@ module Instana
|
|
83
84
|
|
84
85
|
# The agent may pass down custom headers for this sensor to capture
|
85
86
|
@extra_headers = nil
|
87
|
+
|
88
|
+
# The values considered sensitive and removed from http query parameters
|
89
|
+
# and database connection strings
|
90
|
+
@secret_values = nil
|
86
91
|
end
|
87
92
|
|
88
93
|
# Spawns the background thread and calls start. This method is separated
|
@@ -278,6 +283,7 @@ module Instana
|
|
278
283
|
data = Oj.load(response.body, OJ_OPTIONS)
|
279
284
|
@process[:report_pid] = data['pid']
|
280
285
|
@agent_uuid = data['agentUuid']
|
286
|
+
@secret_values = data['secrets']
|
281
287
|
|
282
288
|
if data.key?('extraHeaders')
|
283
289
|
@extra_headers = data['extraHeaders']
|
data/lib/instana/base.rb
CHANGED
@@ -12,6 +12,7 @@ module Instana
|
|
12
12
|
attr_accessor :config
|
13
13
|
attr_accessor :logger
|
14
14
|
attr_accessor :pid
|
15
|
+
attr_reader :secrets
|
15
16
|
|
16
17
|
##
|
17
18
|
# setup
|
@@ -24,6 +25,7 @@ module Instana
|
|
24
25
|
@tracer = ::Instana::Tracer.new
|
25
26
|
@processor = ::Instana::Processor.new
|
26
27
|
@collector = ::Instana::Collector.new
|
28
|
+
@secrets = ::Instana::Secrets.new
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/instana/config.rb
CHANGED
@@ -42,12 +42,23 @@ module Instana
|
|
42
42
|
# ::Instana.config[:collect_backtraces] = true
|
43
43
|
@config[:collect_backtraces] = false
|
44
44
|
|
45
|
+
# By default, collected SQL will be sanitized to remove potentially sensitive bind params such as:
|
46
|
+
# > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = "Mr. Smith"
|
47
|
+
#
|
48
|
+
# ...would be sanitized to be:
|
49
|
+
# > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = ?
|
50
|
+
#
|
51
|
+
# This sanitization step can be disabled by setting the following value to false.
|
52
|
+
# ::Instana.config[:sanitize_sql] = false
|
53
|
+
@config[:sanitize_sql] = true
|
54
|
+
|
45
55
|
@config[:action_controller] = { :enabled => true }
|
46
56
|
@config[:action_view] = { :enabled => true }
|
47
57
|
@config[:active_record] = { :enabled => true }
|
48
58
|
@config[:dalli] = { :enabled => true }
|
49
59
|
@config[:excon] = { :enabled => true }
|
50
60
|
@config[:grpc] = { :enabled => true }
|
61
|
+
@config[:graphql] = { :enabled => true }
|
51
62
|
@config[:nethttp] = { :enabled => true }
|
52
63
|
@config[:redis] = { :enabled => true }
|
53
64
|
@config[:'resque-client'] = { :enabled => true }
|
@@ -3,23 +3,23 @@ require "instana/rack"
|
|
3
3
|
module Instana
|
4
4
|
module CubaPathTemplateExtractor
|
5
5
|
REPLACE_TARGET = /:(?<term>[^\/]+)/i
|
6
|
-
|
6
|
+
|
7
7
|
def self.prepended(base)
|
8
8
|
::Instana.logger.debug "#{base} prepended #{self}"
|
9
9
|
end
|
10
|
-
|
11
|
-
def on(*args, &blk)
|
10
|
+
|
11
|
+
def on(*args, &blk)
|
12
12
|
wrapper = lambda do |*caputres|
|
13
13
|
env['INSTANA_PATH_TEMPLATE_FRAGMENTS'] << args
|
14
14
|
.select { |a| a.is_a?(String) }
|
15
15
|
.join('/')
|
16
|
-
|
16
|
+
|
17
17
|
blk.call(*captures)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
super(*args, &wrapper)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def call!(env)
|
24
24
|
env['INSTANA_PATH_TEMPLATE_FRAGMENTS'] = []
|
25
25
|
response = super(env)
|
@@ -30,10 +30,3 @@ module Instana
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
|
-
|
35
|
-
if defined?(::Cuba)
|
36
|
-
::Instana.logger.debug "Instrumenting Cuba"
|
37
|
-
Cuba.use ::Instana::Rack
|
38
|
-
Cuba.prepend ::Instana::CubaPathTemplateExtractor
|
39
|
-
end
|
@@ -6,10 +6,8 @@ module Instana
|
|
6
6
|
|
7
7
|
# This module supports instrumenting ActiveRecord with the mysql2 adapter.
|
8
8
|
#
|
9
|
-
def self.
|
9
|
+
def self.prepended(klass)
|
10
10
|
if ActiveRecord::VERSION::STRING >= '3.2'
|
11
|
-
Instana::Util.method_alias(klass, :execute)
|
12
|
-
|
13
11
|
@@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
|
14
12
|
end
|
15
13
|
end
|
@@ -40,17 +38,17 @@ module Instana
|
|
40
38
|
IGNORED_PAYLOADS.include?(name) || sql !~ EXPLAINED_SQLS
|
41
39
|
end
|
42
40
|
|
43
|
-
def
|
41
|
+
def execute(sql, name = nil)
|
44
42
|
tracing = ::Instana.tracer.tracing?
|
45
43
|
if !tracing || ignore_payload?(name, sql)
|
46
|
-
return
|
44
|
+
return super(sql, name)
|
47
45
|
elsif ::Instana.tracer.current_span[:n] == :activerecord
|
48
|
-
return
|
46
|
+
return super(sql, name)
|
49
47
|
end
|
50
48
|
|
51
49
|
kv_payload = collect(sql)
|
52
50
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
53
|
-
|
51
|
+
super(sql, name)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
@@ -1,18 +1,13 @@
|
|
1
1
|
module Instana
|
2
2
|
module Instrumentation
|
3
3
|
module ActionViewRenderer
|
4
|
-
def
|
5
|
-
::Instana::Util.method_alias(klass, :render_partial)
|
6
|
-
::Instana::Util.method_alias(klass, :render_collection)
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_partial_with_instana(*args)
|
4
|
+
def render_partial(*args)
|
10
5
|
kv_payload = { :render => {} }
|
11
6
|
kv_payload[:render][:type] = :partial
|
12
7
|
kv_payload[:render][:name] = @options[:partial].to_s if @options.is_a?(Hash)
|
13
8
|
|
14
9
|
::Instana.tracer.log_entry(:render, kv_payload)
|
15
|
-
|
10
|
+
super(*args)
|
16
11
|
rescue Exception => e
|
17
12
|
::Instana.tracer.log_error(e)
|
18
13
|
raise
|
@@ -20,13 +15,14 @@ module Instana
|
|
20
15
|
::Instana.tracer.log_exit(:render)
|
21
16
|
end
|
22
17
|
|
23
|
-
def
|
18
|
+
def render_collection(*args)
|
19
|
+
puts 'called'
|
24
20
|
kv_payload = { :render => {} }
|
25
21
|
kv_payload[:render][:type] = :collection
|
26
22
|
kv_payload[:render][:name] = @path.to_s
|
27
23
|
|
28
24
|
::Instana.tracer.log_entry(:render, kv_payload)
|
29
|
-
|
25
|
+
super(*args)
|
30
26
|
rescue Exception => e
|
31
27
|
::Instana.tracer.log_error(e)
|
32
28
|
raise
|
@@ -39,5 +35,5 @@ end
|
|
39
35
|
|
40
36
|
if defined?(::ActionView) && ::Instana.config[:action_view][:enabled] && ::ActionPack::VERSION::STRING >= '3.1'
|
41
37
|
::Instana.logger.debug "Instrumenting ActionView"
|
42
|
-
::ActionView::PartialRenderer.send(:
|
38
|
+
::ActionView::PartialRenderer.send(:prepend, ::Instana::Instrumentation::ActionViewRenderer)
|
43
39
|
end
|
@@ -9,19 +9,19 @@ if defined?(::ActiveRecord) && ::Instana.config[:active_record][:enabled]
|
|
9
9
|
# Mysql
|
10
10
|
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
|
11
11
|
::Instana.logger.debug "Instrumenting ActiveRecord (mysql)"
|
12
|
-
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:
|
13
|
-
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send(:
|
12
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:prepend, ::Instana::Instrumentation::MysqlAdapter)
|
13
|
+
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send(:prepend, ::Instana::Instrumentation::AbstractMysqlAdapter)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Mysql2
|
17
17
|
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
18
18
|
::Instana.logger.debug "Instrumenting ActiveRecord (mysql2)"
|
19
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:
|
19
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:prepend, ::Instana::Instrumentation::Mysql2Adapter)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Postgres
|
23
23
|
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
24
24
|
::Instana.logger.debug "Instrumenting ActiveRecord (postgresql)"
|
25
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:
|
25
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:prepend, ::Instana::Instrumentation::PostgreSQLAdapter)
|
26
26
|
end
|
27
27
|
end
|
@@ -6,13 +6,9 @@ module Instana
|
|
6
6
|
|
7
7
|
# This module supports instrumenting ActiveRecord with the mysql2 adapter.
|
8
8
|
#
|
9
|
-
def self.
|
9
|
+
def self.prepended(klass)
|
10
10
|
# ActiveRecord 3.1 and up only (for now possibly)
|
11
11
|
if ActiveRecord::VERSION::STRING > '3.0'
|
12
|
-
Instana::Util.method_alias(klass, :exec_delete)
|
13
|
-
Instana::Util.method_alias(klass, :exec_insert)
|
14
|
-
Instana::Util.method_alias(klass, :exec_query)
|
15
|
-
|
16
12
|
@@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
|
17
13
|
end
|
18
14
|
end
|
@@ -24,7 +20,13 @@ module Instana
|
|
24
20
|
#
|
25
21
|
def collect(sql)
|
26
22
|
payload = { :activerecord => {} }
|
27
|
-
|
23
|
+
|
24
|
+
if ::Instana.config[:sanitize_sql]
|
25
|
+
payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
|
26
|
+
else
|
27
|
+
payload[:activerecord][:sql] = sql
|
28
|
+
end
|
29
|
+
|
28
30
|
payload[:activerecord][:adapter] = @config[:adapter]
|
29
31
|
payload[:activerecord][:host] = @config[:host]
|
30
32
|
payload[:activerecord][:db] = @config[:database]
|
@@ -43,37 +45,37 @@ module Instana
|
|
43
45
|
IGNORED_PAYLOADS.include?(name) || sql !~ EXPLAINED_SQLS
|
44
46
|
end
|
45
47
|
|
46
|
-
def
|
48
|
+
def exec_delete(sql, name = nil, binds = [])
|
47
49
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
|
48
|
-
return
|
50
|
+
return super(sql, name, binds)
|
49
51
|
end
|
50
52
|
|
51
53
|
kv_payload = collect(sql)
|
52
54
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
53
|
-
|
55
|
+
super(sql, name, binds)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def
|
59
|
+
def exec_insert(sql, name = 'SQL', binds = [], *args)
|
58
60
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
|
59
|
-
return
|
61
|
+
return super(sql, name, binds, *args)
|
60
62
|
end
|
61
63
|
|
62
64
|
kv_payload = collect(sql)
|
63
65
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
64
|
-
|
66
|
+
super(sql, name, binds, *args)
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
68
|
-
def
|
70
|
+
def exec_query(sql, name = 'SQL', binds = [], *args)
|
69
71
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql) ||
|
70
72
|
::Instana.tracer.current_span[:n] == :activerecord
|
71
|
-
return
|
73
|
+
return super(sql, name, binds, *args)
|
72
74
|
end
|
73
75
|
|
74
76
|
kv_payload = collect(sql)
|
75
77
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
76
|
-
|
78
|
+
super(sql, name, binds, *args)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -6,10 +6,8 @@ module Instana
|
|
6
6
|
|
7
7
|
# This module supports instrumenting ActiveRecord with the mysql2 adapter.
|
8
8
|
#
|
9
|
-
def self.
|
9
|
+
def self.prepended(klass)
|
10
10
|
if ActiveRecord::VERSION::STRING >= '3.2'
|
11
|
-
Instana::Util.method_alias(klass, :exec_query)
|
12
|
-
|
13
11
|
@@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
|
14
12
|
end
|
15
13
|
end
|
@@ -21,7 +19,13 @@ module Instana
|
|
21
19
|
#
|
22
20
|
def collect(sql)
|
23
21
|
payload = { :activerecord => {} }
|
24
|
-
|
22
|
+
|
23
|
+
if ::Instana.config[:sanitize_sql]
|
24
|
+
payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
|
25
|
+
else
|
26
|
+
payload[:activerecord][:sql] = sql
|
27
|
+
end
|
28
|
+
|
25
29
|
payload[:activerecord][:adapter] = @config[:adapter]
|
26
30
|
payload[:activerecord][:host] = @config[:host]
|
27
31
|
payload[:activerecord][:db] = @config[:database]
|
@@ -40,15 +44,15 @@ module Instana
|
|
40
44
|
IGNORED_PAYLOADS.include?(name) || sql !~ EXPLAINED_SQLS
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
47
|
+
def exec_query(sql, name = 'SQL', binds = [], *args)
|
44
48
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql) ||
|
45
49
|
::Instana.tracer.current_span[:n] == :activerecord
|
46
|
-
return
|
50
|
+
return super(sql, name, binds, *args)
|
47
51
|
end
|
48
52
|
|
49
53
|
kv_payload = collect(sql)
|
50
54
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
51
|
-
|
55
|
+
super(sql, name, binds, *args)
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
@@ -8,16 +8,11 @@ module Instana
|
|
8
8
|
# This module supports instrumenting ActiveRecord with the postgresql adapter. Only
|
9
9
|
# versions >= 3.1 are supported.
|
10
10
|
#
|
11
|
-
def self.
|
11
|
+
def self.prepended(klass)
|
12
12
|
if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR > 0) ||
|
13
13
|
::ActiveRecord::VERSION::MAJOR >= 4
|
14
14
|
|
15
15
|
# ActiveRecord 3.1 and up
|
16
|
-
Instana::Util.method_alias(klass, :exec_query)
|
17
|
-
Instana::Util.method_alias(klass, :exec_delete)
|
18
|
-
Instana::Util.method_alias(klass, :execute)
|
19
|
-
|
20
|
-
|
21
16
|
@@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
|
22
17
|
end
|
23
18
|
end
|
@@ -27,14 +22,33 @@ module Instana
|
|
27
22
|
# @param sql [String]
|
28
23
|
# @return [Hash] Hash of collected KVs
|
29
24
|
#
|
30
|
-
def collect(sql)
|
25
|
+
def collect(sql, binds = nil)
|
31
26
|
payload = { :activerecord => {} }
|
32
|
-
|
27
|
+
|
33
28
|
payload[:activerecord][:adapter] = @config[:adapter]
|
34
29
|
payload[:activerecord][:host] = @config[:host]
|
35
30
|
payload[:activerecord][:db] = @config[:database]
|
36
31
|
payload[:activerecord][:username] = @config[:username]
|
32
|
+
|
33
|
+
if ::Instana.config[:sanitize_sql]
|
34
|
+
payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
|
35
|
+
else
|
36
|
+
# No sanitization so raw SQL and collect up binds
|
37
|
+
payload[:activerecord][:sql] = sql
|
38
|
+
|
39
|
+
# FIXME: Only works on Rails 5 as the bind format varied in previous versions of Rails
|
40
|
+
if binds.is_a?(Array)
|
41
|
+
raw_binds = []
|
42
|
+
binds.each { |x| raw_binds << x.value_before_type_cast }
|
43
|
+
payload[:activerecord][:binds] = raw_binds
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
37
47
|
payload
|
48
|
+
rescue Exception => e
|
49
|
+
::Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
50
|
+
ensure
|
51
|
+
return payload
|
38
52
|
end
|
39
53
|
|
40
54
|
# In the spirit of ::ActiveRecord::ExplainSubscriber.ignore_payload? There are
|
@@ -48,36 +62,36 @@ module Instana
|
|
48
62
|
IGNORED_PAYLOADS.include?(name) || IGNORED_SQL.include?(sql)
|
49
63
|
end
|
50
64
|
|
51
|
-
def
|
65
|
+
def exec_query(sql, name = 'SQL', binds = [], *args)
|
52
66
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
|
53
|
-
return
|
67
|
+
return super(sql, name, binds, *args)
|
54
68
|
end
|
55
69
|
|
56
|
-
kv_payload = collect(sql)
|
70
|
+
kv_payload = collect(sql, binds)
|
57
71
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
58
|
-
|
72
|
+
super(sql, name, binds, *args)
|
59
73
|
end
|
60
74
|
end
|
61
75
|
|
62
|
-
def
|
76
|
+
def exec_delete(sql, name = nil, binds = [])
|
63
77
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
|
64
|
-
return
|
78
|
+
return super(sql, name, binds)
|
65
79
|
end
|
66
80
|
|
67
|
-
kv_payload = collect(sql)
|
81
|
+
kv_payload = collect(sql, binds)
|
68
82
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
69
|
-
|
83
|
+
super(sql, name, binds)
|
70
84
|
end
|
71
85
|
end
|
72
86
|
|
73
|
-
def
|
87
|
+
def execute(sql, name = nil)
|
74
88
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
|
75
|
-
return
|
89
|
+
return super(sql, name)
|
76
90
|
end
|
77
91
|
|
78
92
|
kv_payload = collect(sql)
|
79
93
|
::Instana.tracer.trace(:activerecord, kv_payload) do
|
80
|
-
|
94
|
+
super(sql, name)
|
81
95
|
end
|
82
96
|
end
|
83
97
|
end
|