instana 1.192.1 → 1.193.5
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 +200 -133
- data/.gitignore +3 -0
- data/.rubocop.yml +10 -1145
- data/.rubocop_todo.yml +1140 -0
- data/Appraisals +103 -0
- data/Gemfile +14 -32
- data/LICENSE +2 -1
- data/Rakefile +19 -39
- data/benchmarks/10k-rack-traces.rb +3 -0
- data/benchmarks/Gemfile +4 -0
- data/benchmarks/id_generation.rb +4 -0
- data/benchmarks/opentracing.rb +4 -0
- data/benchmarks/rack_vanilla_vs_traced.rb +3 -0
- data/benchmarks/stackprof_rack_tracing.rb +3 -0
- data/benchmarks/time_processing.rb +4 -0
- data/bin/console +8 -4
- data/examples/opentracing.rb +4 -0
- data/examples/tracing.rb +4 -0
- data/extras/license_header.rb +44 -0
- data/gemfiles/.bundle/config +1 -2
- data/gemfiles/cuba_30.gemfile +18 -0
- data/gemfiles/dalli_20.gemfile +18 -0
- data/gemfiles/excon_02.gemfile +18 -0
- data/gemfiles/graphql_10.gemfile +18 -0
- data/gemfiles/grpc_10.gemfile +18 -0
- data/gemfiles/net_http_01.gemfile +17 -0
- data/gemfiles/rack_16.gemfile +18 -0
- data/gemfiles/rack_20.gemfile +18 -0
- data/gemfiles/rails_42.gemfile +21 -0
- data/gemfiles/rails_50.gemfile +21 -0
- data/gemfiles/rails_52.gemfile +21 -0
- data/gemfiles/rails_60.gemfile +21 -0
- data/gemfiles/redis_40.gemfile +18 -0
- data/gemfiles/resque_122.gemfile +19 -0
- data/gemfiles/resque_20.gemfile +18 -0
- data/gemfiles/rest_client_16.gemfile +18 -0
- data/gemfiles/rest_client_20.gemfile +18 -0
- data/gemfiles/roda_20.gemfile +18 -0
- data/gemfiles/roda_30.gemfile +18 -0
- data/gemfiles/sidekiq_42.gemfile +18 -0
- data/gemfiles/sidekiq_50.gemfile +18 -0
- data/gemfiles/sinatra_14.gemfile +18 -0
- data/instana.gemspec +5 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +44 -0
- data/lib/instana/activators/action_cable.rb +24 -0
- data/lib/instana/activators/action_controller_api.rb +21 -0
- data/lib/instana/activators/action_controller_base.rb +21 -0
- data/lib/instana/activators/action_view.rb +21 -0
- data/lib/instana/activators/active_record.rb +21 -0
- data/lib/instana/activators/cuba.rb +21 -0
- data/lib/instana/activators/dalli.rb +23 -0
- data/lib/instana/activators/excon.rb +20 -0
- data/lib/instana/activators/graphql.rb +22 -0
- data/lib/instana/activators/grpc_client.rb +20 -0
- data/lib/instana/activators/grpc_server.rb +20 -0
- data/lib/instana/activators/net_http.rb +20 -0
- data/lib/instana/activators/rack.rb +16 -0
- data/lib/instana/activators/rails.rb +18 -0
- data/lib/instana/activators/redis.rb +20 -0
- data/lib/instana/activators/resque_client.rb +21 -0
- data/lib/instana/activators/resque_worker.rb +33 -0
- data/lib/instana/activators/rest_client.rb +20 -0
- data/lib/instana/activators/roda.rb +21 -0
- data/lib/instana/activators/sidekiq_client.rb +24 -0
- data/lib/instana/activators/sidekiq_worker.rb +24 -0
- data/lib/instana/activators/sinatra.rb +21 -0
- data/lib/instana/agent.rb +3 -0
- data/lib/instana/agent/helpers.rb +3 -0
- data/lib/instana/agent/hooks.rb +3 -0
- data/lib/instana/agent/tasks.rb +3 -0
- data/lib/instana/base.rb +3 -0
- data/lib/instana/collector.rb +3 -0
- data/lib/instana/collectors/gc.rb +3 -0
- data/lib/instana/collectors/memory.rb +3 -0
- data/lib/instana/collectors/thread.rb +3 -0
- data/lib/instana/config.rb +3 -0
- data/lib/instana/frameworks/cuba.rb +9 -13
- data/lib/instana/frameworks/rails.rb +22 -32
- data/lib/instana/frameworks/roda.rb +10 -13
- data/lib/instana/frameworks/sinatra.rb +4 -8
- data/lib/instana/helpers.rb +3 -0
- data/lib/instana/instrumentation/action_cable.rb +53 -0
- data/lib/instana/instrumentation/action_controller.rb +84 -0
- data/lib/instana/instrumentation/action_view.rb +30 -0
- data/lib/instana/instrumentation/active_record.rb +50 -0
- data/lib/instana/instrumentation/dalli.rb +10 -18
- data/lib/instana/instrumentation/excon.rb +54 -57
- data/lib/instana/instrumentation/graphql.rb +19 -18
- data/lib/instana/instrumentation/grpc.rb +73 -66
- data/lib/instana/instrumentation/instrumented_request.rb +6 -1
- data/lib/instana/instrumentation/net-http.rb +46 -47
- data/lib/instana/instrumentation/rack.rb +4 -0
- data/lib/instana/instrumentation/redis.rb +13 -18
- data/lib/instana/instrumentation/resque.rb +17 -50
- data/lib/instana/instrumentation/rest-client.rb +5 -17
- data/lib/instana/instrumentation/sidekiq-client.rb +3 -9
- data/lib/instana/instrumentation/sidekiq-worker.rb +3 -9
- data/lib/instana/opentracing/carrier.rb +3 -0
- data/lib/instana/opentracing/tracer.rb +3 -0
- data/lib/instana/rack.rb +4 -0
- data/lib/instana/secrets.rb +10 -7
- data/lib/instana/setup.rb +6 -1
- data/lib/instana/thread_local.rb +3 -0
- data/lib/instana/tracer.rb +3 -0
- data/lib/instana/tracing/processor.rb +3 -0
- data/lib/instana/tracing/span.rb +3 -0
- data/lib/instana/tracing/span_context.rb +3 -0
- data/lib/instana/util.rb +4 -41
- data/lib/instana/version.rb +4 -1
- data/lib/oj_check.rb +3 -0
- data/lib/opentracing.rb +3 -0
- data/test/activator_test.rb +30 -0
- data/test/agent/agent_test.rb +3 -0
- data/test/benchmarks/bench_id_generation.rb +3 -0
- data/test/benchmarks/bench_opentracing.rb +3 -0
- data/test/config_test.rb +3 -0
- data/test/frameworks/cuba_test.rb +41 -40
- data/test/frameworks/roda_test.rb +43 -41
- data/test/frameworks/sinatra_test.rb +64 -64
- data/test/instana_test.rb +3 -0
- data/test/instrumentation/dalli_test.rb +3 -0
- data/test/instrumentation/excon_test.rb +4 -0
- data/test/instrumentation/graphql_test.rb +3 -0
- data/test/instrumentation/grpc_test.rb +5 -1
- data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +4 -0
- data/test/instrumentation/{instrumented_request_test.rb → rack_instrumented_request_test.rb} +4 -1
- data/test/{frameworks → instrumentation}/rack_test.rb +3 -1
- data/test/instrumentation/rails_action_cable_test.rb +131 -0
- data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +40 -21
- data/test/instrumentation/rails_action_view_test.rb +151 -0
- data/test/instrumentation/rails_active_record_test.rb +122 -0
- data/test/instrumentation/redis_test.rb +3 -0
- data/test/instrumentation/resque_test.rb +6 -11
- data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +9 -0
- data/test/instrumentation/sidekiq-client_test.rb +4 -0
- data/test/instrumentation/sidekiq-worker_test.rb +4 -0
- data/test/secrets_test.rb +3 -0
- data/test/support/apps/active_record/active_record.rb +24 -0
- data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +4 -1
- data/test/{apps → support/apps/grpc}/grpc_server.rb +3 -0
- data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +3 -0
- data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +10 -13
- data/test/{models → support/apps/rails/models}/block.rb +4 -1
- data/test/{models → support/apps/rails/models}/block6.rb +3 -0
- data/test/support/apps/resque/boot.rb +5 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +3 -0
- data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +3 -0
- data/test/support/apps/sidekiq/boot.rb +25 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +3 -0
- data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +3 -0
- data/test/{servers → support/apps}/sidekiq/worker.rb +5 -2
- data/test/support/helpers.rb +97 -0
- data/test/test_helper.rb +27 -144
- data/test/tracing/custom_test.rb +3 -0
- data/test/tracing/id_management_test.rb +4 -0
- data/test/tracing/opentracing_test.rb +3 -0
- data/test/tracing/tracer_async_test.rb +3 -0
- data/test/tracing/tracer_test.rb +3 -0
- metadata +105 -96
- data/gemfiles/libraries.gemfile +0 -73
- 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/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -58
- data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -194
- data/lib/instana/frameworks/instrumentation/action_view.rb +0 -43
- data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -87
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -62
- data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -103
- 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/frameworks/rails/actionview3_test.rb +0 -210
- data/test/frameworks/rails/actionview4_test.rb +0 -208
- data/test/frameworks/rails/actionview5_test.rb +0 -221
- data/test/frameworks/rails/activerecord_test.rb +0 -279
- data/test/servers/helpers/sidekiq_worker_initializer.rb +0 -27
@@ -0,0 +1,122 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
require 'support/apps/active_record/active_record'
|
6
|
+
|
7
|
+
class RailsActiveRecordTest < Minitest::Test
|
8
|
+
def setup
|
9
|
+
skip unless ENV['DATABASE_URL']
|
10
|
+
@connection = ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
|
11
|
+
ActiveRecord::Migration.suppress_messages do
|
12
|
+
ActiveRecord::Migration.run(CreateBlocks, direction: :up)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
ActiveRecord::Migration.suppress_messages do
|
18
|
+
ActiveRecord::Migration.run(CreateBlocks, direction: :down)
|
19
|
+
end
|
20
|
+
ActiveRecord::Base.remove_connection(@connection)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_config_defaults
|
24
|
+
assert ::Instana.config[:sanitize_sql] == true
|
25
|
+
assert ::Instana.config[:active_record].is_a?(Hash)
|
26
|
+
assert ::Instana.config[:active_record].key?(:enabled)
|
27
|
+
assert_equal true, ::Instana.config[:active_record][:enabled]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_create
|
31
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
32
|
+
Block.create(name: 'core', color: 'blue')
|
33
|
+
end
|
34
|
+
|
35
|
+
spans = ::Instana.processor.queued_spans
|
36
|
+
assert_equal 2, spans.length
|
37
|
+
span = find_first_span_by_name(spans, :activerecord)
|
38
|
+
data = span[:data][:activerecord]
|
39
|
+
|
40
|
+
assert data[:sql].start_with?('INSERT INTO')
|
41
|
+
assert 'core', data[:binds][0]
|
42
|
+
assert 'blue', data[:binds][1]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_read
|
46
|
+
Block.create(name: 'core', color: 'blue')
|
47
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
48
|
+
Block.find_by(name: 'core')
|
49
|
+
end
|
50
|
+
|
51
|
+
spans = ::Instana.processor.queued_spans
|
52
|
+
assert_equal 2, spans.length
|
53
|
+
span = find_first_span_by_name(spans, :activerecord)
|
54
|
+
data = span[:data][:activerecord]
|
55
|
+
|
56
|
+
assert data[:sql].start_with?('SELECT')
|
57
|
+
assert 'core', data[:binds][0]
|
58
|
+
assert 1, data[:binds][1]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_update
|
62
|
+
Block.create(name: 'core', color: 'blue')
|
63
|
+
b = Block.find_by(name: 'core')
|
64
|
+
|
65
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
66
|
+
b.color = 'red'
|
67
|
+
b.save
|
68
|
+
end
|
69
|
+
|
70
|
+
spans = ::Instana.processor.queued_spans
|
71
|
+
assert_equal 2, spans.length
|
72
|
+
span = find_first_span_by_name(spans, :activerecord)
|
73
|
+
data = span[:data][:activerecord]
|
74
|
+
|
75
|
+
assert data[:sql].start_with?('UPDATE')
|
76
|
+
assert 'red', data[:binds][0]
|
77
|
+
assert 1, data[:binds][2]
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_delete
|
81
|
+
b = Block.create(name: 'core', color: 'blue')
|
82
|
+
|
83
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
84
|
+
b.delete
|
85
|
+
end
|
86
|
+
|
87
|
+
spans = ::Instana.processor.queued_spans
|
88
|
+
assert_equal 2, spans.length
|
89
|
+
span = find_first_span_by_name(spans, :activerecord)
|
90
|
+
data = span[:data][:activerecord]
|
91
|
+
|
92
|
+
assert data[:sql].start_with?('DELETE')
|
93
|
+
assert 1, data[:binds][0]
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_raw
|
97
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
98
|
+
ActiveRecord::Base.connection.execute('SELECT 1')
|
99
|
+
end
|
100
|
+
|
101
|
+
spans = ::Instana.processor.queued_spans
|
102
|
+
assert_equal 2, spans.length
|
103
|
+
span = find_first_span_by_name(spans, :activerecord)
|
104
|
+
data = span[:data][:activerecord]
|
105
|
+
|
106
|
+
assert 'SELECT 1', data[:sql]
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_raw_error
|
110
|
+
assert_raises ActiveRecord::StatementInvalid do
|
111
|
+
Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
|
112
|
+
ActiveRecord::Base.connection.execute('INVALID')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
spans = ::Instana.processor.queued_spans
|
117
|
+
assert_equal 2, spans.length
|
118
|
+
span = find_first_span_by_name(spans, :activerecord)
|
119
|
+
|
120
|
+
assert_equal 1, span[:ec]
|
121
|
+
end
|
122
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2018
|
3
|
+
|
1
4
|
require 'test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
if ENV.key?('REDIS_URL')
|
7
|
-
::Resque.redis = ENV['REDIS_URL']
|
8
|
-
elsif ENV.key?('REDIS_URL')
|
9
|
-
::Resque.redis = ENV['REDIS_URL']
|
10
|
-
else
|
11
|
-
::Resque.redis = 'localhost:6379'
|
12
|
-
end
|
5
|
+
require 'support/apps/resque/boot'
|
6
|
+
|
7
|
+
::Resque.redis = ENV['REDIS_URL']
|
13
8
|
|
14
9
|
class ResqueClientTest < Minitest::Test
|
15
10
|
def setup
|
@@ -1,6 +1,15 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2016
|
3
|
+
|
1
4
|
require 'test_helper'
|
5
|
+
require 'support/apps/http_endpoint/boot'
|
2
6
|
|
3
7
|
class RestClientTest < Minitest::Test
|
8
|
+
def setup
|
9
|
+
# See https://github.com/rest-client/rest-client/issues/612
|
10
|
+
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ciphers] = OpenSSL::SSL::SSLContext.new.ciphers
|
11
|
+
end
|
12
|
+
|
4
13
|
def test_config_defaults
|
5
14
|
assert ::Instana.config[:'rest-client'].is_a?(Hash)
|
6
15
|
assert ::Instana.config[:'rest-client'].key?(:enabled)
|
data/test/secrets_test.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'rails'
|
5
|
+
require 'active_record/railtie'
|
6
|
+
|
7
|
+
migration_class = if ActiveRecord::Migration.respond_to?(:[])
|
8
|
+
ActiveRecord::Migration[4.2]
|
9
|
+
else
|
10
|
+
ActiveRecord::Migration
|
11
|
+
end
|
12
|
+
|
13
|
+
class CreateBlocks < migration_class
|
14
|
+
def change
|
15
|
+
create_table :blocks do |t|
|
16
|
+
t.string :name
|
17
|
+
t.string :color
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Block < ActiveRecord::Base
|
24
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2017
|
3
|
+
|
4
|
+
require_relative 'grpc_server'
|
2
5
|
|
3
6
|
::Instana.logger.info "Booting instrumented gRPC server on port 50051 for tests."
|
4
7
|
|
@@ -1,22 +1,19 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2017
|
1
3
|
|
2
4
|
::Instana.logger.warn "Starting background Ruby on Rails #{Rails::VERSION::STRING} application on port 3205"
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require "
|
9
|
-
require "action_controller/railtie" # require more if needed
|
6
|
+
require "rails"
|
7
|
+
require "active_record/railtie"
|
8
|
+
require "active_model/railtie"
|
9
|
+
require "action_controller/railtie"
|
10
|
+
require "active_model/railtie"
|
10
11
|
require 'rack/handler/puma'
|
11
12
|
|
12
13
|
if Rails::VERSION::STRING >= '6.0'
|
13
|
-
|
14
|
-
system("mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js")
|
15
|
-
# Rails 6 Issue: https://github.com/rails/rails/issues/37183
|
16
|
-
class ApplicationController < ActionController::Base
|
17
|
-
end
|
14
|
+
require_relative 'models/block6'
|
18
15
|
else
|
19
|
-
|
16
|
+
require_relative 'models/block'
|
20
17
|
end
|
21
18
|
|
22
19
|
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
|
@@ -62,7 +59,7 @@ class RailsTestApp < Rails::Application
|
|
62
59
|
# uncomment below to display errors
|
63
60
|
# config.consider_all_requests_local = true
|
64
61
|
|
65
|
-
config.paths['app/views'].unshift(File.
|
62
|
+
config.paths['app/views'].unshift(File.join(__dir__, 'views'))
|
66
63
|
|
67
64
|
config.active_support.deprecation = :stderr
|
68
65
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2017
|
3
|
+
|
1
4
|
class Block < ActiveRecord::Base
|
2
5
|
def do_work(*args)
|
3
6
|
block = Block.first
|
@@ -7,7 +10,7 @@ class Block < ActiveRecord::Base
|
|
7
10
|
end
|
8
11
|
end
|
9
12
|
|
10
|
-
class CreateBlocks < ActiveRecord::Migration
|
13
|
+
class CreateBlocks < ActiveRecord::Migration[4.2]
|
11
14
|
def change
|
12
15
|
create_table :blocks do |t|
|
13
16
|
t.string :name
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Hook into sidekiq to control the current mode
|
2
|
+
|
3
|
+
# (c) Copyright IBM Corp. 2021
|
4
|
+
# (c) Copyright Instana Inc. 2021
|
5
|
+
|
6
|
+
$sidekiq_mode = :client
|
7
|
+
class << Sidekiq
|
8
|
+
def server?
|
9
|
+
$sidekiq_mode == :server
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure redis for sidekiq client
|
14
|
+
Sidekiq.configure_client do |config|
|
15
|
+
config.redis = { url: ENV['REDIS_URL'] }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Configure redis for sidekiq worker
|
19
|
+
$sidekiq_mode = :server
|
20
|
+
::Sidekiq.configure_server do |config|
|
21
|
+
config.redis = { url: ENV['REDIS_URL'] }
|
22
|
+
end
|
23
|
+
$sidekiq_mode = :client
|
24
|
+
|
25
|
+
require_relative 'worker'
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2017
|
3
|
+
|
1
4
|
require 'sidekiq/launcher'
|
2
5
|
require 'sidekiq/cli'
|
3
6
|
require 'sidekiq/api'
|
4
7
|
require 'sidekiq/processor'
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
require_relative 'jobs/sidekiq_job_1'
|
10
|
+
require_relative 'jobs/sidekiq_job_2'
|
8
11
|
|
9
12
|
::Instana.logger.info "Booting instrumented sidekiq worker for tests."
|
10
13
|
::Sidekiq.logger.level = ::Logger::FATAL
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (c) Copyright IBM Corp. 2021
|
4
|
+
# (c) Copyright Instana Inc. 2021
|
5
|
+
|
6
|
+
module Instana
|
7
|
+
module TestHelpers
|
8
|
+
# Used to reset the gem to boot state. It clears out any queued and/or staged
|
9
|
+
# traces and resets the tracer to no active trace.
|
10
|
+
#
|
11
|
+
def clear_all!
|
12
|
+
::Instana.processor.clear!
|
13
|
+
::Instana.tracer.clear!
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def disable_redis_instrumentation
|
18
|
+
::Instana.config[:redis][:enabled] = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def enable_redis_instrumentation
|
22
|
+
::Instana.config[:redis][:enabled] = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_sdk_span(json_span, sdk_hash = {}, errored = false, _ec = 1)
|
26
|
+
assert_equal :sdk, json_span[:n]
|
27
|
+
assert json_span.key?(:k)
|
28
|
+
assert json_span.key?(:d)
|
29
|
+
assert json_span.key?(:ts)
|
30
|
+
|
31
|
+
sdk_hash.each do |k, v|
|
32
|
+
assert_equal v, json_span[:data][:sdk][k]
|
33
|
+
end
|
34
|
+
|
35
|
+
return unless errored
|
36
|
+
|
37
|
+
assert_equal true, json_span[:error]
|
38
|
+
assert_equal 1, json_span[:ec]
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_spans_by_name(spans, name)
|
42
|
+
spans.select do |span|
|
43
|
+
(span[:n] == :sdk && span[:data][:sdk][:name] == name) || span[:n] == name
|
44
|
+
end.tap do |result|
|
45
|
+
raise StandardError, "No SDK spans (#{name}) could be found" if result.empty?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_first_span_by_name(spans, name)
|
50
|
+
spans.each do |span|
|
51
|
+
case span[:n]
|
52
|
+
when :sdk
|
53
|
+
return span if span[:data][:sdk][:name] == name
|
54
|
+
when name
|
55
|
+
return span
|
56
|
+
end
|
57
|
+
end
|
58
|
+
raise StandardError, "Span (#{name}) not found"
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_span_by_id(spans, id)
|
62
|
+
spans.each do |span|
|
63
|
+
return span if span[:s] == id
|
64
|
+
end
|
65
|
+
raise StandardError, "Span with id (#{id}) not found"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Finds the first span in +spans+ for which +block+ returns true
|
69
|
+
#
|
70
|
+
# ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
71
|
+
# span[:data][:activerecord][:sql] == sql
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# This helper will raise an exception if no span evaluates to true against he provided block.
|
75
|
+
#
|
76
|
+
# +spans+: +Array+ of spans to search
|
77
|
+
# +block+: The Ruby block to evaluate against each span
|
78
|
+
def find_first_span_by_qualifier(spans, &block)
|
79
|
+
spans.each do |span|
|
80
|
+
return span if block.call(span)
|
81
|
+
end
|
82
|
+
raise StandardError, 'Span with qualifier not found'
|
83
|
+
end
|
84
|
+
|
85
|
+
def has_postgres_database?
|
86
|
+
URI(ENV.fetch('DATABASE_URL', '')).scheme == 'postgres'
|
87
|
+
end
|
88
|
+
|
89
|
+
def has_mysql2_database?
|
90
|
+
URI(ENV.fetch('DATABASE_URL', '')).scheme == 'mysql2'
|
91
|
+
end
|
92
|
+
|
93
|
+
def has_mysql_database?
|
94
|
+
URI(ENV.fetch('DATABASE_URL', '')).scheme == 'mysql'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|