Langfuse.OpenTelemetry.AttributeMapper (Langfuse v0.2.0)
View SourceMaps 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:
langfuse.*namespace (highest priority)gen_ai.*semantic conventions- Framework-specific attributes (OpenInference, MLflow)
- Generic attributes (lowest priority)
Trace-Level Attributes
| OpenTelemetry Attribute | Langfuse Field |
|---|---|
langfuse.trace.name | name |
langfuse.user.id, user.id | userId |
langfuse.session.id, session.id | sessionId |
langfuse.trace.tags | tags |
langfuse.trace.public | public |
langfuse.trace.input | input |
langfuse.trace.output | output |
langfuse.release | release |
langfuse.version | version |
langfuse.environment, deployment.environment | environment |
Observation-Level Attributes
| OpenTelemetry Attribute | Langfuse Field |
|---|---|
langfuse.observation.input, gen_ai.prompt, input.value | input |
langfuse.observation.output, gen_ai.completion, output.value | output |
langfuse.observation.level | level |
langfuse.observation.status_message | statusMessage |
Generation-Specific Attributes
| OpenTelemetry Attribute | Langfuse Field |
|---|---|
gen_ai.request.model, gen_ai.response.model, model | model |
gen_ai.request.* | modelParameters |
gen_ai.usage.*, llm.token_count.* | usage |
gen_ai.usage.cost | cost |
langfuse.observation.prompt.name | promptName |
langfuse.observation.prompt.version | promptVersion |
langfuse.observation.completion_start_time | completionStartTime |
Summary
Functions
Maps OpenTelemetry span attributes to Langfuse observation fields.
Functions
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"}