Class: OpenTracing::Tracer
- Inherits:
-
Object
- Object
- OpenTracing::Tracer
- Defined in:
- lib/opentracing/tracer.rb
Overview
Tracer is the entry point API between instrumentation code and the tracing implementation.
This implementation both defines the public Tracer API, and provides a default no-op behavior.
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.
-
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier.
-
#scope_manager ⇒ ScopeManager
The current ScopeManager, which may be a no-op but may not be nil.
-
#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, Object
Returns a newly started and activated Scope.
-
#start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false) {|Span| ... } ⇒ Span, Object
Like #start_active_span, but the returned Span has not been registered via the ScopeManager.
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.
18 19 20 21 |
# File 'lib/opentracing/tracer.rb', line 18 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.
116 117 118 119 120 121 122 123 124 |
# File 'lib/opentracing/tracer.rb', line 116 def extract(format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK return SpanContext::NOOP_INSTANCE else warn 'Unknown extract format' nil end end |
#inject(span_context, format, carrier) ⇒ Object
Inject a SpanContext into the given carrier
102 103 104 105 106 107 108 109 |
# File 'lib/opentracing/tracer.rb', line 102 def inject(span_context, format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK return nil else warn 'Unknown inject format' end end |
#scope_manager ⇒ ScopeManager
Returns the current ScopeManager, which may be a no-op but may not be nil.
11 12 13 |
# File 'lib/opentracing/tracer.rb', line 11 def scope_manager ScopeManager::NOOP_INSTANCE 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, Object
Returns 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.
If specified, the `references` parameter must be omitted.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/opentracing/tracer.rb', line 51 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) Scope::NOOP_INSTANCE.tap do |scope| return yield scope if block_given? end end |
#start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false) {|Span| ... } ⇒ Span, Object
Like #start_active_span, but the returned Span has not been registered via the ScopeManager.
If specified, the `references` parameter must be omitted.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/opentracing/tracer.rb', line 86 def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil, ignore_active_scope: false) Span::NOOP_INSTANCE.tap do |span| return yield span if block_given? end end |