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:
class MyClassTest def setup @tracer_provider = TracerProvider.new @exporter = InMemorySpanExporter.new @tracer_provider.add_span_processor(SimpleSampledSpansProcessor.new(@exporter)) end
def test_finished_spans @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")
end
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.
-
#initialize ⇒ 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 ⇒ Object
Returns a new instance of the OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.
34 35 36 37 38 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 34 def initialize @finished_spans = [] @stopped = false @mutex = Mutex.new end |
Instance Method Details
#export(span_datas, timeout: nil) ⇒ Integer
Called to export sampled SpanDatas.
66 67 68 69 70 71 72 73 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 66 def export(span_datas, timeout: nil) @mutex.synchronize do return FAILURE if @stopped @finished_spans.concat(span_datas.to_a) 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.
44 45 46 47 48 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 44 def finished_spans @mutex.synchronize do @finished_spans.clone.freeze end end |
#reset ⇒ Object
Clears the internal collection of finished Spans.
Does not reset the state of this exporter if already shutdown.
53 54 55 56 57 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 53 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.
81 82 83 84 85 86 87 |
# File 'lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb', line 81 def shutdown(timeout: nil) @mutex.synchronize do @finished_spans.clear @stopped = true end SUCCESS end |