instana 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/instana/config.rb +1 -0
- data/lib/instana/frameworks/instrumentation/active_record.rb +1 -1
- data/lib/instana/instrumentation/redis.rb +82 -0
- data/lib/instana/tracing/span.rb +2 -2
- data/lib/instana/version.rb +1 -1
- data/test/instrumentation/redis_test.rb +141 -0
- data/test/instrumentation/sidekiq-client_test.rb +4 -1
- data/test/instrumentation/sidekiq-worker_test.rb +9 -0
- data/test/test_helper.rb +14 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b5079ebac90a5ee51a0a808661dd4ccf2f0a308
|
4
|
+
data.tar.gz: 61284e14d6d709258d7b67e5f0e582cc0fb9d72c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb5d83f78ae37c40b3e0d7a959391e67b938876cd13a0d1d07bc6c9b0638e0486626caf03349eb974dd5efc9bf62feb459607d978a57e557fd004709ebb9c74
|
7
|
+
data.tar.gz: adfdead8d412acb7bcaef9a1e51e9bdb70a4dd6aaaf323ffde5ddc4a5aa0950a6653b4015575f0fea65ad10b00b3fc71864d9cf61a5d1d5f2f41d5ab6b7ebba1
|
data/lib/instana/config.rb
CHANGED
@@ -23,6 +23,6 @@ if defined?(::ActiveRecord) && ::Instana.config[:active_record][:enabled]
|
|
23
23
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, ::Instana::Instrumentation::PostgreSQLAdapter)
|
24
24
|
|
25
25
|
else
|
26
|
-
::Instana.logger.
|
26
|
+
::Instana.logger.debug "Unsupported ActiveRecord adapter: #{ActiveRecord::Base.connection.adapter_name.downcase}"
|
27
27
|
end
|
28
28
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Instana
|
2
|
+
module Instrumentation
|
3
|
+
class Redis
|
4
|
+
def self.get_host(client)
|
5
|
+
client.host
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_port(client)
|
9
|
+
client.port
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.pipeline_command(pipeline)
|
13
|
+
pipeline.is_a?(::Redis::Pipeline::Multi) ? 'MULTI' : 'PIPELINE'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(::Redis) && ::Instana.config[:redis][:enabled]
|
20
|
+
::Redis::Client.class_eval do
|
21
|
+
def call_with_instana(*args, &block)
|
22
|
+
kv_payload = { redis: {} }
|
23
|
+
|
24
|
+
if !Instana.tracer.tracing?
|
25
|
+
return call_without_instana(*args, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
host = ::Instana::Instrumentation::Redis.get_host(self)
|
29
|
+
port = ::Instana::Instrumentation::Redis.get_port(self)
|
30
|
+
kv_payload[:redis] = {
|
31
|
+
connection: "#{host}:#{port}",
|
32
|
+
db: db,
|
33
|
+
command: args[0][0].to_s.upcase
|
34
|
+
}
|
35
|
+
::Instana.tracer.log_entry(:redis, kv_payload)
|
36
|
+
|
37
|
+
call_without_instana(*args, &block)
|
38
|
+
rescue => e
|
39
|
+
kv_payload[:redis][:error] = true
|
40
|
+
::Instana.tracer.log_info(kv_payload)
|
41
|
+
::Instana.tracer.log_error(e)
|
42
|
+
raise
|
43
|
+
ensure
|
44
|
+
::Instana.tracer.log_exit(:redis, {})
|
45
|
+
end
|
46
|
+
|
47
|
+
::Instana.logger.info "Instrumenting Redis"
|
48
|
+
|
49
|
+
alias call_without_instana call
|
50
|
+
alias call call_with_instana
|
51
|
+
|
52
|
+
def call_pipeline_with_instana(*args, &block)
|
53
|
+
kv_payload = { redis: {} }
|
54
|
+
|
55
|
+
if !Instana.tracer.tracing?
|
56
|
+
return call_pipeline_without_instana(*args, &block)
|
57
|
+
end
|
58
|
+
|
59
|
+
pipeline = args.first
|
60
|
+
host = ::Instana::Instrumentation::Redis.get_host(self)
|
61
|
+
port = ::Instana::Instrumentation::Redis.get_port(self)
|
62
|
+
kv_payload[:redis] = {
|
63
|
+
connection: "#{host}:#{port}",
|
64
|
+
db: db,
|
65
|
+
command: ::Instana::Instrumentation::Redis.pipeline_command(pipeline)
|
66
|
+
}
|
67
|
+
::Instana.tracer.log_entry(:redis, kv_payload)
|
68
|
+
|
69
|
+
call_pipeline_without_instana(*args, &block)
|
70
|
+
rescue => e
|
71
|
+
kv_payload[:redis][:error] = true
|
72
|
+
::Instana.tracer.log_info(kv_payload)
|
73
|
+
::Instana.tracer.log_error(e)
|
74
|
+
raise
|
75
|
+
ensure
|
76
|
+
::Instana.tracer.log_exit(:redis, {})
|
77
|
+
end
|
78
|
+
|
79
|
+
alias call_pipeline_without_instana call_pipeline
|
80
|
+
alias call_pipeline call_pipeline_with_instana
|
81
|
+
end
|
82
|
+
end
|
data/lib/instana/tracing/span.rb
CHANGED
@@ -2,9 +2,9 @@ module Instana
|
|
2
2
|
class Span
|
3
3
|
REGISTERED_SPANS = [ :actioncontroller, :actionview, :activerecord, :excon,
|
4
4
|
:memcache, :'net-http', :rack, :render, :'rpc-client',
|
5
|
-
:'rpc-server', :'sidekiq-client', :'sidekiq-worker' ].freeze
|
5
|
+
:'rpc-server', :'sidekiq-client', :'sidekiq-worker', :redis].freeze
|
6
6
|
ENTRY_SPANS = [ :rack, :'rpc-server', :'sidekiq-worker' ].freeze
|
7
|
-
EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'rpc-client', :'sidekiq-client' ].freeze
|
7
|
+
EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'rpc-client', :'sidekiq-client', :redis ].freeze
|
8
8
|
HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
|
9
9
|
|
10
10
|
attr_accessor :parent
|
data/lib/instana/version.rb
CHANGED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RedisTest < Minitest::Test
|
4
|
+
def test_normal_call
|
5
|
+
clear_all!
|
6
|
+
redis_client = create_redis_client
|
7
|
+
|
8
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
9
|
+
redis_client.set('hello', 'world')
|
10
|
+
end
|
11
|
+
redis_client.disconnect!
|
12
|
+
|
13
|
+
assert_redis_trace('SET')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_normal_call_with_error
|
17
|
+
clear_all!
|
18
|
+
redis_client = create_redis_client
|
19
|
+
|
20
|
+
redis_client.client.instance_eval do
|
21
|
+
def read
|
22
|
+
raise 'Something went wrong'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
27
|
+
begin
|
28
|
+
redis_client.set('hello', 'world')
|
29
|
+
rescue; end
|
30
|
+
end
|
31
|
+
redis_client.disconnect!
|
32
|
+
|
33
|
+
assert_redis_trace('SET', with_error: 'Something went wrong')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_pipeline_call
|
37
|
+
clear_all!
|
38
|
+
redis_client = create_redis_client
|
39
|
+
|
40
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
41
|
+
redis_client.pipelined do
|
42
|
+
exec_sample_pipeline_calls(redis_client)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_redis_trace('PIPELINE')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_pipeline_call_with_error
|
50
|
+
clear_all!
|
51
|
+
redis_client = create_redis_client
|
52
|
+
|
53
|
+
redis_client.client.instance_eval do
|
54
|
+
def read
|
55
|
+
raise 'Something went wrong'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
60
|
+
begin
|
61
|
+
redis_client.pipelined do
|
62
|
+
exec_sample_pipeline_calls(redis_client)
|
63
|
+
end
|
64
|
+
rescue; end
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_redis_trace('PIPELINE', with_error: 'Something went wrong')
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_multi_call
|
71
|
+
clear_all!
|
72
|
+
redis_client = create_redis_client
|
73
|
+
|
74
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
75
|
+
redis_client.multi do
|
76
|
+
exec_sample_pipeline_calls(redis_client)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_redis_trace('MULTI')
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_multi_call_with_error
|
84
|
+
clear_all!
|
85
|
+
redis_client = create_redis_client
|
86
|
+
|
87
|
+
redis_client.client.instance_eval do
|
88
|
+
def read
|
89
|
+
raise 'Something went wrong'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
94
|
+
begin
|
95
|
+
redis_client.multi do
|
96
|
+
exec_sample_pipeline_calls(redis_client)
|
97
|
+
end
|
98
|
+
rescue; end
|
99
|
+
end
|
100
|
+
|
101
|
+
assert_redis_trace('MULTI', with_error: 'Something went wrong')
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def create_redis_client
|
107
|
+
Redis.new(url: ENV['I_REDIS_URL'])
|
108
|
+
end
|
109
|
+
|
110
|
+
def exec_sample_pipeline_calls(redis_client)
|
111
|
+
redis_client.set('hello', 'world')
|
112
|
+
redis_client.set('other', 'world')
|
113
|
+
redis_client.hmset('awesome', 'wonderful', 'world')
|
114
|
+
end
|
115
|
+
|
116
|
+
def assert_redis_trace(command, with_error: nil)
|
117
|
+
assert_equal 1, ::Instana.processor.queue_count
|
118
|
+
trace = ::Instana.processor.queued_traces.first
|
119
|
+
|
120
|
+
assert_equal 2, trace.spans.count
|
121
|
+
first_span, second_span = trace.spans.to_a
|
122
|
+
|
123
|
+
# first_span is the parent of second_span
|
124
|
+
assert_equal first_span.id, second_span[:p]
|
125
|
+
assert_equal :sdk, first_span[:n]
|
126
|
+
assert_equal :redis, second_span[:n]
|
127
|
+
|
128
|
+
data = second_span[:data]
|
129
|
+
|
130
|
+
uri = URI.parse(ENV['I_REDIS_URL'])
|
131
|
+
assert_equal "#{uri.host}:#{uri.port}", data[:redis][:connection]
|
132
|
+
|
133
|
+
assert_equal 0, data[:redis][:db]
|
134
|
+
assert_equal command, data[:redis][:command]
|
135
|
+
|
136
|
+
if with_error
|
137
|
+
assert_equal true, data[:redis][:error]
|
138
|
+
assert_equal with_error, data[:log][:message]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -9,14 +9,15 @@ class SidekiqClientTest < Minitest::Test
|
|
9
9
|
|
10
10
|
def test_enqueue
|
11
11
|
clear_all!
|
12
|
-
|
13
12
|
Instana.tracer.start_or_continue_trace(:sidekiqtests) do
|
13
|
+
disable_redis_instrumentation
|
14
14
|
::Sidekiq::Client.push(
|
15
15
|
'queue' => 'some_random_queue',
|
16
16
|
'class' => ::SidekiqJobOne,
|
17
17
|
'args' => [1, 2, 3],
|
18
18
|
'retry' => false
|
19
19
|
)
|
20
|
+
enable_redis_instrumentation
|
20
21
|
end
|
21
22
|
|
22
23
|
queue = ::Sidekiq::Queue.new('some_random_queue')
|
@@ -30,6 +31,7 @@ class SidekiqClientTest < Minitest::Test
|
|
30
31
|
clear_all!
|
31
32
|
|
32
33
|
Instana.tracer.start_or_continue_trace(:sidekiqtests) do
|
34
|
+
disable_redis_instrumentation
|
33
35
|
add_sidekiq_exception_middleware
|
34
36
|
begin
|
35
37
|
::Sidekiq::Client.push(
|
@@ -39,6 +41,7 @@ class SidekiqClientTest < Minitest::Test
|
|
39
41
|
'retry' => false
|
40
42
|
)
|
41
43
|
rescue; end
|
44
|
+
enable_redis_instrumentation
|
42
45
|
remove_sidekiq_exception_middleware
|
43
46
|
end
|
44
47
|
|
@@ -12,6 +12,7 @@ class SidekiqServerTest < Minitest::Test
|
|
12
12
|
$sidekiq_mode = :server
|
13
13
|
inject_instrumentation
|
14
14
|
|
15
|
+
disable_redis_instrumentation
|
15
16
|
::Sidekiq.redis_pool.with do |redis|
|
16
17
|
redis.sadd('queues'.freeze, 'important')
|
17
18
|
redis.lpush(
|
@@ -26,6 +27,7 @@ class SidekiqServerTest < Minitest::Test
|
|
26
27
|
JSON
|
27
28
|
)
|
28
29
|
end
|
30
|
+
enable_redis_instrumentation
|
29
31
|
sleep 1
|
30
32
|
|
31
33
|
assert_equal 1, ::Instana.processor.queue_count
|
@@ -39,6 +41,7 @@ class SidekiqServerTest < Minitest::Test
|
|
39
41
|
$sidekiq_mode = :server
|
40
42
|
inject_instrumentation
|
41
43
|
|
44
|
+
disable_redis_instrumentation
|
42
45
|
::Sidekiq.redis_pool.with do |redis|
|
43
46
|
redis.sadd('queues'.freeze, 'important')
|
44
47
|
redis.lpush(
|
@@ -53,6 +56,8 @@ class SidekiqServerTest < Minitest::Test
|
|
53
56
|
JSON
|
54
57
|
)
|
55
58
|
end
|
59
|
+
enable_redis_instrumentation
|
60
|
+
|
56
61
|
sleep 1
|
57
62
|
assert_equal 1, ::Instana.processor.queue_count
|
58
63
|
assert_failed_worker_trace(::Instana.processor.queued_traces.first)
|
@@ -66,11 +71,13 @@ class SidekiqServerTest < Minitest::Test
|
|
66
71
|
inject_instrumentation
|
67
72
|
|
68
73
|
Instana.tracer.start_or_continue_trace(:sidekiqtests) do
|
74
|
+
disable_redis_instrumentation
|
69
75
|
::Sidekiq::Client.push(
|
70
76
|
'queue' => 'important',
|
71
77
|
'class' => ::SidekiqJobOne,
|
72
78
|
'args' => [1, 2, 3]
|
73
79
|
)
|
80
|
+
enable_redis_instrumentation
|
74
81
|
end
|
75
82
|
sleep 1
|
76
83
|
assert_equal 2, ::Instana.processor.queue_count
|
@@ -92,11 +99,13 @@ class SidekiqServerTest < Minitest::Test
|
|
92
99
|
inject_instrumentation
|
93
100
|
|
94
101
|
Instana.tracer.start_or_continue_trace(:sidekiqtests) do
|
102
|
+
disable_redis_instrumentation
|
95
103
|
::Sidekiq::Client.push(
|
96
104
|
'queue' => 'important',
|
97
105
|
'class' => ::SidekiqJobTwo,
|
98
106
|
'args' => [1, 2, 3]
|
99
107
|
)
|
108
|
+
enable_redis_instrumentation
|
100
109
|
end
|
101
110
|
sleep 1
|
102
111
|
assert_equal 2, ::Instana.processor.queue_count
|
data/test/test_helper.rb
CHANGED
@@ -65,3 +65,17 @@ def clear_all!
|
|
65
65
|
$redis.flushall if $redis
|
66
66
|
nil
|
67
67
|
end
|
68
|
+
|
69
|
+
def disable_redis_instrumentation
|
70
|
+
::Redis::Client.class_eval do
|
71
|
+
alias call call_without_instana
|
72
|
+
alias call_pipeline call_pipeline_without_instana
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def enable_redis_instrumentation
|
77
|
+
::Redis::Client.class_eval do
|
78
|
+
alias call call_with_instana
|
79
|
+
alias call_pipeline call_pipeline_with_instana
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Giacomo Lombardo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/instana/instrumentation/grpc.rb
|
205
205
|
- lib/instana/instrumentation/net-http.rb
|
206
206
|
- lib/instana/instrumentation/rack.rb
|
207
|
+
- lib/instana/instrumentation/redis.rb
|
207
208
|
- lib/instana/instrumentation/rest-client.rb
|
208
209
|
- lib/instana/instrumentation/sidekiq-client.rb
|
209
210
|
- lib/instana/instrumentation/sidekiq-worker.rb
|
@@ -245,6 +246,7 @@ files:
|
|
245
246
|
- test/instrumentation/excon_test.rb
|
246
247
|
- test/instrumentation/grpc_test.rb
|
247
248
|
- test/instrumentation/net-http_test.rb
|
249
|
+
- test/instrumentation/redis_test.rb
|
248
250
|
- test/instrumentation/rest-client_test.rb
|
249
251
|
- test/instrumentation/sidekiq-client_test.rb
|
250
252
|
- test/instrumentation/sidekiq-worker_test.rb
|
@@ -309,6 +311,7 @@ test_files:
|
|
309
311
|
- test/instrumentation/excon_test.rb
|
310
312
|
- test/instrumentation/grpc_test.rb
|
311
313
|
- test/instrumentation/net-http_test.rb
|
314
|
+
- test/instrumentation/redis_test.rb
|
312
315
|
- test/instrumentation/rest-client_test.rb
|
313
316
|
- test/instrumentation/sidekiq-client_test.rb
|
314
317
|
- test/instrumentation/sidekiq-worker_test.rb
|