Module: Instana::Trace

Includes:
OpenTelemetry::Trace
Defined in:
lib/instana/trace.rb,
lib/instana/trace/export.rb,
lib/instana/samplers/result.rb,
lib/instana/samplers/samplers.rb,
lib/instana/trace/span_limits.rb,
lib/instana/trace/tracer_provider.rb

Overview

The Trace API allows recording a set of events, triggered as a result of a single logical operation, consolidated across various components of an application.

Defined Under Namespace

Modules: Export, Samplers Classes: SpanLimits, TracerProvider

Constant Summary collapse

ID_RANGE =
-2**63..2**63 - 1

Class Method Summary collapse

Class Method Details

.context_with_span(span, parent_context: OpenTelemetry::Context.current) ⇒ Object

Returns a context containing the span, derived from the optional parent context, or the current context if one was not provided.

Parameters:

  • context (optional Context)

    The context to use as the parent for the returned context



44
45
46
# File 'lib/instana/trace.rb', line 44

def context_with_span(span, parent_context:  OpenTelemetry::Context.current)
  parent_context.set_value(CURRENT_SPAN_KEY, span)
end

.current_span(context = nil) ⇒ Object

Returns the current span from the current or provided context

Parameters:

  • context (optional Context) (defaults to: nil)

    The context to lookup the current Span from. Defaults to Context.current



34
35
36
37
# File 'lib/instana/trace.rb', line 34

def current_span(context = nil)
  context ||= OpenTelemetry::Context.current
  context.value(CURRENT_SPAN_KEY) || nil
end

.generate_span_id(size = 1) ⇒ Object

Generates a valid span identifier



24
25
26
27
28
# File 'lib/instana/trace.rb', line 24

def generate_span_id(size = 1)
  Array.new(size) { rand(ID_RANGE) }
       .pack('q>*')
       .unpack1('H*')
end

.generate_trace_id(size = 1) ⇒ Object

Generates a valid trace identifier



16
17
18
19
20
# File 'lib/instana/trace.rb', line 16

def generate_trace_id(size = 1)
  Array.new(size) { rand(ID_RANGE) }
       .pack('q>*')
       .unpack1('H*')
end

.non_recording_span(span_context) ⇒ Span

Wraps a SpanContext with an object implementing the Span interface. This is done in order to expose a SpanContext as a Span in operations such as in-process Span propagation.

Parameters:

  • span_context (SpanContext)

    SpanContext to be wrapped

Returns:



65
66
67
# File 'lib/instana/trace.rb', line 65

def non_recording_span(span_context)
  OpenTelemetry::Trace::Span.new(span_context: span_context)
end

.with_span(span) {|span, context| ... } ⇒ Object

Activates/deactivates the Span within the current Context, which makes the “current span” available implicitly.

On exit, the Span that was active before calling this method will be reactivated.

Parameters:

  • span (Span)

    the span to activate

Yields:

  • (span, context)

    yields span and a context containing the span to the block.



55
56
57
# File 'lib/instana/trace.rb', line 55

def with_span(span)
  OpenTelemetry::Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
end