Class: Test::Tracer
- Inherits:
-
OpenTracing::Tracer
- Object
- OpenTracing::Tracer
- Test::Tracer
- Includes:
- TypeCheck
- Defined in:
- lib/test/tracer.rb
Instance Attribute Summary collapse
-
#extractors ⇒ Object
readonly
Returns the value of attribute extractors.
-
#finished_spans ⇒ Object
readonly
Returns the value of attribute finished_spans.
-
#injectors ⇒ Object
readonly
Returns the value of attribute injectors.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#spans ⇒ Object
readonly
Returns the value of attribute spans.
Instance Method Summary collapse
- #clear ⇒ Object
-
#extract(format, carrier) ⇒ Object
OT complaiant.
-
#initialize(logger: nil) ⇒ Tracer
constructor
A new instance of Tracer.
-
#inject(span_context, format, carrier) ⇒ Object
OT complaiant.
- #register_codec(format, codec) ⇒ Object
- #register_extractor(format, extractor) ⇒ Object
- #register_injector(format, injector) ⇒ Object
-
#start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil) ⇒ Object
OT complaiant.
Methods included from TypeCheck
#Argument!, #NotNull!, #Type!, #Type?
Constructor Details
#initialize(logger: nil) ⇒ Tracer
Returns a new instance of Tracer.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/test/tracer.rb', line 18 def initialize(logger: nil) @logger = logger @spans = [] @finished_spans = [] @injectors = {} @extractors = {} register_codec(OpenTracing::FORMAT_TEXT_MAP, Propagation::TextMapCodec.new) register_codec(OpenTracing::FORMAT_RACK, Propagation::RackCodec.new) end |
Instance Attribute Details
#extractors ⇒ Object (readonly)
Returns the value of attribute extractors.
14 15 16 |
# File 'lib/test/tracer.rb', line 14 def extractors @extractors end |
#finished_spans ⇒ Object (readonly)
Returns the value of attribute finished_spans.
13 14 15 |
# File 'lib/test/tracer.rb', line 13 def finished_spans @finished_spans end |
#injectors ⇒ Object (readonly)
Returns the value of attribute injectors.
14 15 16 |
# File 'lib/test/tracer.rb', line 14 def injectors @injectors end |
#logger ⇒ Object
Returns the value of attribute logger.
16 17 18 |
# File 'lib/test/tracer.rb', line 16 def logger @logger end |
#spans ⇒ Object (readonly)
Returns the value of attribute spans.
13 14 15 |
# File 'lib/test/tracer.rb', line 13 def spans @spans end |
Instance Method Details
#clear ⇒ Object
98 99 100 101 102 |
# File 'lib/test/tracer.rb', line 98 def clear @spans.clear @finished_spans.clear self end |
#extract(format, carrier) ⇒ Object
OT complaiant
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/test/tracer.rb', line 85 def extract(format, carrier) NotNull! format NotNull! carrier extractor = @extractors[format] if extractor extractor.extract(carrier) else log(Logger::WARN, "No extractor found for '#{format}' format") nil end end |
#inject(span_context, format, carrier) ⇒ Object
OT complaiant
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/test/tracer.rb', line 70 def inject(span_context, format, carrier) Type! span_context, ::Test::SpanContext, NilClass NotNull! format return unless carrier injector = @injectors[format] if injector injector.inject(span_context, carrier) else log(Logger::WARN, "No injector found for '#{format}' format") end end |
#register_codec(format, codec) ⇒ Object
47 48 49 50 51 |
# File 'lib/test/tracer.rb', line 47 def register_codec(format, codec) register_injector(format, codec) register_extractor(format, codec) self end |
#register_extractor(format, extractor) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/test/tracer.rb', line 39 def register_extractor(format, extractor) NotNull! format Argument! extractor.respond_to?(:extract), "Extractor must respond to 'extract' method" @extractors[format] = extractor self end |
#register_injector(format, injector) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/test/tracer.rb', line 31 def register_injector(format, injector) NotNull! format Argument! injector.respond_to?(:inject), "Injector must respond to 'inject' method" @injectors[format] = injector self end |
#start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil) ⇒ Object
OT complaiant
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/test/tracer.rb', line 54 def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil) Type! child_of, ::Test::Span, ::Test::SpanContext, NilClass parent_context = child_of && child_of.respond_to?(:context) ? child_of.context : child_of new_context = parent_context ? ::Test::SpanContext.child_of(parent_context) : ::Test::SpanContext.root new_span = Span.new(tracer: self, operation_name: operation_name, context: new_context, start_time: start_time, tags: ) @spans << new_span new_span end |