instana 1.9.7 → 1.10.0.slimfast

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/instana/agent.rb +19 -19
  3. data/lib/instana/agent/helpers.rb +2 -2
  4. data/lib/instana/agent/tasks.rb +2 -2
  5. data/lib/instana/collectors/gc.rb +1 -1
  6. data/lib/instana/collectors/memory.rb +1 -1
  7. data/lib/instana/collectors/thread.rb +1 -1
  8. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +1 -1
  9. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +1 -1
  10. data/lib/instana/helpers.rb +2 -2
  11. data/lib/instana/instrumentation.rb +1 -1
  12. data/lib/instana/instrumentation/excon.rb +8 -5
  13. data/lib/instana/instrumentation/rack.rb +2 -2
  14. data/lib/instana/instrumentation/resque.rb +3 -3
  15. data/lib/instana/tracer.rb +92 -117
  16. data/lib/instana/tracing/processor.rb +18 -133
  17. data/lib/instana/tracing/span.rb +40 -35
  18. data/lib/instana/tracing/span_context.rb +3 -1
  19. data/lib/instana/util.rb +5 -5
  20. data/lib/instana/version.rb +1 -1
  21. data/lib/opentracing.rb +1 -1
  22. data/test/frameworks/rack_test.rb +6 -11
  23. data/test/frameworks/rails/actioncontroller_test.rb +32 -62
  24. data/test/frameworks/rails/actionview5_test.rb +91 -132
  25. data/test/frameworks/rails/activerecord5_test.rb +14 -17
  26. data/test/instrumentation/dalli_test.rb +51 -72
  27. data/test/instrumentation/excon_test.rb +70 -94
  28. data/test/instrumentation/grpc_test.rb +164 -126
  29. data/test/instrumentation/net-http_test.rb +48 -57
  30. data/test/instrumentation/redis_test.rb +4 -6
  31. data/test/instrumentation/resque_test.rb +41 -41
  32. data/test/instrumentation/rest-client_test.rb +25 -31
  33. data/test/instrumentation/sidekiq-client_test.rb +12 -20
  34. data/test/instrumentation/sidekiq-worker_test.rb +48 -63
  35. data/test/jobs/resque_error_job.rb +7 -1
  36. data/test/jobs/resque_fast_job.rb +7 -1
  37. data/test/servers/sidekiq/worker.rb +1 -3
  38. data/test/test_helper.rb +58 -0
  39. data/test/tracing/custom_test.rb +11 -19
  40. data/test/tracing/opentracing_test.rb +48 -156
  41. data/test/tracing/trace_test.rb +67 -67
  42. data/test/tracing/tracer_async_test.rb +75 -175
  43. data/test/tracing/tracer_test.rb +75 -75
  44. metadata +4 -5
  45. data/lib/instana/tracing/trace.rb +0 -316
@@ -30,15 +30,11 @@ class TracerTest < Minitest::Test
30
30
  sleep 0.1
31
31
  end
32
32
 
33
- traces = ::Instana.processor.queued_traces
34
- assert_equal 1, traces.length
35
- t = traces.first
36
- assert_equal 1, t.spans.size
37
- assert t.valid?
33
+ spans = ::Instana.processor.queued_spans
34
+ assert_equal 1, spans.length
38
35
 
39
- first_span = t.spans.first
36
+ first_span = spans.first
40
37
  assert_equal :rack, first_span[:n]
41
- assert_equal :ruby, first_span[:ta]
42
38
  assert first_span[:ts].is_a?(Integer)
43
39
  assert first_span[:d].is_a?(Integer)
44
40
  assert first_span[:d].between?(100, 130)
@@ -63,15 +59,11 @@ class TracerTest < Minitest::Test
63
59
 
64
60
  assert exception_raised
65
61
 
66
- traces = ::Instana.processor.queued_traces
67
- assert_equal 1, traces.length
68
- t = traces.first
69
- assert_equal 1, t.spans.size
70
- assert t.valid?
62
+ spans = ::Instana.processor.queued_spans
63
+ assert_equal 1, spans.length
71
64
 
72
- first_span = t.spans.first
65
+ first_span = spans.first
73
66
  assert_equal :rack, first_span[:n]
74
- assert_equal :ruby, first_span[:ta]
75
67
  assert first_span[:ts].is_a?(Integer)
76
68
  assert first_span[:ts] > 0
77
69
  assert first_span[:d].is_a?(Integer)
@@ -82,7 +74,8 @@ class TracerTest < Minitest::Test
82
74
  assert first_span[:f].key?(:e)
83
75
  assert first_span[:f].key?(:h)
