Class: OpenCensus::Trace::Formatters::CloudTrace

Inherits:
Object
  • Object
show all
Defined in:
lib/opencensus/trace/formatters/cloud_trace.rb

Overview

This formatter serializes and deserializes span context according to the Google X-Cloud-Trace header specification.

Instance Method Summary collapse

Instance Method Details

#deserialize(header) ⇒ TraceContextData?

Deserialize a trace context header into a TraceContext object.

Parameters:

  • header (String)

Returns:



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 72

def deserialize header
  match = HEADER_FORMAT.match(header)
  if match
    trace_id = match[1].downcase
    span_id = format("%016x", match[2].to_i)
    trace_options = match[3].to_i
    TraceContextData.new trace_id, span_id, trace_options
  else
    nil
  end
end

#header_nameString

Returns the name of the header used for context propagation.

Returns:

  • (String)


52
53
54
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 52

def header_name
  HEADER_NAME
end

#rack_header_nameString

Returns the name of the rack_environment header to use when parsing context from an incoming request.

Returns:

  • (String)


62
63
64
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 62

def rack_header_name
  RACK_HEADER_NAME
end

#serialize(trace_context) ⇒ String

Serialize a TraceContextData object.

Parameters:

Returns:

  • (String)


90
91
92
93
94
95
96
97
98
99
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 90

def serialize trace_context
  trace_context.trace_id.dup.tap do |ret|
    if trace_context.span_id
      ret << "/" << trace_context.span_id.to_i(16).to_s
    end
    if trace_context.trace_options
      ret << ";o=" << trace_context.trace_options.to_s
    end
  end
end