Method: OpenCensus::Trace::SpanContext.create_root

Defined in:
lib/opencensus/trace/span_context.rb

.create_root(trace_context: nil, same_process_as_parent: nil) ⇒ SpanContext

Create a new root SpanContext object, given either a Trace-Context header value by itself, or an entire Rack environment. If a valid Trace-Context header can be obtained from either source, it is used to generate the SpanContext. Otherwise, a new root context with a unique ‘trace_id` and a root `span_id` of “” is used.

Parameters:

  • trace_context (TraceContextData) (defaults to: nil)

    The request’s incoming trace context (optional)

  • same_process_as_parent (boolean, nil) (defaults to: nil)

    Set to ‘true` if the parent span is local, `false` if it is remote, or `nil` if there is no parent span or this information is not available.

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/opencensus/trace/span_context.rb', line 60

def create_root trace_context: nil, same_process_as_parent: nil
  if trace_context
    trace_data = TraceData.new \
      trace_context.trace_id, trace_context.trace_options, {}
    new trace_data, nil, trace_context.span_id,
        same_process_as_parent
  else
    trace_id = rand 1..MAX_TRACE_ID
    trace_id = trace_id.to_s(16).rjust(32, "0")
    trace_data = TraceData.new trace_id, 0, {}
    new trace_data, nil, "", nil
  end
end