84
76
  assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
85
- assert t.has_error?
77
+ assert_equal first_span[:error], true
78
+ assert_equal first_span[:ec], 1
86
79
  end
87
80
 
88
81
  def test_complex_trace_block
@@ -94,11 +87,22 @@ class TracerTest < Minitest::Test
94
87
  end
95
88
  end
96
89
 
97
- traces = ::Instana.processor.queued_traces
98
- assert_equal 1, traces.length
99
- t = traces.first
100
- assert_equal 2, t.spans.size
101
- assert t.valid?
90
+ spans = ::Instana.processor.queued_spans
91
+ assert_equal 2, spans.length
92
+
93
+ rack_span = find_first_span_by_name(spans, :rack)
94
+ sdk_span = find_first_span_by_name(spans, :sub_block)
95
+
96
+ assert_equal rack_span[:n], :rack
97
+ assert_equal rack_span[:p], nil
98
+ assert_equal rack_span[:t], rack_span[:s]
99
+ assert_equal rack_span[:data][:one], 1
100
+
101
+ assert_equal sdk_span[:n], :sdk
102
+ assert_equal sdk_span[:data][:sdk][:name], :sub_block
103
+ assert_equal sdk_span[:data][:sdk][:type], :intermediate
104
+ assert_equal sdk_span[:k], 3
105
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:sub_two], 2
102
106
  end
103
107
 
104
108
  def test_basic_low_level_tracing
@@ -113,11 +117,8 @@ class TracerTest < Minitest::Test
113
117
  ::Instana.tracer.log_end(:rack, {:close_one => 1})
114
118
  assert_equal false, ::Instana.tracer.tracing?
115
119
 
116
- traces = ::Instana.processor.queued_traces
117
- assert_equal 1, traces.length
118
- t = traces.first
119
- assert_equal 1, t.spans.size
120
- assert t.valid?
120
+ spans = ::Instana.processor.queued_spans
121
+ assert_equal 1, spans.length
121
122
  end
122
123
 
123
124
  def test_complex_low_level_tracing
@@ -142,22 +143,30 @@ class TracerTest < Minitest::Test
142
143
  ::Instana.tracer.log_end(:rack, {:close_one => 1})
143
144
  assert_equal false, ::Instana.tracer.tracing?
144
145
 
145
- traces = ::Instana.processor.queued_traces
146
- assert_equal 1, traces.length
146
+ spans = ::Instana.processor.queued_spans
147
+ assert_equal 2, spans.length
147
148
 
148
- t = traces.first
149
- assert_equal 2, t.spans.size
150
- assert t.valid?
149
+ rack_span = find_first_span_by_name(spans, :rack)
150
+ sdk_span = find_first_span_by_name(spans, :sub_task)
151
+
152
+ assert_equal :rack, rack_span[:n]
153
+ assert rack_span.key?(:data)
154
+ assert_equal rack_span[:data][:one], 1
155
+ assert_equal rack_span[:data][:info_logged], 1
156
+ assert_equal rack_span[:data][:close_one], 1
157
+
158
+ assert rack_span.key?(:f)
159
+ assert rack_span[:f].key?(:e)
160
+ assert rack_span[:f].key?(:h)
161
+ assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
162
+
163
+ assert_equal sdk_span[:n], :sdk
164
+ assert_equal sdk_span[:data][:sdk][:name], :sub_task
165
+ assert_equal sdk_span[:data][:sdk][:type], :intermediate
166
+ assert_equal sdk_span[:k], 3
167
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:sub_task_info], 1
168
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:sub_task_exit_info], 1
151
169
 
152
- first_span = t.spans.first
153
- assert_equal :rack, first_span[:n]
154
- assert_equal :ruby, first_span[:ta]
155
- assert first_span.key?(:data)
156
- assert_equal 1, first_span[:data][:one]
157
- assert first_span.key?(:f)
158
- assert first_span[:f].key?(:e)
159
- assert first_span[:f].key?(:h)
160
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
161
170
  end
162
171
 
163
172
  def test_block_tracing_error_capture
@@ -173,13 +182,19 @@ class TracerTest < Minitest::Test
173
182
 
174
183
  assert exception_raised
175
184
 
176
- traces = ::Instana.processor.queued_traces
177
- assert_equal 1, traces.length
185
+ spans = ::Instana.processor.queued_spans
186
+ assert_equal 1, spans.length
187
+
188
+ sdk_span = spans[0]
178
189
 
