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
data/lib/instana/setup.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2016
|
3
|
+
|
1
4
|
require 'oj_check'
|
2
5
|
|
3
6
|
require "instana/base"
|
@@ -7,10 +10,12 @@ require "instana/collector"
|
|
7
10
|
require "instana/secrets"
|
8
11
|
require "instana/tracer"
|
9
12
|
require "instana/tracing/processor"
|
10
|
-
|
13
|
+
|
14
|
+
require 'instana/activator'
|
11
15
|
|
12
16
|
::Instana.setup
|
13
17
|
::Instana.agent.setup
|
18
|
+
::Instana::Activator.start
|
14
19
|
|
15
20
|
# Register the metric collectors
|
16
21
|
unless RUBY_PLATFORM == 'java'.freeze
|
data/lib/instana/thread_local.rb
CHANGED
data/lib/instana/tracer.rb
CHANGED
data/lib/instana/tracing/span.rb
CHANGED
data/lib/instana/util.rb
CHANGED
@@ -1,47 +1,10 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2016
|
3
|
+
|
1
4
|
module Instana
|
2
5
|
module Util
|
3
6
|
class << self
|
4
7
|
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
8
|
# Debugging helper method
|
46
9
|
#
|
47
10
|
def pry!
|
@@ -246,7 +209,7 @@ module Instana
|
|
246
209
|
#
|
247
210
|
def id_to_header(id)
|
248
211
|
return '' unless id.is_a?(String)
|
249
|
-
# Only send 64bit IDs downstream for now
|
212
|
+
# Only send 64bit IDs downstream for now
|
250
213
|
id.length == 32 ? id[16..-1] : id
|
251
214
|
end
|
252
215
|
|
data/lib/instana/version.rb
CHANGED
data/lib/oj_check.rb
CHANGED
data/lib/opentracing.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class ActivatorTest < Minitest::Test
|
7
|
+
def test_start
|
8
|
+
refute_nil Instana::Activator.trace_point
|
9
|
+
assert Instana::Activator.trace_point.enabled?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_klass_call
|
13
|
+
assert_equal [], Instana::Activator.call
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_instance_call
|
17
|
+
subject = Class.new(Instana::Activator) do
|
18
|
+
def can_instrument?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def instrument
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal 1, Instana::Activator.call.length
|
28
|
+
assert subject.call
|
29
|
+
end
|
30
|
+
end
|
data/test/agent/agent_test.rb
CHANGED
data/test/config_test.rb
CHANGED
@@ -1,57 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../apps/cuba')
|
4
|
-
require 'rack/test'
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2016
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
require 'test_helper'
|
5
|
+
require 'rack/test'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class CubaTest < Minitest::Test
|
8
|
+
include Rack::Test::Methods
|
9
|
+
APP = Rack::Builder.parse_file('test/support/apps/cuba/config.ru').first
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
def app
|
12
|
+
APP
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic_get
|
16
|
+
clear_all!
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
r = get '/hello'
|
19
|
+
assert last_response.ok?
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
assert r.headers.key?("X-Instana-T")
|
22
|
+
assert r.headers.key?("X-Instana-S")
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
spans = ::Instana.processor.queued_spans
|
25
|
+
assert_equal 1, spans.count
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
first_span = spans.first
|
28
|
+
assert_equal :rack, first_span[:n]
|
29
|
+
assert first_span.key?(:data)
|
30
|
+
assert first_span[:data].key?(:http)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
assert first_span[:data][:http].key?(:method)
|
33
|
+
assert_equal "GET", first_span[:data][:http][:method]
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
assert first_span[:data][:http].key?(:url)
|
36
|
+
assert_equal "/hello", first_span[:data][:http][:url]
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
assert first_span[:data][:http].key?(:status)
|
39
|
+
assert_equal 200, first_span[:data][:http][:status]
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
assert first_span[:data][:http].key?(:host)
|
42
|
+
assert_equal "example.org", first_span[:data][:http][:host]
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
def test_path_template
|
46
|
+
clear_all!
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
r = get '/greet/instana'
|
49
|
+
assert last_response.ok?
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
spans = ::Instana.processor.queued_spans
|
52
|
+
assert_equal 1, spans.count
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
54
|
+
first_span = spans.first
|
55
|
+
assert_equal :rack, first_span[:n]
|
56
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
56
57
|
end
|
57
58
|
end
|
@@ -1,58 +1,60 @@
|
|
1
1
|
|
2
|
-
if defined?(::Roda)
|
3
|
-
require 'test_helper'
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + '/../apps/roda')
|
5
|
-
require 'rack/test'
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
# (c) Copyright IBM Corp. 2021
|
4
|
+
# (c) Copyright Instana Inc. 2016
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
require 'test_helper'
|
7
|
+
require 'rack/test'
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
class RodaTest < Minitest::Test
|
10
|
+
include Rack::Test::Methods
|
11
|
+
APP = Rack::Builder.parse_file('test/support/apps/roda/config.ru').first
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
def app
|
14
|
+
APP
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basic_get
|
18
|
+
clear_all!
|
19
|
+
|
20
|
+
r = get '/hello'
|
21
|
+
assert last_response.ok?
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
assert r.headers.key?("X-Instana-T")
|
24
|
+
assert r.headers.key?("X-Instana-S")
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
spans = ::Instana.processor.queued_spans
|
27
|
+
assert_equal 1, spans.count
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
first_span = spans.first
|
30
|
+
assert_equal :rack, first_span[:n]
|
31
|
+
assert first_span.key?(:data)
|
32
|
+
assert first_span[:data].key?(:http)
|
30
33
|
|
31
|
-
|
32
|
-
|
34
|
+
assert first_span[:data][:http].key?(:method)
|
35
|
+
assert_equal "GET", first_span[:data][:http][:method]
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
assert first_span[:data][:http].key?(:url)
|
38
|
+
assert_equal "/hello", first_span[:data][:http][:url]
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
assert first_span[:data][:http].key?(:status)
|
41
|
+
assert_equal 200, first_span[:data][:http][:status]
|
42
|
+
|
43
|
+
assert first_span[:data][:http].key?(:host)
|
44
|
+
assert_equal "example.org", first_span[:data][:http][:host]
|
45
|
+
end
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_path_template
|
45
|
-
clear_all!
|
47
|
+
def test_path_template
|
48
|
+
clear_all!
|
46
49
|
|
47
|
-
|
48
|
-
|
50
|
+
r = get '/greet/instana'
|
51
|
+
assert last_response.ok?
|
49
52
|
|
50
|
-
|
51
|
-
|
53
|
+
spans = ::Instana.processor.queued_spans
|
54
|
+
assert_equal 1, spans.count
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
56
|
+
first_span = spans.first
|
57
|
+
assert_equal :rack, first_span[:n]
|
58
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
57
59
|
end
|
58
60
|
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2016
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
class SinatraTest < Minitest::Test
|
8
|
+
include Rack::Test::Methods
|
9
|
+
APP = Rack::Builder.parse_file('test/support/apps/sinatra/config.ru').first
|
10
|
+
|
11
|
+
def app
|
12
|
+
APP
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic_get
|
16
|
+
clear_all!
|
17
|
+
|
18
|
+
r = get '/'
|
19
|
+
assert last_response.ok?
|
20
|
+
|
21
|
+
|
22
|
+
spans = ::Instana.processor.queued_spans
|
23
|
+
assert_equal 1, spans.count
|
24
|
+
|
25
|
+
rack_span = spans.first
|
26
|
+
assert_equal :rack, rack_span[:n]
|
27
|
+
# ::Instana::Util.pry!
|
28
|
+
|
29
|
+
assert r.headers.key?("X-Instana-T")
|
30
|
+
assert r.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
|
31
|
+
assert r.headers.key?("X-Instana-S")
|
32
|
+
assert r.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
|
33
|
+
assert r.headers.key?("X-Instana-L")
|
34
|
+
assert r.headers["X-Instana-L"] == '1'
|
35
|
+
assert r.headers.key?("Server-Timing")
|
36
|
+
assert r.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
|
37
|
+
|
38
|
+
assert rack_span.key?(:data)
|
39
|
+
assert rack_span[:data].key?(:http)
|
40
|
+
assert rack_span[:data][:http].key?(:method)
|
41
|
+
assert_equal "GET", rack_span[:data][:http][:method]
|
42
|
+
|
43
|
+
assert rack_span[:data][:http].key?(:url)
|
44
|
+
assert_equal "/", rack_span[:data][:http][:url]
|
45
|
+
|
46
|
+
assert rack_span[:data][:http].key?(:status)
|
47
|
+
assert_equal 200, rack_span[:data][:http][:status]
|
48
|
+
|
49
|
+
assert rack_span[:data][:http].key?(:host)
|
50
|
+
assert_equal "example.org", rack_span[:data][:http][:host]
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_path_template
|
54
|
+
clear_all!
|
55
|
+
|
56
|
+
r = get '/greet/instana'
|
57
|
+
assert last_response.ok?
|
58
|
+
|
59
|
+
spans = ::Instana.processor.queued_spans
|
60
|
+
assert_equal 1, spans.count
|
61
|
+
|
62
|
+
first_span = spans.first
|
63
|
+
assert_equal :rack, first_span[:n]
|
64
|
+
assert_equal '/greet/:name', first_span[:data][:http][:path_tpl]
|
65
65
|
end
|
66
66
|
end
|