Class: OpenCensus::Trace::Formatters::CloudTrace
- Inherits:
-
Object
- Object
- OpenCensus::Trace::Formatters::CloudTrace
- 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
-
#deserialize(header) ⇒ TraceContextData?
Deserialize a trace context header into a TraceContext object.
-
#header_name ⇒ String
Returns the name of the header used for context propagation.
-
#rack_header_name ⇒ String
Returns the name of the rack_environment header to use when parsing context from an incoming request.
-
#serialize(trace_context) ⇒ String
Serialize a TraceContextData object.
Instance Method Details
#deserialize(header) ⇒ TraceContextData?
Deserialize a trace context header into a TraceContext object.
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) = match[3].to_i TraceContextData.new trace_id, span_id, else nil end end |
#header_name ⇒ String
Returns the name of the header used for context propagation.
52 53 54 |
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 52 def header_name HEADER_NAME end |
#rack_header_name ⇒ String
Returns the name of the rack_environment header to use when parsing context from an incoming request.
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.
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. ret << ";o=" << trace_context..to_s end end end |