Class: Langfuse::SpanProcessor Private

Inherits:
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor
  • Object
show all
Defined in:
lib/langfuse/span_processor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Batch span processor that owns Langfuse's enrichment and export filtering.

Instance Method Summary collapse

Constructor Details

#initialize(config:, exporter:, metrics_reporter:) ⇒ SpanProcessor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SpanProcessor.

Parameters:

  • config (Langfuse::Config)

    SDK configuration used for defaults and filtering

  • exporter (#export, #force_flush, #shutdown)

    Span exporter used by the batch processor

  • metrics_reporter (#add_to_counter, #record_value, #observe_value, nil)

    Resilient reporter shared with the OTLP exporter



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/langfuse/span_processor.rb', line 14

def initialize(config:, exporter:, metrics_reporter:)
  @logger = config.logger
  @default_trace_attributes = build_default_trace_attributes(config).freeze
  @should_export_span = config.should_export_span || Langfuse.method(:default_export_span?)
  @app_root_tracker = AppRootTracking::Tracker.new

  super(
    exporter,
    max_queue_size: config.batch_size * 2,
    schedule_delay: schedule_delay_for(config),
    max_export_batch_size: config.batch_size,
    metrics_reporter: metrics_reporter
  )
end

Instance Method Details

#on_finish(span) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Drop spans when the export filter rejects them or raises.

Parameters:

  • span (OpenTelemetry::SDK::Trace::Span)

    The span that ended



46
47
48
49
# File 'lib/langfuse/span_processor.rb', line 46

def on_finish(span)
  ready_spans = @app_root_tracker.finish(span, exportable: should_export_span?(span))
  ready_spans.each { |ready_span| super(copy_with_app_root(ready_span)) }
end

#on_start(span, parent_context) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Apply Langfuse trace defaults and propagated attributes before a span records work.

Parameters:

  • span (OpenTelemetry::SDK::Trace::Span)

    The span that started

  • parent_context (OpenTelemetry::Context)

    The parent context



34
35
36
37
38
39
40
# File 'lib/langfuse/span_processor.rb', line 34

def on_start(span, parent_context)
  return unless span.recording?

  apply_attributes(span, @default_trace_attributes)
  apply_attributes(span, propagated_attributes(parent_context))
  remember_app_root_state(span, parent_context)
end