Class: OpenCensus::Trace::Formatters::TraceContext

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

Overview

This formatter serializes and deserializes span context according to the TraceContext specification. See documentation.

Instance Method Summary collapse

Instance Method Details

#deserialize(header) ⇒ TraceContextData?

Deserialize a trace context header into a TraceContext object.

Parameters:

  • header (String)

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/opencensus/trace/formatters/trace_context.rb', line 80

def deserialize header
  match = VERSION_PATTERN.match(header)
  if match
    version = match[1].to_i(16)
    version_format = match[2]
    case version
    when 0
      parse_trace_context_header_version_0 version_format
    else
      nil
    end
  else
    nil
  end
end

#header_nameString

Returns the name of the header used for context propagation.

Returns:

  • (String)


60
61
62
# File 'lib/opencensus/trace/formatters/trace_context.rb', line 60

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)


70
71
72
# File 'lib/opencensus/trace/formatters/trace_context.rb', line 70

def rack_header_name
  RACK_HEADER_NAME
end

#serialize(trace_context) ⇒ String

Serialize a TraceContextData object.

Parameters:

Returns:

  • (String)


102
103
104
105
106
107
108
109
110
# File 'lib/opencensus/trace/formatters/trace_context.rb', line 102

def serialize trace_context
  format(
    "%02<version>d-%<trace_id>s-%<span_id>s-%02<trace_options>d",
    version: 0, # version 0,
    trace_id: trace_context.trace_id,
    span_id: trace_context.span_id,
    trace_options: trace_context.trace_options
  )
end