instana 1.11.4 → 1.12.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/.circleci/config.yml +168 -0
- data/README.md +1 -1
- data/lib/instana/frameworks/cuba.rb +33 -0
- data/lib/instana/frameworks/instrumentation/action_controller.rb +11 -0
- data/lib/instana/frameworks/roda.rb +41 -0
- data/lib/instana/frameworks/sinatra.rb +17 -0
- data/lib/instana/instrumentation/rack.rb +23 -3
- data/lib/instana/instrumentation/redis.rb +41 -53
- data/lib/instana/test.rb +4 -3
- data/lib/instana/tracer.rb +26 -5
- data/lib/instana/tracing/span.rb +9 -0
- data/lib/instana/version.rb +1 -1
- data/test/apps/cuba.rb +4 -0
- data/test/apps/roda.rb +3 -0
- data/test/apps/sinatra.rb +4 -0
- data/test/frameworks/cuba_test.rb +14 -1
- data/test/frameworks/rack_test.rb +125 -65
- data/test/frameworks/rails/actioncontroller_test.rb +12 -0
- data/test/frameworks/roda_test.rb +14 -0
- data/test/frameworks/sinatra_test.rb +37 -15
- data/test/instrumentation/grpc_test.rb +1 -1
- data/test/instrumentation/redis_test.rb +25 -28
- data/test/instrumentation/resque_test.rb +9 -16
- data/test/instrumentation/sidekiq-client_test.rb +7 -0
- data/test/instrumentation/sidekiq-worker_test.rb +6 -0
- data/test/jobs/resque_error_job.rb +2 -2
- data/test/jobs/resque_fast_job.rb +2 -2
- data/test/test_helper.rb +3 -8
- data/test/tracing/opentracing_test.rb +21 -0
- data/test/tracing/tracer_test.rb +31 -1
- metadata +4 -6
- data/.travis.yml +0 -43
- data/test/tracing/trace_test.rb +0 -67
data/lib/instana/test.rb
CHANGED
@@ -7,14 +7,15 @@ module Instana
|
|
7
7
|
def setup_environment
|
8
8
|
# Set defaults if not set
|
9
9
|
ENV['MEMCACHED_HOST'] ||= '127.0.0.1:11211'
|
10
|
-
ENV['
|
11
|
-
ENV['
|
10
|
+
ENV['POSTGRES_HOST'] ||= "127.0.0.1"
|
11
|
+
ENV['POSTGRES_USER'] ||= "stan"
|
12
|
+
ENV['POSTGRES_PASSWORD'] ||= "stanlikesdata"
|
12
13
|
ENV['TRAVIS_MYSQL_HOST'] ||= "127.0.0.1"
|
13
14
|
ENV['TRAVIS_MYSQL_USER'] ||= "root"
|
14
15
|
|
15
16
|
if !ENV.key?('DATABASE_URL')
|
16
17
|
if ENV['DB_FLAVOR'] == 'postgresql'
|
17
|
-
ENV['DATABASE_URL'] = "postgresql://#{ENV['
|
18
|
+
ENV['DATABASE_URL'] = "postgresql://#{ENV['POSTGRES_USER']}:#{ENV['POSTGRES_PASSWORD']}@#{ENV['POSTGRES_HOST']}:5432/#{ENV['POSTGRES_USER']}"
|
18
19
|
elsif ENV['DB_FLAVOR'] == 'mysql'
|
19
20
|
ENV['DATABASE_URL'] = "mysql://#{ENV['TRAVIS_MYSQL_USER']}:#{ENV['TRAVIS_MYSQL_PASS']}@#{ENV['TRAVIS_MYSQL_HOST']}:3306/travis_ci_test"
|
20
21
|
else
|
data/lib/instana/tracer.rb
CHANGED
@@ -26,7 +26,7 @@ module Instana
|
|
26
26
|
# Will start a new trace or continue an on-going one (such as
|
27
27
|
# from incoming remote requests with context headers).
|
28
28
|
#
|
29
|
-
# @param name [String] the name of the span to start
|
29
|
+
# @param name [String, Symbol] the name of the span to start
|
30
30
|
# @param kvs [Hash] list of key values to be reported in the span
|
31
31
|
# @param incoming_context [Hash] specifies the incoming context. At a
|
32
32
|
# minimum, it should specify :trace_id and :span_id from the following:
|
@@ -52,7 +52,7 @@ module Instana
|
|
52
52
|
# @db.select(1)
|
53
53
|
# end
|
54
54
|
#
|
55
|
-
# @param name [String] the name of the span to start
|
55
|
+
# @param name [String, Symbol] the name of the span to start
|
56
56
|
# @param kvs [Hash] list of key values to be reported in this new span
|
57
57
|
#
|
58
58
|
def trace(name, kvs = {}, &block)
|
@@ -72,7 +72,7 @@ module Instana
|
|
72
72
|
# Will start a new trace or continue an on-going one (such as
|
73
73
|
# from incoming remote requests with context headers).
|
74
74
|
#
|
75
|
-
# @param name [String] the name of the span to start
|
75
|
+
# @param name [String, Symbol] the name of the span to start
|
76
76
|
# @param kvs [Hash] list of key values to be reported in the span
|
77
77
|
# @param incoming_context [SpanContext or Hash] specifies the incoming context. At a
|
78
78
|
# minimum, it should specify :trace_id and :span_id from the following:
|
@@ -107,7 +107,7 @@ module Instana
|
|
107
107
|
# Will establish a new span as a child of the current span
|
108
108
|
# in an existing trace
|
109
109
|
#
|
110
|
-
# @param name [String] the name of the span to create
|
110
|
+
# @param name [String, Symbol] the name of the span to create
|
111
111
|
# @param kvs [Hash] list of key values to be reported in the span
|
112
112
|
#
|
113
113
|
def log_entry(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
|
@@ -145,7 +145,7 @@ module Instana
|
|
145
145
|
# @note `name` isn't really required but helps keep sanity that
|
146
146
|
# we're closing out the span that we really want to close out.
|
147
147
|
#
|
148
|
-
# @param name [String] the name of the span to exit (close out)
|
148
|
+
# @param name [String, Symbol] the name of the span to exit (close out)
|
149
149
|
# @param kvs [Hash] list of key values to be reported in the span
|
150
150
|
#
|
151
151
|
def log_exit(name, kvs = {})
|
@@ -263,6 +263,27 @@ module Instana
|
|
263
263
|
new_span
|
264
264
|
end
|
265
265
|
|
266
|
+
# Start a new span which is the child of the current span
|
267
|
+
#
|
268
|
+
# @param operation_name [String] The name of the operation represented by the span
|
269
|
+
# @param child_of [Span] A span to be used as the ChildOf reference
|
270
|
+
# @param start_time [Time] the start time of the span
|
271
|
+
# @param tags [Hash] Starting tags for the span
|
272
|
+
#
|
273
|
+
# @return [Span]
|
274
|
+
#
|
275
|
+
def start_active_span(operation_name, child_of: self.current_span, start_time: ::Instana::Util.now_in_ms, tags: nil)
|
276
|
+
self.current_span = start_span(operation_name, child_of: child_of, start_time: start_time, tags: tags)
|
277
|
+
end
|
278
|
+
|
279
|
+
# Returns the currently active span
|
280
|
+
#
|
281
|
+
# @return [Span]
|
282
|
+
#
|
283
|
+
def active_span
|
284
|
+
self.current_span
|
285
|
+
end
|
286
|
+
|
266
287
|
# Inject a span into the given carrier
|
267
288
|
#
|
268
289
|
# @param span_context [SpanContext]
|
data/lib/instana/tracing/span.rb
CHANGED
@@ -303,6 +303,15 @@ module Instana
|
|
303
303
|
# a String, Numeric, or Boolean it will be encoded with to_s
|
304
304
|
#
|
305
305
|
def set_tag(key, value)
|
306
|
+
if ![Symbol, String].include?(key.class)
|
307
|
+
key = key.to_s
|
308
|
+
end
|
309
|
+
|
310
|
+
# If <value> is not a Symbol, String, Array, Hash or Numeric - convert to string
|
311
|
+
if ![Symbol, String, Array, TrueClass, FalseClass, Hash].include?(value.class) && !value.is_a?(Numeric)
|
312
|
+
value = value.to_s
|
313
|
+
end
|
314
|
+
|
306
315
|
if custom?
|
307
316
|
@data[:data][:sdk][:custom] ||= {}
|
308
317
|
@data[:data][:sdk][:custom][:tags] ||= {}
|
data/lib/instana/version.rb
CHANGED
data/test/apps/cuba.rb
CHANGED
data/test/apps/roda.rb
CHANGED
data/test/apps/sinatra.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
if defined?(::Cuba)
|
3
2
|
require 'test_helper'
|
4
3
|
require File.expand_path(File.dirname(__FILE__) + '/../apps/cuba')
|
@@ -40,5 +39,19 @@ if defined?(::Cuba)
|
|
40
39
|
assert first_span[:data][:http].key?(:host)
|
41
40
|
assert_equal "example.org", first_span[:data][:http][:host]
|
42
41
|
end
|
42
|
+
|
43
|
+
def test_path_template
|
44
|
+
clear_all!
|
45
|
+
|
46
|
+
r = get '/greet/instana'
|
47
|
+
assert last_response.ok?
|
48
|
+
|
49
|
+
spans = ::Instana.processor.queued_spans
|
50
|
+
assert_equal 1, spans.count
|
51
|
+
|
52
|
+
first_span = spans.first
|
53
|
+
assert_equal :rack, first_span[:n]
|
54
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
@@ -5,16 +5,22 @@ require "instana/rack"
|
|
5
5
|
|
6
6
|
class RackTest < Minitest::Test
|
7
7
|
include Rack::Test::Methods
|
8
|
+
|
9
|
+
class PathTemplateApp
|
10
|
+
def call(env)
|
11
|
+
env['INSTANA_HTTP_PATH_TEMPLATE'] = 'sample_template'
|
12
|
+
[200, {}, ['Ok']]
|
13
|
+
end
|
14
|
+
end
|
8
15
|
|
9
16
|
def app
|
10
|
-
@app = Rack::Builder.new
|
17
|
+
@app = Rack::Builder.new do
|
11
18
|
use Rack::CommonLogger
|
12
19
|
use Rack::ShowExceptions
|
13
20
|
use Instana::Rack
|
14
|
-
map
|
15
|
-
|
16
|
-
|
17
|
-
}
|
21
|
+
map("/mrlobster") { run Rack::Lobster.new }
|
22
|
+
map("/path_tpl") { run PathTemplateApp.new }
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
def test_basic_get
|
@@ -29,23 +35,33 @@ class RackTest < Minitest::Test
|
|
29
35
|
# Span validation
|
30
36
|
assert_equal 1, spans.count
|
31
37
|
|
32
|
-
|
33
|
-
assert_equal :rack,
|
34
|
-
|
35
|
-
assert
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
assert
|
41
|
-
assert
|
42
|
-
assert
|
43
|
-
|
38
|
+
rack_span = spans.first
|
39
|
+
assert_equal :rack, rack_span[:n]
|
40
|
+
|
41
|
+
assert last_response.headers.key?("X-Instana-T")
|
42
|
+
assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
|
43
|
+
assert last_response.headers.key?("X-Instana-S")
|
44
|
+
assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
|
45
|
+
assert last_response.headers.key?("X-Instana-L")
|
46
|
+
assert last_response.headers["X-Instana-L"] == '1'
|
47
|
+
assert last_response.headers.key?("Server-Timing")
|
48
|
+
assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
|
49
|
+
|
50
|
+
assert rack_span.key?(:data)
|
51
|
+
assert rack_span[:data].key?(:http)
|
52
|
+
assert_equal "GET", rack_span[:data][:http][:method]
|
53
|
+
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
54
|
+
assert_equal 200, rack_span[:data][:http][:status]
|
55
|
+
assert_equal 'example.org', rack_span[:data][:http][:host]
|
56
|
+
assert rack_span.key?(:f)
|
57
|
+
assert rack_span[:f].key?(:e)
|
58
|
+
assert rack_span[:f].key?(:h)
|
59
|
+
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
44
60
|
|
45
61
|
# Backtrace fingerprint validation
|
46
|
-
assert
|
47
|
-
assert_equal 2,
|
48
|
-
refute_nil
|
62
|
+
assert rack_span.key?(:stack)
|
63
|
+
assert_equal 2, rack_span[:stack].count
|
64
|
+
refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
|
49
65
|
|
50
66
|
# Restore to default
|
51
67
|
::Instana.config[:collect_backtraces] = false
|
@@ -63,8 +79,8 @@ class RackTest < Minitest::Test
|
|
63
79
|
# Span validation
|
64
80
|
assert_equal 1, spans.count
|
65
81
|
|
66
|
-
|
67
|
-
assert_equal 'WalterBishop',
|
82
|
+
rack_span = spans.first
|
83
|
+
assert_equal 'WalterBishop', rack_span[:data][:service]
|
68
84
|
|
69
85
|
ENV.delete('INSTANA_SERVICE_NAME')
|
70
86
|
end
|
@@ -78,17 +94,27 @@ class RackTest < Minitest::Test
|
|
78
94
|
|
79
95
|
# Span validation
|
80
96
|
assert_equal 1, spans.count
|
81
|
-
|
82
|
-
assert_equal :rack,
|
83
|
-
|
84
|
-
assert
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert
|
89
|
-
assert
|
90
|
-
assert
|
91
|
-
|
97
|
+
rack_span = spans.first
|
98
|
+
assert_equal :rack, rack_span[:n]
|
99
|
+
|
100
|
+
assert last_response.headers.key?("X-Instana-T")
|
101
|
+
assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
|
102
|
+
assert last_response.headers.key?("X-Instana-S")
|
103
|
+
assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
|
104
|
+
assert last_response.headers.key?("X-Instana-L")
|
105
|
+
assert last_response.headers["X-Instana-L"] == '1'
|
106
|
+
assert last_response.headers.key?("Server-Timing")
|
107
|
+
assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
|
108
|
+
|
109
|
+
assert rack_span.key?(:data)
|
110
|
+
assert rack_span[:data].key?(:http)
|
111
|
+
assert_equal "POST", rack_span[:data][:http][:method]
|
112
|
+
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
113
|
+
assert_equal 200, rack_span[:data][:http][:status]
|
114
|
+
assert rack_span.key?(:f)
|
115
|
+
assert rack_span[:f].key?(:e)
|
116
|
+
assert rack_span[:f].key?(:h)
|
117
|
+
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
92
118
|
end
|
93
119
|
|
94
120
|
def test_basic_put
|
@@ -100,17 +126,27 @@ class RackTest < Minitest::Test
|
|
100
126
|
|
101
127
|
# Span validation
|
102
128
|
assert_equal 1, spans.count
|
103
|
-
|
104
|
-
assert_equal :rack,
|
105
|
-
|
106
|
-
assert
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
assert
|
111
|
-
assert
|
112
|
-
assert
|
113
|
-
|
129
|
+
rack_span = spans.first
|
130
|
+
assert_equal :rack, rack_span[:n]
|
131
|
+
|
132
|
+
assert last_response.headers.key?("X-Instana-T")
|
133
|
+
assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
|
134
|
+
assert last_response.headers.key?("X-Instana-S")
|
135
|
+
assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
|
136
|
+
assert last_response.headers.key?("X-Instana-L")
|
137
|
+
assert last_response.headers["X-Instana-L"] == '1'
|
138
|
+
assert last_response.headers.key?("Server-Timing")
|
139
|
+
assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
|
140
|
+
|
141
|
+
assert rack_span.key?(:data)
|
142
|
+
assert rack_span[:data].key?(:http)
|
143
|
+
assert_equal "PUT", rack_span[:data][:http][:method]
|
144
|
+
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
145
|
+
assert_equal 200, rack_span[:data][:http][:status]
|
146
|
+
assert rack_span.key?(:f)
|
147
|
+
assert rack_span[:f].key?(:e)
|
148
|
+
assert rack_span[:f].key?(:h)
|
149
|
+
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
114
150
|
end
|
115
151
|
|
116
152
|
def test_context_continuation
|
@@ -125,23 +161,33 @@ class RackTest < Minitest::Test
|
|
125
161
|
|
126
162
|
# Span validation
|
127
163
|
assert_equal 1, spans.count
|
128
|
-
|
129
|
-
assert_equal :rack,
|
130
|
-
|
131
|
-
assert
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
assert
|
136
|
-
assert
|
137
|
-
assert
|
138
|
-
|
164
|
+
rack_span = spans.first
|
165
|
+
assert_equal :rack, rack_span[:n]
|
166
|
+
|
167
|
+
assert last_response.headers.key?("X-Instana-T")
|
168
|
+
assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
|
169
|
+
assert last_response.headers.key?("X-Instana-S")
|
170
|
+
assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
|
171
|
+
assert last_response.headers.key?("X-Instana-L")
|
172
|
+
assert last_response.headers["X-Instana-L"] == '1'
|
173
|
+
assert last_response.headers.key?("Server-Timing")
|
174
|
+
assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
|
175
|
+
|
176
|
+
assert rack_span.key?(:data)
|
177
|
+
assert rack_span[:data].key?(:http)
|
178
|
+
assert_equal "GET", rack_span[:data][:http][:method]
|
179
|
+
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
180
|
+
assert_equal 200, rack_span[:data][:http][:status]
|
181
|
+
assert rack_span.key?(:f)
|
182
|
+
assert rack_span[:f].key?(:e)
|
183
|
+
assert rack_span[:f].key?(:h)
|
184
|
+
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
139
185
|
|
140
186
|
# Context validation
|
141
187
|
# The first span should have the passed in trace ID
|
142
188
|
# and specify the passed in span ID as it's parent.
|
143
|
-
assert_equal 1234,
|
144
|
-
assert_equal 4321,
|
189
|
+
assert_equal 1234, rack_span[:t]
|
190
|
+
assert_equal 4321, rack_span[:p]
|
145
191
|
end
|
146
192
|
|
147
193
|
def test_instana_response_headers
|
@@ -181,20 +227,34 @@ class RackTest < Minitest::Test
|
|
181
227
|
|
182
228
|
# Span validation
|
183
229
|
assert_equal 1, spans.count
|
184
|
-
|
230
|
+
rack_span = spans.first
|
185
231
|
|
186
|
-
assert
|
187
|
-
assert
|
188
|
-
assert !
|
189
|
-
assert_equal "ThereYouGo",
|
232
|
+
assert rack_span[:data][:http].key?(:header)
|
233
|
+
assert rack_span[:data][:http][:header].key?(:"X-Capture-This")
|
234
|
+
assert !rack_span[:data][:http][:header].key?(:"X-Capture-That")
|
235
|
+
assert_equal "ThereYouGo", rack_span[:data][:http][:header][:"X-Capture-This"]
|
190
236
|
|
191
237
|
# Backtrace fingerprint validation
|
192
|
-
assert
|
193
|
-
assert_equal 2,
|
194
|
-
refute_nil
|
238
|
+
assert rack_span.key?(:stack)
|
239
|
+
assert_equal 2, rack_span[:stack].count
|
240
|
+
refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
|
195
241
|
|
196
242
|
# Restore to default
|
197
243
|
::Instana.config[:collect_backtraces] = false
|
198
244
|
::Instana.agent.extra_headers = nil
|
199
245
|
end
|
246
|
+
|
247
|
+
def test_capture_http_path_template
|
248
|
+
clear_all!
|
249
|
+
|
250
|
+
get '/path_tpl'
|
251
|
+
assert last_response.ok?
|
252
|
+
|
253
|
+
spans = ::Instana.processor.queued_spans
|
254
|
+
assert_equal 1, spans.length
|
255
|
+
|
256
|
+
rack_span = spans.first
|
257
|
+
assert_equal :rack, rack_span[:n]
|
258
|
+
assert_equal 'sample_template', rack_span[:data][:http][:path_tpl]
|
259
|
+
end
|
200
260
|
end
|
@@ -153,4 +153,16 @@ class ActionControllerTest < Minitest::Test
|
|
153
153
|
assert ac_span.key?(:stack)
|
154
154
|
assert 1, ac_span[:ec]
|
155
155
|
end
|
156
|
+
|
157
|
+
def test_path_template
|
158
|
+
clear_all!
|
159
|
+
|
160
|
+
Net::HTTP.get(URI.parse('http://localhost:3205/test/world'))
|
161
|
+
|
162
|
+
spans = ::Instana.processor.queued_spans
|
163
|
+
rack_span = find_first_span_by_name(spans, :rack)
|
164
|
+
|
165
|
+
assert_equal false, rack_span.key?(:error)
|
166
|
+
assert_equal '/test/world(.:format)', rack_span[:data][:http][:path_tpl]
|
167
|
+
end
|
156
168
|
end
|
@@ -40,5 +40,19 @@ if defined?(::Roda)
|
|
40
40
|
assert first_span[:data][:http].key?(:host)
|
41
41
|
assert_equal "example.org", first_span[:data][:http][:host]
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_path_template
|
45
|
+
clear_all!
|
46
|
+
|
47
|
+
r = get '/greet/instana'
|
48
|
+
assert last_response.ok?
|
49
|
+
|
50
|
+
spans = ::Instana.processor.queued_spans
|
51
|
+
assert_equal 1, spans.count
|
52
|
+
|
53
|
+
first_span = spans.first
|
54
|
+
assert_equal :rack, first_span[:n]
|
55
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
56
|
+
end
|
43
57
|
end
|
44
58
|
end
|