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.
-
#wrapped_span_context_extractor ⇒ Object
Returns the value of attribute wrapped_span_context_extractor.
-
#wrapped_span_extractor ⇒ Object
Returns the value of attribute wrapped_span_extractor.
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/test/tracer.rb', line 23 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) default_extractor = Wrapped::DefaultExtractor.new @wrapped_span_extractor = default_extractor @wrapped_span_context_extractor = default_extractor end |
Instance Attribute Details
#extractors ⇒ Object (readonly)
Returns the value of attribute extractors.
15 16 17 |
# File 'lib/test/tracer.rb', line 15 def extractors @extractors end |
#finished_spans ⇒ Object (readonly)
Returns the value of attribute finished_spans.
14 15 16 |
# File 'lib/test/tracer.rb', line 14 def finished_spans @finished_spans end |
#injectors ⇒ Object (readonly)
Returns the value of attribute injectors.
15 16 17 |
# File 'lib/test/tracer.rb', line 15 def injectors @injectors end |
#logger ⇒ Object
Returns the value of attribute logger.
20 21 22 |
# File 'lib/test/tracer.rb', line 20 def logger @logger end |
#spans ⇒ Object (readonly)
Returns the value of attribute spans.
14 15 16 |
# File 'lib/test/tracer.rb', line 14 def spans @spans end |
#wrapped_span_context_extractor ⇒ Object
Returns the value of attribute wrapped_span_context_extractor.
18 19 20 |
# File 'lib/test/tracer.rb', line 18 def wrapped_span_context_extractor @wrapped_span_context_extractor end |
#wrapped_span_extractor ⇒ Object
Returns the value of attribute wrapped_span_extractor.
17 18 19 |
# File 'lib/test/tracer.rb', line 17 def wrapped_span_extractor @wrapped_span_extractor end |
Instance Method Details
#clear ⇒ Object
107 108 109 110 111 |
# File 'lib/test/tracer.rb', line 107 def clear @spans.clear @finished_spans.clear self end |
#extract(format, carrier) ⇒ Object
OT complaiant
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/test/tracer.rb', line 94 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
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/test/tracer.rb', line 79 def inject(span_context, format, carrier) NotNull! format span_context = extract_span_context(span_context) 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
56 57 58 59 60 |
# File 'lib/test/tracer.rb', line 56 def register_codec(format, codec) register_injector(format, codec) register_extractor(format, codec) self end |
#register_extractor(format, extractor) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/test/tracer.rb', line 48 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
40 41 42 43 44 45 46 |
# File 'lib/test/tracer.rb', line 40 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/test/tracer.rb', line 63 def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil) child_of = extract_span(child_of) || extract_span_context(child_of) 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 |