Class: OpenTelemetry::Trace::SpanContext

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/trace/span_context.rb

Overview

A SpanContext contains the state that must propagate to child Spans and across process boundaries. It contains the identifiers (a trace ID and span ID) associated with the Span, a set of TraceFlags, a system-specific tracestate, and a boolean indicating that the SpanContext was extracted from the wire.

Constant Summary collapse

INVALID =

Represents an invalid OpenTelemetry::Trace::SpanContext, with an invalid trace ID and an invalid span ID.

new(trace_id: INVALID_TRACE_ID, span_id: INVALID_SPAN_ID)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace_id: Trace.generate_trace_id, span_id: Trace.generate_span_id, trace_flags: TraceFlags::DEFAULT, tracestate: Tracestate::DEFAULT, remote: false) ⇒ SpanContext

Parameters:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opentelemetry/trace/span_context.rb', line 24

def initialize(
  trace_id: Trace.generate_trace_id,
  span_id: Trace.generate_span_id,
  trace_flags: TraceFlags::DEFAULT,
  tracestate: Tracestate::DEFAULT,
  remote: false
)
  @trace_id = trace_id
  @span_id = span_id
  @trace_flags = trace_flags
  @tracestate = tracestate
  @remote = remote
end

Instance Attribute Details

#span_idString (readonly)

Returns the binary representation of the span ID.

Returns:

  • (String)

    An 8-byte binary string.



60
61
62
# File 'lib/opentelemetry/trace/span_context.rb', line 60

def span_id
  @span_id
end

#trace_flagsObject (readonly)

Returns the value of attribute trace_flags.



14
15
16
# File 'lib/opentelemetry/trace/span_context.rb', line 14

def trace_flags
  @trace_flags
end

#trace_idString (readonly)

Returns the binary representation of the trace ID.

Returns:

  • (String)

    A 16-byte binary string.



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

def trace_id
  @trace_id
end

#tracestateObject (readonly)

Returns the value of attribute tracestate.



14
15
16
# File 'lib/opentelemetry/trace/span_context.rb', line 14

def tracestate
  @tracestate
end

Instance Method Details

#hex_span_idString

Returns the lowercase hex encoded span ID.

Returns:

  • (String)

    A 16-hex-character lowercase string.



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

def hex_span_id
  @span_id.unpack1('H*')
end

#hex_trace_idString

Returns the lowercase hex encoded trace ID.

Returns:

  • (String)

    A 32-hex-character lowercase string.



41
42
43
# File 'lib/opentelemetry/trace/span_context.rb', line 41

def hex_trace_id
  @trace_id.unpack1('H*')
end

#remote?Boolean

Returns true if the OpenTelemetry::Trace::SpanContext was propagated from a remote parent.

Returns:

  • (Boolean)


72
73
74
# File 'lib/opentelemetry/trace/span_context.rb', line 72

def remote?
  @remote
end

#valid?Boolean

Returns true if the OpenTelemetry::Trace::SpanContext has a non-zero trace ID and non-zero span ID.

Returns:

  • (Boolean)


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

def valid?
  @trace_id != INVALID_TRACE_ID && @span_id != INVALID_SPAN_ID
end