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/util/http_to_status.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, Util 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.
-
#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.
70 71 72 |
# File 'lib/opentelemetry/trace.rb', line 70 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
60 61 62 63 |
# File 'lib/opentelemetry/trace.rb', line 60 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.
49 50 51 52 53 54 |
# File 'lib/opentelemetry/trace.rb', line 49 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.
38 39 40 41 42 43 |
# File 'lib/opentelemetry/trace.rb', line 38 def generate_trace_id loop do id = RANDOM.bytes(16) return id unless id == INVALID_TRACE_ID end 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.
81 82 83 |
# File 'lib/opentelemetry/trace.rb', line 81 def with_span(span) Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c } end |