Class: OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter
- Defined in:
- lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb
Overview
A SpanExporter implementation that can be used to test OpenTelemetry integration.
Example usage in a test suite:
class MyClassTest def setup @tracer_provider = TracerProvider.new # The default is recording: true
, which is appropriate in non-test environments. @exporter = InMemorySpanExporter.new(recording: false) @tracer_provider.add_span_processor(SimpleSampledSpansProcessor.new(@exporter)) end
def test_finished_spans @exporter.recording = true @tracer_provider.tracer.in_span(“span”) {}
spans = @exporter.finished_spans
spans.wont_be_nil
spans.size.must_equal(1)
spans[0].name.must_equal("span")
@exporter.recording = false
end
Instance Attribute Summary collapse
-
#recording ⇒ Boolean
Controls whether or not the exporter will record spans, or discard them.
Instance Method Summary collapse
-
#export(span_datas, timeout: nil) ⇒ Integer
Called to export sampled SpanDatas.
-
#finished_spans ⇒ Array<SpanData>
Returns a frozen array of the finished SpanDatas, represented by ioio.opentelemetryio.opentelemetry.protoio.opentelemetry.proto.traceio.opentelemetry.proto.trace.v1io.opentelemetry.proto.trace.v1.Span.
-
#force_flush(timeout: nil) ⇒ Integer
Called when TracerProvider#force_flush is called, if this exporter is registered to a TracerProvider object.
-
#initialize(recording: true) ⇒ Object
constructor
Returns a new instance of the InMemorySpanExporter.
-
#reset ⇒ Object
Clears the internal collection of finished Spans.
-
#shutdown(timeout: nil) ⇒ Integer
Called when TracerProvider#shutdown is called, if this exporter is registered to a TracerProvider object.
Constructor Details
#initialize(recording: true) ⇒ Object
Returns a new instance of the OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.
42 43 44 45 46 47 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 42 def initialize(recording: true) @finished_spans = [] @stopped = false @recording = recording @mutex = Mutex.new end |
Instance Attribute Details
#recording ⇒ Boolean
Controls whether or not the exporter will record spans, or discard them.
37 38 39 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 37 def recording @recording end |
Instance Method Details
#export(span_datas, timeout: nil) ⇒ Integer
Called to export sampled SpanDatas.
75 76 77 78 79 80 81 82 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 75 def export(span_datas, timeout: nil) @mutex.synchronize do return FAILURE if @stopped @finished_spans.concat(span_datas.to_a) if @recording end SUCCESS end |
#finished_spans ⇒ Array<SpanData>
Returns a frozen array of the finished SpanDatas, represented by OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.ioio.opentelemetryio.opentelemetry.protoio.opentelemetry.proto.traceio.opentelemetry.proto.trace.v1io.opentelemetry.proto.trace.v1.Span.
53 54 55 56 57 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 53 def finished_spans @mutex.synchronize do @finished_spans.clone.freeze end end |
#force_flush(timeout: nil) ⇒ Integer
Called when TracerProvider#force_flush is called, if this exporter is registered to a TracerProvider object.
90 91 92 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 90 def force_flush(timeout: nil) SUCCESS end |
#reset ⇒ Object
Clears the internal collection of finished Spans.
Does not reset the state of this exporter if already shutdown.
62 63 64 65 66 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 62 def reset @mutex.synchronize do @finished_spans.clear end end |
#shutdown(timeout: nil) ⇒ Integer
Called when TracerProvider#shutdown is called, if this exporter is registered to a TracerProvider object.
100 101 102 103 104 105 106 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 100 def shutdown(timeout: nil) @mutex.synchronize do @finished_spans.clear @stopped = true end SUCCESS end |