instana 2.9.0 → 2.11.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.
@@ -68,7 +68,7 @@ module Instana
68
68
  end
69
69
 
70
70
  def to_hash
71
- { :trace_id => @trace_id, :span_id => @span_id }
71
+ { :trace_id => @trace_id, :span_id => @span_id, :level => @level }
72
72
  end
73
73
 
74
74
  def valid?
data/lib/instana/util.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- module Util
5
+ module Util # rubocop:disable Metrics/ModuleLength
6
6
  class << self
7
7
  ID_RANGE = -2**63..2**63-1
8
8
  # Retrieves and returns the source code for any ruby
@@ -171,6 +171,44 @@ module Instana
171
171
  given
172
172
  end
173
173
 
174
+ # Parse W3C +traceparent+ / +tracestate+ values using the OpenTelemetry
175
+ # trace-context propagator.
176
+ #
177
+ # When the tracestate carries an Instana entry (+in=<trace>;<span>+) it
178
+ # takes precedence over the ids in the traceparent.
179
+ #
180
+ # @param traceparent [String] the traceparent header value
181
+ # @param tracestate [String, nil] the tracestate header value
182
+ #
183
+ # @return [Hash, nil] +nil+ when the traceparent is missing or invalid,
184
+ # otherwise a hash with:
185
+ # - +:trace_id+, +:span_id+, +:level+ for continuing the trace
186
+ # - +:external_trace_id+, +:external_trace_flags+, +:external_state+
187
+ # for re-emitting the W3C context downstream
188
+ #
189
+ def parse_w3c_trace_context(traceparent, tracestate = nil)
190
+ return nil unless traceparent.is_a?(String)
191
+
192
+ carrier = { 'traceparent' => traceparent, 'tracestate' => tracestate.is_a?(String) ? tracestate : nil }
193
+ extracted = OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator.extract(
194
+ carrier, context: OpenTelemetry::Context.empty
195
+ )
196
+ span_context = OpenTelemetry::Trace.current_span(extracted).context
197
+ return nil unless span_context.valid?
198
+
199
+ sampled = span_context.trace_flags.sampled?
200
+ instana_state = span_context.tracestate.value('in')&.match(/\A(?<trace>[0-9a-f]+);(?<span>[0-9a-f]+)\z/)
201
+
202
+ {
203
+ trace_id: header_to_id(instana_state ? instana_state[:trace] : span_context.hex_trace_id[16..]),
204
+ span_id: header_to_id(instana_state ? instana_state[:span] : span_context.hex_span_id),
205
+ level: sampled ? 1 : 0,
206
+ external_trace_id: span_context.hex_trace_id,
207
+ external_trace_flags: sampled ? '01' : '00',
208
+ external_state: tracestate
209
+ }
210
+ end
211
+
174
212
  def timeout_timestamp
175
213
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
176
214
  end
@@ -229,6 +267,35 @@ module Instana
229
267
 
230
268
  klass.name.sub('Net::HTTP', '').gsub(/([A-Z])/, ' \1').strip
231
269
  end
270
+
271
+ # Build the W3C trace-context message attributes for an AWS message
272
+ # (SQS or SNS). Returns a hash suitable for merging into
273
+ # +params[:message_attributes]+.
274
+ #
275
+ # @param span_context [Instana::SpanContext]
276
+ # @return [Hash]
277
+ #
278
+ def aws_message_attributes_w3c(span_context)
279
+ {
280
+ 'traceparent' => { data_type: 'String', string_value: span_context.trace_parent_header },
281
+ 'tracestate' => { data_type: 'String', string_value: span_context.trace_state_header }
282
+ }
283
+ end
284
+
285
+ # Build the Instana proprietary message attributes for an AWS message
286
+ # (SQS or SNS). Returns a hash suitable for merging into
287
+ # +params[:message_attributes]+.
288
+ #
289
+ # @param span_context [Instana::SpanContext]
290
+ # @return [Hash]
291
+ #
292
+ def aws_message_attributes_instana(span_context)
293
+ {
294
+ 'X_INSTANA_T' => { data_type: 'String', string_value: span_context.trace_id },
295
+ 'X_INSTANA_S' => { data_type: 'String', string_value: span_context.span_id },
296
+ 'X_INSTANA_L' => { data_type: 'String', string_value: span_context.level.to_s }
297
+ }
298
+ end
232
299
  end
233
300
  end
234
301
  end
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "2.9.0"
5
+ VERSION = "2.11.0"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instana
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
@@ -416,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
416
416
  - !ruby/object:Gem::Version
417
417
  version: '0'
418
418
  requirements: []
419
- rubygems_version: 4.0.21
419
+ rubygems_version: 4.0.23
420
420
  specification_version: 4
421
421
  summary: Ruby Distributed Tracing & Metrics Sensor for Instana
422
422
  test_files: []