Class: OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor

Inherits:
Object
  • Object
show all
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.

Only spans that are recorded are converted, Trace::Span#is_recording? must return true.

Instance Method Summary collapse

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.

Parameters:

  • span_exporter

    the (duck type) SpanExporter to where the recorded Spans are pushed.

Raises:

  • ArgumentError if the span_exporter is nil.



25
26
27
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 25

def initialize(span_exporter)
  @span_exporter = span_exporter
end

Instance Method Details

#force_flushInteger

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.

Returns:

  • (Integer)

    SUCCESS if no error occurred, FAILURE if a non-specific failure occurred, TIMEOUT if a timeout occurred.



67
68
69
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 67

def force_flush
  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.

Parameters:

  • span (Span)

    the Span that just ended.



49
50
51
52
53
54
55
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 49

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.

Parameters:

  • span (Span)

    the Span that just started.

  • parent_context (Context)

    the parent Context of the newly started span.



38
39
40
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 38

def on_start(span, parent_context)
  # Do nothing.
end

#shutdownInteger

Called when TracerProvider#shutdown is called.

Returns:

  • (Integer)

    SUCCESS if no error occurred, FAILURE if a non-specific failure occurred, TIMEOUT if a timeout occurred.



75
76
77
# File 'lib/opentelemetry/sdk/trace/export/simple_span_processor.rb', line 75

def shutdown
  @span_exporter&.shutdown || SUCCESS
end