Class: Langfuse::OtelExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/otel_exporter.rb

Overview

Converts batched Langfuse events into OTLP/HTTP JSON (ExportTraceServiceRequest) and sends them to the Langfuse OTEL endpoint for v4-compatible ingestion.

Constant Summary collapse

OTEL_ENDPOINT =
'/api/public/otel/v1/traces'

Instance Method Summary collapse

Constructor Details

#initialize(connection:, debug: false) ⇒ OtelExporter

Returns a new instance of OtelExporter.

Parameters:

  • connection (Faraday::Connection)

    HTTP connection to Langfuse host

  • debug (Boolean) (defaults to: false)

    whether to print debug output



14
15
16
17
# File 'lib/langfuse/otel_exporter.rb', line 14

def initialize(connection:, debug: false)
  @connection = connection
  @debug = debug
end

Instance Method Details

#export(events) ⇒ Faraday::Response

Export a batch of Langfuse events as OTLP spans.

Parameters:

  • events (Array<Hash>)

    array of event hashes from the event queue

Returns:

  • (Faraday::Response)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/langfuse/otel_exporter.rb', line 22

def export(events)
  resource_spans = build_resource_spans(events)
  payload = { resourceSpans: resource_spans }

  puts "OTEL export payload: #{JSON.pretty_generate(payload)}" if @debug

  @connection.post(OTEL_ENDPOINT) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(payload)
  end
end