179
- t = traces.first
180
- assert_equal 1, t.spans.size
181
- assert t.valid?
182
- assert t.has_error?
190
+ assert_equal sdk_span[:n], :sdk
191
+ assert_equal sdk_span[:data][:sdk][:name], :test_trace
192
+ assert_equal sdk_span[:data][:sdk][:type], :intermediate
193
+ assert_equal sdk_span[:k], 3
194
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:one], 1
195
+ assert_equal sdk_span[:error], true
196
+ assert_equal sdk_span[:ec], 1
197
+ assert_equal sdk_span.key?(:stack), true
183
198
  end
184
199
 
185
200
  def test_low_level_error_logging
@@ -189,35 +204,20 @@ class TracerTest < Minitest::Test
189
204
  ::Instana.tracer.log_error(Exception.new("Low level tracing api error"))
190
205
  ::Instana.tracer.log_end(:test_trace, {:close_one => 1})
191
206
 
192
- traces = ::Instana.processor.queued_traces
193
- assert_equal 1, traces.length
194
-
195
- t = traces.first
196
- assert_equal 1, t.spans.size
197
- assert t.valid?
198
- assert t.has_error?
199
- end
200
-
201
- def test_instana_headers_in_response
202
- clear_all!
203
- ::Instana.tracer.start_or_continue_trace(:rack, {:one => 1}) do
204
- sleep 0.5
205
- end
206
-
207
- traces = ::Instana.processor.queued_traces
208
- assert_equal 1, traces.length
209
- t = traces.first
210
- assert_equal 1, t.spans.size
211
- assert t.valid?
212
-
213
- first_span = t.spans.first
214
- assert_equal :rack, first_span[:n]
215
- assert_equal :ruby, first_span[:ta]
216
- assert first_span.key?(:data)
217
- assert_equal 1, first_span[:data][:one]
218
- assert first_span.key?(:f)
219
- assert first_span[:f].key?(:e)
220
- assert first_span[:f].key?(:h)
221
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
207
+ spans = ::Instana.processor.queued_spans
208
+ assert_equal 1, spans.length
209
+
210
+ sdk_span = spans[0]
211
+
212
+ assert_equal sdk_span[:n], :sdk
213
+ assert_equal sdk_span[:data][:sdk][:name], :test_trace
214
+ assert_equal sdk_span[:data][:sdk][:type], :intermediate
215
+ assert_equal sdk_span[:k], 3
216
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:one], 1
217
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:info_logged], 1
218
+ assert_equal sdk_span[:data][:sdk][:custom][:tags][:close_one], 1
219
+ assert_equal sdk_span[:error], true
220
+ assert_equal sdk_span[:ec], 1
221
+ assert_equal sdk_span.key?(:stack), false
222
222
  end
223
223
  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.9.7
4
+ version: 1.10.0.slimfast
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: 2019-08-14 00:00:00.000000000 Z
11
+ date: 2019-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -245,7 +245,6 @@ files:
245
245
  - lib/instana/tracing/processor.rb
246
246
  - lib/instana/tracing/span.rb
247
247
  - lib/instana/tracing/span_context.rb
248
- - lib/instana/tracing/trace.rb
249
248
  - lib/instana/util.rb
250
249
  - lib/instana/version.rb
251
250
  - lib/opentracing.rb
@@ -311,9 +310,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
311
310
  version: '2.1'
312
311
  required_rubygems_version: !ruby/object:Gem::Requirement
313
312
  requirements:
314
- - - ">="
313
+ - - ">"
315
314
  - !ruby/object:Gem::Version
316
- version: '0'
315
+ version: 1.3.1
317
316
  requirements: []
318
317
  rubygems_version: 3.0.3
319
318
  signing_key:
