Class: Logasm::Tracer
- Inherits:
-
Object
- Object
- Logasm::Tracer
- Defined in:
- lib/logasm/tracer.rb,
lib/logasm/tracer/span.rb,
lib/logasm/tracer/version.rb,
lib/logasm/tracer/trace_id.rb,
lib/logasm/tracer/span_context.rb
Overview
Defined Under Namespace
Modules: TraceId Classes: Span, SpanContext
Constant Summary collapse
- FORMAT_TEXT_MAP =
1- FORMAT_BINARY =
2- FORMAT_RACK =
3- VERSION =
"0.2.1"
Instance Method Summary collapse
-
#extract(format, carrier) ⇒ SpanContext
Extract a SpanContext in the given format from the given carrier.
-
#initialize(logger) ⇒ Tracer
constructor
A new instance of Tracer.
-
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier.
-
#start_span(operation_name, child_of: nil, start_time: Time.now, tags: {}) ⇒ Span
Starts a new span.
Constructor Details
#initialize(logger) ⇒ Tracer
Returns a new instance of Tracer.
16 17 18 |
# File 'lib/logasm/tracer.rb', line 16 def initialize(logger) @logger = logger end |
Instance Method Details
#extract(format, carrier) ⇒ SpanContext
Extract a SpanContext in the given format from the given carrier.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/logasm/tracer.rb', line 67 def extract(format, carrier) case format when FORMAT_TEXT_MAP trace_id = carrier['trace-id'] parent_id = carrier['parent-id'] span_id = carrier['span-id'] if trace_id && span_id SpanContext.new(trace_id: trace_id, parent_id: parent_id, span_id: span_id) else nil end when FORMAT_RACK trace_id = carrier['X-Trace-Id'] parent_id = carrier['X-Trace-Parent-Id'] span_id = carrier['X-Trace-Span-Id'] if trace_id && span_id SpanContext.new(trace_id: trace_id, parent_id: parent_id, span_id: span_id) else nil end else @logger.error "Logasm::Tracer with format #{format} is not supported yet" nil end end |
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/logasm/tracer.rb', line 47 def inject(span_context, format, carrier) case format when FORMAT_TEXT_MAP carrier['trace-id'] = span_context.trace_id carrier['parent-id'] = span_context.parent_id carrier['span-id'] = span_context.span_id when FORMAT_RACK carrier['X-Trace-Id'] = span_context.trace_id carrier['X-Trace-Parent-Id'] = span_context.parent_id carrier['X-Trace-Span-Id'] = span_context.span_id else @logger.error "Logasm::Tracer with format #{format} is not supported yet" end end |
#start_span(operation_name, child_of: nil, start_time: Time.now, tags: {}) ⇒ Span
Starts a new span.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/logasm/tracer.rb', line 30 def start_span(operation_name, child_of: nil, start_time: Time.now, tags: {}, **) context = if child_of parent_context = child_of.respond_to?(:context) ? child_of.context : child_of SpanContext.create_from_parent_context(parent_context) else SpanContext.create_parent_context end Span.new(context, operation_name, @logger, start_time: start_time, tags: ) end |