Span Context

SpanContext encapsulates the current context within the request's trace.

class opencensus.trace.span_context.SpanContext(trace_id=None, span_id=None, trace_options=None, tracestate=None, from_header=False)[source]

Bases: object

SpanContext includes 3 fields: traceId, spanId, and an trace_options flag which indicates whether or not the request is being traced. It contains the current context to be propagated to the child spans.

Parameters
  • trace_id (str) -- (Optional) Trace_id is a 32 digits uuid for the trace. If not given, will generate one automatically.

  • span_id (str) -- (Optional) Identifier for the span, unique within a trace. If not given, will generate one automatically.

  • trace_options -- (Optional) TraceOptions indicates 8 trace options.

  • from_header (bool) -- (Optional) Indicates whether the trace context is generated from request header.

opencensus.trace.span_context.generate_span_id()[source]

Return the random generated span ID for a span. Must be a 16 character hexadecimal encoded string

Return type

str

Returns

16 digit randomly generated hex trace id.

opencensus.trace.span_context.generate_trace_id()[source]

Generate a random 32 char hex trace_id.

Return type

str

Returns

32 digit randomly generated hex trace id.