@@ -1,316 +0,0 @@
1
- module Instana
2
- class Trace
3
- # @return [Integer] the ID for this trace
4
- attr_reader :id
5
-
6
- # The collection of `Span` for this trace
7
- # @return [Set] the collection of spans for this trace
8
- attr_reader :spans
9
-
10
- # The currently active span
11
- attr_reader :current_span
12
-
13
- # Initializes a new instance of Trace
14
- #
15
- # @param name [String] the name of the span to start
16
- # @param kvs [Hash] list of key values to be reported in the span
17
- # @param incoming_context [Hash] specifies the incoming context. At a
18
- # minimum, it should specify :trace_id and :span_id from the following:
19
- # :trace_id the trace ID (must be an unsigned hex-string)
20
- # :span_id the ID of the parent span (must be an unsigned hex-string)
21
- # :level specifies data collection level (optional)
22
- #
23
- def initialize(name, kvs = nil, incoming_context = {}, start_time = ::Instana::Util.now_in_ms)
24
- # The collection of spans that make
25
- # up this trace.
26
- @spans = Set.new
27
-
28
- # Generate a random 64bit ID for this trace
29
- @id = ::Instana::Util.generate_id
30
-
31
- # Indicates the time when this trace was started. Used to timeout
32
- # traces that have asynchronous spans that never close out.
33
- @started_at = Time.now
34
-
35
- # Indicates if this trace has any asynchronous spans within it
36
- @has_async = false
37
-
38
- # This is a new trace so open the first span with the proper
39
- # root span IDs.
40
- @current_span = Span.new(name, @id, start_time: start_time)
41
- @current_span.set_tags(kvs) if kvs
42
-
43
- # Handle potential incoming context
44
- if !incoming_context || incoming_context.empty?
45
- # No incoming context. Set trace ID the same
46
- # as this first span.
47
- @current_span[:s] = @id
48
- else
49
- @id = incoming_context[:trace_id]
50
- @current_span[:t] = incoming_context[:trace_id]
51
- @current_span[:p] = incoming_context[:span_id]
52
- end
53
-
54
- @spans.add(@current_span)
55
- end
56
-
57
- # Start a new span as a child of @current_span
58
- #
59
- # @param name [String] the name of the span to start
60
- # @param kvs [Hash] list of key values to be reported in the span
61
- #
62
- def new_span(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
63
- return unless @current_span
64
-
65
- if child_of && child_of.is_a?(::Instana::Span)
66
- new_span = Span.new(name, @id, parent_id: child_of.id, start_time: start_time)
67
- new_span.parent = child_of
68
- new_span.baggage = child_of.baggage.dup
69
- else
70
- new_span = Span.new(name, @id, parent_id: @current_span.id, start_time: start_time)
71
- new_span.parent = @current_span
72
- new_span.baggage = @current_span.baggage.dup
73
- end
74
- new_span.set_tags(kvs) if kvs
75
-
76
- @spans.add(new_span)
77
- @current_span = new_span
78
- end
79
-
80
- # Add KVs to the current span
81
- #
82
- # @param span [Span] the span to add kvs to or otherwise the current span
83
- # @param kvs [Hash] list of key values to be reported in the span
84
- #
85
- def add_info(kvs, span = nil)
86
- return unless @current_span
87
- span ||= @current_span
88
-
89
- # Pass on to the OT span interface which will properly
90
- # apply KVs based on span type
91
- span.set_tags(kvs)
92
- end
93
-
94
- # Log an error into the current span
95
- #
96
- # @param e [Exception] Add exception to the current span
97
- #
98
- def add_error(e, span = nil)
99
- # Return if we've already logged this exception and it
100
- # is just propogating up the spans.
101
- return if e && e.instance_variable_get(:@instana_logged) || @current_span.nil?
102
- span ||= @current_span
103
- span.add_error(e)
104
- end
105
-
106
- # Close out the current span and set the parent as
107
- # the current span
108
- #
109
- # @param kvs [Hash] list of key values to be reported in the span
110
- #
111
- def end_span(kvs = {}, end_time = ::Instana::Util.now_in_ms)
112
- return unless @current_span
113
-
114
- @current_span.close(end_time)
115
- add_info(kvs) if kvs && !kvs.empty?
116
- @current_span = @current_span.parent unless @current_span.is_root?
117
- end
118
- alias finish end_span
119
-
120
- ###########################################################################
121
- # Asynchronous Methods
122
- ###########################################################################
123
-
124
- # Start a new asynchronous span
125
- #
126
- # The major differentiator between this method and simple new_span is that
127
- # this method doesn't affect @current_trace and instead returns an
128
- # ID pair that can be used later to close out the created async span.
129
- #
130
- # @param name [String] the name of the span to start
131
- # @param kvs [Hash] list of key values to be reported in the span
132
- #
133
- def new_async_span(name, kvs = {})
134
- new_span = Span.new(name, @id, parent_id: @current_span.id)
135
- new_span.set_tags(kvs) unless kvs.empty?
136
- new_span.parent = @current_span
137
- new_span[:deferred] = @has_async = true
138
-
139
- # Add the new span to the span collection
140
- @spans.add(new_span)
141
- new_span
142
- end
143
-
144
- # Log info into an asynchronous span
145
- #
146
- # @param kvs [Hash] list of key values to be reported in the span
147
- # @param span [Span] the span of this Async op (previously returned
148
- # from `log_async_entry`)
149
- #
150
- def add_async_info(kvs, span)
151
- span.set_tags(kvs)
152
- end
153
-
154
- # Log an error into an asynchronous span
155
- #
156
- # @param e [Exception] Add exception to the current span
157
- # @param span [Span] the span of this Async op (previously returned
158
- # from `log_async_entry`)
159
- #
160
- def add_async_error(e, span)
161
- span.add_error(e)
162
- end
163
-
164
- # End an asynchronous span
165
- #
166
- # @param name [Symbol] the name of the span
167
- # @param kvs [Hash] list of key values to be reported in the span
168
- # @param span [Span] the span of this Async op (previously returned
169
- # from `log_async_entry`)
170
- #
171
- def end_async_span(kvs = {}, span)
172
- span.set_tags(kvs) unless kvs.empty?
173
- span.close
174
- end
175
-
176
- ###########################################################################
177
- # Validator and Helper Methods
178
- ###########################################################################
179
-
180
- # Indicates whether all seems ok with this trace in it's current state.
181
- # Should be only called on finished traces.
182
- #
183
- # @return [Boolean] true or false on whether this trace is valid
184
- #
185
- def valid?
186
- @spans.each do |span|
187
- unless span.key?(:d)
188
- return false
189
- end
190
- end
191
- true
192
- end
193
-
194
- # Indicates if every span of this trace has completed. Useful when
195
- # asynchronous spans potentially could run longer than the parent trace.
196
- #
197
- def complete?
198
- @spans.each do |span|
199
- if !span.duration
200
- return false
201
- end
202
- end
203
- true
204
- end
205
-
206
- # Indicates whether this trace has any asynchronous spans.
207
- #
208
- def has_async?
209
- @has_async
210
- end
211
-
212
- # Searches the set of spans and indicates if there
213
- # is an error logged in one of them.
214
- #
215
- # @return [Boolean] true or false indicating the presence
216
- # of an error
217
- #
218
- def has_error?
219
- @spans.each do |s|
220
- if s.key?(:error)
221
- if s[:error] == true
222
- return true
223
- end
224
- end
225
- end
226
- false
227
- end
228
-
229
- # Get the ID of the current span for this trace.
230
- # Used often to place in HTTP response headers.
231
- #
232
- # @return [Integer] a random 64bit integer
233
- #
234
- def current_span_id
235
- @current_span.id
236
- end
237
-
238
- # Get the name of the current span. Supports both registered spans
239
- # and custom sdk spans.
240
- #
241
- def current_span_name
242
- @current_span.name
243
- end
244
-
245
- # Check if the current span has the name value of <name>
246
- #
247
- # @param name [Symbol] The name to be checked against.
248
- #
249
- # @return [Boolean]
250
- #
251
- def current_span_name?(name)
252
- @current_span.name == name
253
- end
254
-
255
- # For traces that have asynchronous spans, this method indicates
256
- # whether we have hit the timeout on waiting for those async
257
- # spans to close out.
258
- #
259
- # @return [Boolean]
260
- #
261
- def discard?
262
- # If this trace has async spans that have not closed
263
- # out in 5 minutes, then it's discarded.
264
- if has_async? && (Time.now.to_i - @started_at.to_i) > 601
265
- return true
266
- end
267
- false
268
- end
269
-
270
- private
271
-
272
- # Configure @current_span to be a custom span per the
273
- # SDK generic span type.
274
- #
275
- # @param span [Span] the span to configure or nil
276
- # @param name [String] name of the span
277
- # @param kvs [Hash] list of key values to be reported in the span
278
- #
279
- def configure_custom_span(span, name, kvs = {})
280
- span ||= @current_span
281
- span.configure_custom(name, kvs)
282
- end
283
-
284
- # Adds the passed in backtrace to the specified span. Backtrace can be one
285
- # generated from Kernel.caller or one attached to an exception
286
- #
287
- # @param bt [Array] the backtrace
288
- # @param limit [Integer] Limit the backtrace to the top <limit> frames
289
- # @param span [Span] the span to add the backtrace to or if unspecified
290
- # the current span
291
- #
292
- def add_backtrace_to_span(bt, limit = nil, span)
293
- frame_count = 0
294
- span[:stack] = []
295
-
296
- bt.each do |i|
297
- # If the stack has the full instana gem version in it's path
298
- # then don't include that frame. Also don't exclude the Rack module.
299
- if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
300
- (i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
301
-
302
- break if limit && frame_count >= limit
303
-
304
- x = i.split(':')
305
-
306
- span[:stack] << {
307
- :f => x[0],
308
- :n => x[1],
309
- :m => x[2]
310
- }
311
- frame_count = frame_count + 1 if limit
312
- end
313
- end
314
- end
315
- end
316
- end