Class: OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor
- Defined in:
- lib/opentelemetry/sdk/trace/export/simple_span_processor.rb
Overview
An implementation of the duck type SpanProcessor that converts the Span to ioio.opentelemetryio.opentelemetry.protoio.opentelemetry.proto.traceio.opentelemetry.proto.trace.v1io.opentelemetry.proto.trace.v1.Span and passes it to the configured exporter.
Typically, the SimpleSpanProcessor will be most suitable for use in testing; it should be used with caution in production. It may be appropriate for production use in scenarios where creating multiple threads is not desirable as well as scenarios where different custom attributes should be added to individual spans based on code scopes.
Only spans that are recorded are converted, Trace::Span#is_recording? must return true.
Instance Method Summary collapse
-
#force_flush(timeout: nil) ⇒ Integer
Export all ended spans to the configured
Exporter
that have not yet been exported. -
#initialize(span_exporter) ⇒ SimpleSpanProcessor
constructor
Returns a new SimpleSpanProcessor that converts spans to proto and forwards them to the given span_exporter.
-
#on_finish(span) ⇒ Object
Called when a Span is ended, if the Span#recording? returns true.
-
#on_start(span, parent_context) ⇒ Object
Called when a Span is started, if the Span#recording? returns true.
-
#shutdown(timeout: nil) ⇒ Integer
Called when TracerProvider#shutdown is called.
Constructor Details
#initialize(span_exporter) ⇒ SimpleSpanProcessor
Returns a new OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor that converts spans to proto and forwards them to the given span_exporter.
31 32 33 |
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 31 def initialize(span_exporter) @span_exporter = span_exporter end |
Instance Method Details
#force_flush(timeout: nil) ⇒ Integer
Export all ended spans to the configured Exporter
that have not yet been exported.
This method should only be called in cases where it is absolutely necessary, such as when using some FaaS providers that may suspend the process after an invocation, but before the Processor
exports the completed spans.
74 75 76 |
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 74 def force_flush(timeout: nil) SUCCESS end |
#on_finish(span) ⇒ Object
Called when a Span is ended, if the Span#recording? returns true.
This method is called synchronously on the execution thread, should not throw or block the execution thread.
55 56 57 58 59 60 61 |
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 55 def on_finish(span) return unless span.context.trace_flags.sampled? @span_exporter&.export([span.to_span_data]) rescue => e # rubocop:disable Style/RescueStandardError OpenTelemetry.logger.error("unexpected error in span.on_finish - #{e}") end |
#on_start(span, parent_context) ⇒ Object
Called when a Span is started, if the Span#recording? returns true.
This method is called synchronously on the execution thread, should not throw or block the execution thread.
44 45 46 |
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 44 def on_start(span, parent_context) # Do nothing. end |
#shutdown(timeout: nil) ⇒ Integer
Called when TracerProvider#shutdown is called.
83 84 85 |
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 83 def shutdown(timeout: nil) @span_exporter&.shutdown(timeout: timeout) || SUCCESS end |