Class: OpenTracingTestTracer
- Inherits:
-
Object
- Object
- OpenTracingTestTracer
- Defined in:
- lib/signalfx_test_tracer.rb,
lib/signalfx_test_tracer/span.rb,
lib/signalfx_test_tracer/scope.rb,
lib/signalfx_test_tracer/trace_id.rb,
lib/signalfx_test_tracer/span_context.rb,
lib/signalfx_test_tracer/scope_manager.rb,
lib/signalfx_test_tracer/scope_manager/scope_stack.rb,
lib/signalfx_test_tracer/scope_manager/scope_identifier.rb
Defined Under Namespace
Modules: TraceId Classes: Scope, ScopeManager, Span, SpanContext
Instance Attribute Summary collapse
-
#scope_manager ⇒ ScopeManager
readonly
The current ScopeManager, which may be a no-op but may not be nil.
-
#spans ⇒ Object
readonly
NOTE: This is not OT compliant.
Class Method Summary collapse
Instance Method Summary collapse
-
#active_span ⇒ Span?
The active span.
-
#extract(format, carrier) ⇒ SpanContext
Extract a SpanContext in the given format from the given carrier.
-
#initialize(logger:) ⇒ OpenTracingTestTracer
constructor
A new instance of OpenTracingTestTracer.
-
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier.
-
#start_active_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false, finish_on_close: true) {|Scope| ... } ⇒ Scope
Creates a newly started and activated Scope.
-
#start_span(operation_name, child_of: nil, start_time: Time.now, tags: nil, references: nil, ignore_active_scope: false) ⇒ Span
Starts a new span.
Constructor Details
#initialize(logger:) ⇒ OpenTracingTestTracer
Returns a new instance of OpenTracingTestTracer.
17 18 19 20 21 22 |
# File 'lib/signalfx_test_tracer.rb', line 17 def initialize(logger:) @logger = logger @scope_manager = ScopeManager.new @spans = [] @finished_spans = [] end |
Instance Attribute Details
#scope_manager ⇒ ScopeManager (readonly)
Returns the current ScopeManager, which may be a no-op but may not be nil.
29 30 31 |
# File 'lib/signalfx_test_tracer.rb', line 29 def scope_manager @scope_manager end |
#spans ⇒ Object (readonly)
NOTE: This is not OT compliant. This is meant only for testing.
25 26 27 |
# File 'lib/signalfx_test_tracer.rb', line 25 def spans @spans end |
Class Method Details
.build(logger: Logger.new(STDOUT)) ⇒ Object
13 14 15 |
# File 'lib/signalfx_test_tracer.rb', line 13 def self.build(logger: Logger.new(STDOUT)) new(logger: logger) end |
Instance Method Details
#active_span ⇒ Span?
Returns the active span. This is a shorthand for
scope_manager.active.span, and nil will be returned if
Scope#active is nil.
34 35 36 37 |
# File 'lib/signalfx_test_tracer.rb', line 34 def active_span scope = scope_manager.active scope&.span end |
#extract(format, carrier) ⇒ SpanContext
Extract a SpanContext in the given format from the given carrier.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/signalfx_test_tracer.rb', line 159 def extract(format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP trace_id = carrier['test-traceid'] parent_id = carrier['test-parentspanid'] span_id = carrier['test-spanid'] create_span_context(trace_id, span_id, parent_id) when OpenTracing::FORMAT_RACK trace_id = carrier['HTTP_TEST_TRACEID'] parent_id = carrier['HTTP_TEST_PARENTSPANID'] span_id = carrier['HTTP_TEST_SPANID'] create_span_context(trace_id, span_id, parent_id) else @logger.error "#{format} format is not supported yet" nil end end |
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/signalfx_test_tracer.rb', line 143 def inject(span_context, format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_RACK carrier['test-traceid'] = span_context.trace_id carrier['test-parentspanid'] = span_context.parent_id carrier['test-spanid'] = span_context.span_id else @logger.error "#{format} format is not supported yet" end end |
#start_active_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false, finish_on_close: true) {|Scope| ... } ⇒ Scope
Creates a newly started and activated Scope
If the Tracer's ScopeManager#active is not nil, no explicit references
are provided, and ignore_active_scope is false, then an inferred
References#CHILD_OF reference is created to the ScopeManager#active's
SpanContext when start_active is invoked.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/signalfx_test_tracer.rb', line 109 def start_active_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false, finish_on_close: true, **) span = start_span( operation_name, child_of: child_of, references: references, start_time: start_time, tags: , ignore_active_scope: ignore_active_scope, ) scope = @scope_manager.activate(span, finish_on_close: finish_on_close) if block_given? begin yield scope ensure scope.close end end scope end |
#start_span(operation_name, child_of: nil, start_time: Time.now, tags: nil, references: nil, ignore_active_scope: false) ⇒ Span
Starts a new span
This is similar to #start_active_span, but the returned Span will not be registered via the ScopeManager.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/signalfx_test_tracer.rb', line 59 def start_span(operation_name, child_of: nil, start_time: Time.now, tags: nil, references: nil, ignore_active_scope: false, **) context = prepare_span_context( child_of: child_of, references: references, ignore_active_scope: ignore_active_scope ) span = Span.new( context: context, operation_name: operation_name, start_time: start_time, references: references, tags: , tracer: self, ) @spans << span span end |