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
-
#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.
-
#current_span(context = nil) ⇒ Object
Returns the current span from the current or provided context.
-
#generate_span_id ⇒ String
Generates a valid span identifier, an 8-byte string with at least one non-zero byte.
-
#generate_trace_id ⇒ String
Generates a valid trace identifier, a 16-byte string with at least one non-zero byte.
-
#non_recording_span(span_context) ⇒ Span
Wraps a SpanContext with an object implementing the Span interface.
-
#with_span(span) {|span, context| ... } ⇒ Object
Activates/deactivates the Span within the current Context, which makes the “current span” available implicitly.
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.
60 61 62 |
# File 'lib/opentelemetry/trace.rb', line 60 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
50 51 52 53 |
# File 'lib/opentelemetry/trace.rb', line 50 def current_span(context = nil) context ||= Context.current context.value(CURRENT_SPAN_KEY) || Span::INVALID end |
#generate_span_id ⇒ String
Generates a valid span identifier, an 8-byte string with at least one non-zero byte.
39 40 41 42 43 44 |
# File 'lib/opentelemetry/trace.rb', line 39 def generate_span_id loop do id = Random.bytes(8) return id unless id == INVALID_SPAN_ID end end |
#generate_trace_id ⇒ String
Generates a valid trace identifier, a 16-byte string with at least one non-zero byte.
28 29 30 31 32 33 |
# File 'lib/opentelemetry/trace.rb', line 28 def generate_trace_id loop do id = Random.bytes(16) return id unless id == INVALID_TRACE_ID end 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.
81 82 83 |
# File 'lib/opentelemetry/trace.rb', line 81 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.
71 72 73 |
# File 'lib/opentelemetry/trace.rb', line 71 def with_span(span) Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c } end |