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.
Constant Summary collapse
- HEADER_FORMAT =
Internal regex used to parse fields
%r{([0-9a-fA-F]{32})(?:\/(\d+))?(?:;o=(\d+))?}
- HEADER_NAME =
The outgoing header used for the Google Cloud Trace header specification.
"X-Cloud-Trace".freeze
- RACK_HEADER_NAME =
The rack environment header used the the Google Cloud Trace header specification.
"HTTP_X_CLOUD_TRACE".freeze
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.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 71 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.
51 52 53 |
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 51 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.
61 62 63 |
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 61 def rack_header_name RACK_HEADER_NAME end |
#serialize(trace_context) ⇒ String
Serialize a TraceContextData object.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/opencensus/trace/formatters/cloud_trace.rb', line 89 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 |