Module: OpenTelemetry::Trace

Extended by:
Trace
Included in:
Trace
Defined in:
lib/opentelemetry/trace.rb,
lib/opentelemetry/trace/link.rb,
lib/opentelemetry/trace/span.rb,
lib/opentelemetry/trace/status.rb,
lib/opentelemetry/trace/tracer.rb,
lib/opentelemetry/trace/span_kind.rb,
lib/opentelemetry/trace/tracestate.rb,
lib/opentelemetry/trace/propagation.rb,
lib/opentelemetry/trace/trace_flags.rb,
lib/opentelemetry/trace/span_context.rb,
lib/opentelemetry/trace/tracer_provider.rb,
lib/opentelemetry/trace/propagation/trace_context.rb,
lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb,
lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.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: Propagation, SpanKind Classes: Link, Span, SpanContext, Status, TraceFlags, Tracer, TracerProvider, Tracestate

Constant Summary collapse

INVALID_TRACE_ID =

An invalid trace identifier, a 16-byte string with all zero bytes.

("\0" * 16).b
INVALID_SPAN_ID =

An invalid span identifier, an 8-byte string with all zero bytes.

("\0" * 8).b

Instance Method Summary collapse

Instance Method Details

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

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



58
59
60
# File 'lib/opentelemetry/trace.rb', line 58

def context_with_span(span, parent_context: 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



48
49
50
51
# File 'lib/opentelemetry/trace.rb', line 48

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

#generate_span_idString

Generates a valid span identifier, an 8-byte string with at least one non-zero byte.



38
39
40
41
42
# File 'lib/opentelemetry/trace.rb', line 38

def generate_span_id
  id = Random.bytes(8)
  id = Random.bytes(8) while id == INVALID_SPAN_ID
  id
end

#generate_trace_idString

Generates a valid trace identifier, a 16-byte string with at least one non-zero byte.



28
29
30
31
32
# File 'lib/opentelemetry/trace.rb', line 28

def generate_trace_id
  id = Random.bytes(16)
  id = Random.bytes(16) while id == INVALID_TRACE_ID
  id
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.



79
80
81
# File 'lib/opentelemetry/trace.rb', line 79

def non_recording_span(span_context)
  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.

Yields:

  • (span, context)

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



69
70
71
# File 'lib/opentelemetry/trace.rb', line 69

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