Class: BaselineRedRpm::Tracing::Tracer
- Inherits:
-
Object
- Object
- BaselineRedRpm::Tracing::Tracer
- Defined in:
- lib/baseline_red_rpm/tracing/tracer.rb
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
-
#thread_span_stack ⇒ Object
readonly
Returns the value of attribute thread_span_stack.
Class Method Summary collapse
Instance Method Summary collapse
- #extract(format, carrier) ⇒ Object
-
#initialize(collector, sender) ⇒ Tracer
constructor
A new instance of Tracer.
- #inject(span_context, format, carrier) ⇒ Object
- #start_span(operation_name, opts = {}) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(collector, sender) ⇒ Tracer
Returns a new instance of Tracer.
18 19 20 21 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 18 def initialize(collector, sender) @collector = collector @sender = sender end |
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
6 7 8 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 6 def collector @collector end |
#thread_span_stack ⇒ Object (readonly)
Returns the value of attribute thread_span_stack.
6 7 8 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 6 def thread_span_stack @thread_span_stack end |
Class Method Details
.build(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 8 def self.build(opts = {}) opts[:collector] ||= nil opts[:sender] ||= nil opts[:service_name] ||= nil opts[:sender].start new(opts[:collector], opts[:sender]) end |
Instance Method Details
#extract(format, carrier) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 63 def extract(format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP trace_id = carrier['trace-id'] parent_id = carrier['parent-id'] span_id = carrier['span-id'] sampled = carrier['sampled'] == '1' create_span_context(trace_id, span_id, parent_id, sampled) when OpenTracing::FORMAT_RACK trace_id = carrier['HTTP_X_BaselineRed_TRACEID'] parent_id = carrier['HTTP_X_BaselineRed_PARENTSPANID'] span_id = carrier['HTTP_X_BaselineRed_SPANID'] sampled = carrier['HTTP_X_BaselineRed_SAMPLED'] == '1' create_span_context(trace_id, span_id, parent_id, sampled) else STDERR.puts "BaselineRedRpm::Tracer with format #{format} is not supported yet" nil end end |
#inject(span_context, format, carrier) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 46 def inject(span_context, format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP carrier['trace-id'] = span_context.trace_id carrier['parent-id'] = span_context.parent_id carrier['span-id'] = span_context.span_id carrier['sampled'] = span_context.sampled? ? '1' : '0' when OpenTracing::FORMAT_RACK carrier['X-BaselineRed-TraceId'] = span_context.trace_id carrier['X-BaselineRed-ParentSpanId'] = span_context.parent_id carrier['X-BaselineRed-SpanId'] = span_context.span_id carrier['X-BaselineRed-Sampled'] = span_context.sampled? ? '1' : '0' else STDERR.puts "BaselineRedRpm::Tracer with format #{format} is not supported yet" end end |
#start_span(operation_name, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 27 def start_span(operation_name, opts = {}, *) child_of = opts[:child_of] || nil opts[:start_time] ||= BaselineRedRpm.now opts[: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 = Span.new(context, operation_name, @collector, { start_time: opts[:start_time], tags: opts[:tags] }) end |
#stop ⇒ Object
23 24 25 |
# File 'lib/baseline_red_rpm/tracing/tracer.rb', line 23 def stop @sender.stop end |