Class: Jaeger::Client::Tracer
- Inherits:
-
Object
- Object
- Jaeger::Client::Tracer
- Defined in:
- lib/jaeger/client/tracer.rb
Instance Attribute Summary collapse
-
#scope_manager ⇒ ScopeManager
readonly
The current ScopeManager, which may be a no-op but may not be nil.
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(reporter:, sampler:, injectors:, extractors:) ⇒ Tracer
constructor
A new instance of Tracer.
-
#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: {}, ignore_active_scope: false, finish_on_close: true) {|Scope| ... } ⇒ Scope
Creates a newly started and activated Scope.
-
#start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: {}, ignore_active_scope: false) ⇒ Span
Starts a new span.
Constructor Details
#initialize(reporter:, sampler:, injectors:, extractors:) ⇒ Tracer
Returns a new instance of Tracer.
6 7 8 9 10 11 12 |
# File 'lib/jaeger/client/tracer.rb', line 6 def initialize(reporter:, sampler:, injectors:, extractors:) @reporter = reporter @sampler = sampler @injectors = injectors @extractors = extractors @scope_manager = ScopeManager.new end |
Instance Attribute Details
#scope_manager ⇒ ScopeManager (readonly)
Returns the current ScopeManager, which may be a no-op but may not be nil.
16 17 18 |
# File 'lib/jaeger/client/tracer.rb', line 16 def scope_manager @scope_manager 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.
21 22 23 24 |
# File 'lib/jaeger/client/tracer.rb', line 21 def active_span scope = scope_manager.active scope.span if scope end |
#extract(format, carrier) ⇒ SpanContext
Extract a SpanContext in the given format from the given carrier.
142 143 144 145 146 147 148 149 |
# File 'lib/jaeger/client/tracer.rb', line 142 def extract(format, carrier) @extractors .fetch(format) .lazy .map { |extractor| extractor.extract(carrier) } .reject(&:nil?) .first end |
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier
131 132 133 134 135 |
# File 'lib/jaeger/client/tracer.rb', line 131 def inject(span_context, format, carrier) @injectors.fetch(format).each do |injector| injector.inject(span_context, carrier) end end |
#start_active_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: {}, 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/jaeger/client/tracer.rb', line 97 def start_active_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: {}, 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, references: nil, start_time: Time.now, tags: {}, 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jaeger/client/tracer.rb', line 46 def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: {}, ignore_active_scope: false, **) context = prepare_span_context( child_of: child_of, references: references, ignore_active_scope: ignore_active_scope ) Span.new( context, operation_name, @reporter, start_time: start_time, references: references, tags: .merge( :'sampler.type' => @sampler.type, :'sampler.param' => @sampler.param ) ) end |