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:) ⇒ 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:



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

def initialize(config:, exporter:)
  @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: ResilientMetricsReporter.wrap(config.metrics_reporter, logger: config.logger)
  )
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



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

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



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

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