Langfuse.OpenTelemetry.AttributeMapper (Langfuse v0.1.0)

View Source

Maps OpenTelemetry span attributes to Langfuse observation fields.

This module provides comprehensive mapping from OpenTelemetry semantic conventions to Langfuse's data model, supporting:

  • GenAI semantic conventions (gen_ai.*)
  • Langfuse-specific attributes (langfuse.*)
  • OpenInference attributes (input.value, output.value)
  • MLflow attributes (mlflow.*)
  • LLM common attributes (llm.*)

Attribute Precedence

When multiple attributes map to the same Langfuse field, the precedence is:

  1. langfuse.* namespace (highest priority)
  2. gen_ai.* semantic conventions
  3. Framework-specific attributes (OpenInference, MLflow)
  4. Generic attributes (lowest priority)

Trace-Level Attributes

OpenTelemetry AttributeLangfuse Field
langfuse.trace.namename
langfuse.user.id, user.iduserId
langfuse.session.id, session.idsessionId
langfuse.trace.tagstags
langfuse.trace.publicpublic
langfuse.trace.inputinput
langfuse.trace.outputoutput
langfuse.releaserelease
langfuse.versionversion
langfuse.environment, deployment.environmentenvironment

Observation-Level Attributes

OpenTelemetry AttributeLangfuse Field
langfuse.observation.input, gen_ai.prompt, input.valueinput
langfuse.observation.output, gen_ai.completion, output.valueoutput
langfuse.observation.levellevel
langfuse.observation.status_messagestatusMessage

Generation-Specific Attributes

OpenTelemetry AttributeLangfuse Field
gen_ai.request.model, gen_ai.response.model, modelmodel
gen_ai.request.*modelParameters
gen_ai.usage.*, llm.token_count.*usage
gen_ai.usage.costcost
langfuse.observation.prompt.namepromptName
langfuse.observation.prompt.versionpromptVersion
langfuse.observation.completion_start_timecompletionStartTime

Summary

Functions

Maps OpenTelemetry span attributes to Langfuse observation fields.

Functions

map_attributes(attributes)

@spec map_attributes(map()) :: map()

Maps OpenTelemetry span attributes to Langfuse observation fields.

Takes a map of OTEL attributes and returns a map with Langfuse field names.

Examples

iex> attrs = %{"gen_ai.request.model" => "gpt-4", "gen_ai.usage.input_tokens" => 100}
iex> Langfuse.OpenTelemetry.AttributeMapper.map_attributes(attrs)
%{model: "gpt-4", usage: %{input: 100}}

iex> attrs = %{"langfuse.user.id" => "user-123", "langfuse.session.id" => "sess-456"}
iex> Langfuse.OpenTelemetry.AttributeMapper.map_attributes(attrs)
%{user_id: "user-123", session_id: "sess-456"}