Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(otel): support Genkit spans in OTel pipeline (#12199)

DM8940434fd873
diff --git a/packages/shared/src/server/otel/ObservationTypeMapper.ts b/packages/shared/src/server/otel/ObservationTypeMapper.ts
index 2d0f8e5d96..ac533bab7f 100644
--- a/packages/shared/src/server/otel/ObservationTypeMapper.ts
+++ b/packages/shared/src/server/otel/ObservationTypeMapper.ts
@@ -232,6 +232,7 @@ export class ObservationTypeMapperRegistry {
},
),
+ // Priority 2: OpenInference span kind
new SimpleAttributeMapper("OpenInference", 2, "openinference.span.kind", {
// Format:
// OpenInference Value: Langfuse ObservationType
@@ -245,6 +246,7 @@ export class ObservationTypeMapperRegistry {
EVALUATOR: "EVALUATOR",
}),
+ // Priority 3: OpenTelemetry GenAI operation
new SimpleAttributeMapper(
"OTel_GenAI_Operation",
3,
@@ -265,12 +267,25 @@ export class ObservationTypeMapperRegistry {
},
),
- // Priority 4: Vercel AI SDK generation/embedding operations (require model information)
+ // Priority 4: Genkit subtype
+ new SimpleAttributeMapper("Genkit", 4, "genkit:metadata:subtype", {
+ // Format:
+ // Genkit Value: Langfuse ObservationType
+ "background-model": "GENERATION",
+ model: "GENERATION",
+ embedder: "EMBEDDING",
+ tool: "TOOL",
+ "tool.v2": "TOOL",
+ retriever: "RETRIEVER",
+ evaluator: "EVALUATOR",
+ }),
+
+ // Priority 5: Vercel AI SDK generation/embedding operations (require model information)
new CustomAttributeMapper(
// NAME
"Vercel_AI_SDK_Operation_Generation_Like",
// PRIORITY
- 4,
+ 5,
// CANMAP?
(attributes) => {
const modelKeys = [
@@ -327,12 +342,12 @@ export class ObservationTypeMapperRegistry {
},
),
- // Priority 5: Vercel AI SDK span-like operations (no model info)
+ // Priority 6: Vercel AI SDK span-like operations (no model info)
new CustomAttributeMapper(
// NAME
"Vercel_AI_SDK_Operation_Span_Like",
// PRIORITY
- 5,
+ 6,
// CANMAP?
(attributes) => {
// Check if it's a Vercel AI SDK operation (starts with "ai.")
@@ -378,12 +393,12 @@ export class ObservationTypeMapperRegistry {
},
),
- // GenAI tool call detection (e.g., Pydantic AI, any framework using gen_ai.tool.* attributes)
+ // Priority 7: GenAI tool call detection (e.g., Pydantic AI, any framework using gen_ai.tool.* attributes)
// unfortunately, Pydantic does not set the gen_ai.operation.name attribute on tool calls
// therefore, we need another mapper here.
new CustomAttributeMapper(
"GenAI_Tool_Call",
- 6,
+ 7,
(attributes) => {
// Check for standard GenAI tool call attributes
return (
@@ -394,10 +409,10 @@ export class ObservationTypeMapperRegistry {
() => "TOOL",
),
- // LiveKit spans: use span name to determine observation type
+ // Priority 8: LiveKit spans: use span name to determine observation type
new CustomAttributeMapper(
"LiveKit_SpanName",
- 7,
+ 8,
(_attributes, _resourceAttributes, scopeData, spanName) => {
if (scopeData?.name !== "livekit-agents") return false;
@@ -415,9 +430,10 @@ export class ObservationTypeMapperRegistry {
},
),
+ // Priority 9: Model-based fallback
new CustomAttributeMapper(
"ModelBased",
- 8,
+ 9,
(attributes, _resourceAttributes, _scopeData) => {
const modelKeys = [
LangfuseOtelSpanAttributes.OBSERVATION_MODEL,
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index fef7d32f7e..e1f1053f76 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -1272,6 +1272,9 @@ export class OtelIngestionProcessor {
"gen_ai.output.messages",
"gen_ai.tool.call.arguments",
"gen_ai.tool.call.result",
+ // Genkit
+ "genkit:input",
+ "genkit:output",
];
// Delete simple keys
@@ -1318,6 +1321,25 @@ export class OtelIngestionProcessor {
return { input, output, filteredAttributes };
}
+ // Genkit
+ if (instrumentationScopeName === "genkit-tracer") {
+ const genkitInput =
+ this.parseJsonPayload(attributes["genkit:input"]) ??
+ attributes["genkit:input"];
+ const genkitOutput =
+ this.parseJsonPayload(attributes["genkit:output"]) ??
+ attributes["genkit:output"];
+
+ if (genkitInput != null || genkitOutput != null) {
+ // For model spans prefer messages[] as input and message object as output.
+ // For flow/util spans there is no messages/message wrapper, so fall back to the full object
+ input = genkitInput?.messages ?? genkitInput;
+ output = genkitOutput?.message ?? genkitOutput;
+ }
+
+ return { input, output, filteredAttributes };
+ }
+
// Vercel AI SDK
if (instrumentationScopeName === "ai") {
input =
@@ -1799,6 +1821,11 @@ export class OtelIngestionProcessor {
: JSON.stringify(attributes["gen_ai.tool.name"]);
}
+ // Genkit
+ if ("genkit:name" in attributes) {
+ return attributes["genkit:name"] as string;
+ }
+
// Logfire message for pydantic AI
const nameKeys = ["logfire.msg"];
for (const key of nameKeys) {
@@ -1956,6 +1983,17 @@ export class OtelIngestionProcessor {
}
}
+ // Genkit
+ if (instrumentationScopeName === "genkit-tracer") {
+ const genkitConfig =
+ this.parseJsonPayload(attributes["genkit:input"])?.config ??
+ this.parseJsonPayload(attributes["genkit:output"])?.request?.config;
+
+ if (genkitConfig) {
+ return this.sanitizeModelParams(genkitConfig);
+ }
+ }
+
// Vercel AI SDK
if (instrumentationScopeName === "ai") {
return {
@@ -2060,6 +2098,12 @@ export class OtelIngestionProcessor {
"llm.model_name",
"model",
];
+
+ // Genkit: genkit:name is the model identifier only on model-subtype spans
+ if (attributes["genkit:metadata:subtype"] === "model") {
+ modelNameKeys.push("genkit:name");
+ }
+
for (const key of modelNameKeys) {
if (attributes[key]) {
return typeof attributes[key] === "string"
@@ -2085,6 +2129,29 @@ export class OtelIngestionProcessor {
}
}
+ // Genkit
+ if (instrumentationScopeName === "genkit-tracer") {
+ const genkitOutput = this.parseJsonPayload(attributes["genkit:output"]);
+ const usage = genkitOutput?.usage as Record<string, number>;
+
+ if (usage) {
+ const {
+ inputTokens: input,
+ thoughtsTokens: thoughts,
+ outputTokens: output,
+ totalTokens: total,
+ } = usage;
+
+ const usageDetails: Record<string, number> = {};
+ if (input) usageDetails.input = input;
+ if (output) usageDetails.output = Math.max(output - (thoughts ?? 0), 0);
+ if (total) usageDetails.total = total;
+ if (thoughts) usageDetails.output_reasoning = thoughts;
+
+ return usageDetails;
+ }
+ }
+
if (instrumentationScopeName === "ai") {
try {
const usageDetails: Record<string, number | undefined> = {
@@ -2521,6 +2588,23 @@ export class OtelIngestionProcessor {
// Fallthrough
}
}
+
+ /**
+ * Parses a payload (object or JSON string) and returns the object
+ * or `undefined` if invalid.
+ */
+ private parseJsonPayload = (payload: unknown): any => {
+ if (payload && typeof payload === "object") return payload;
+ if (typeof payload === "string") {
+ try {
+ return JSON.parse(payload);
+ } catch {
+ return undefined;
+ }
+ }
+ return undefined;
+ };
+
/**
* Get a set of trace IDs that have been seen recently (from Redis cache).
* Returns a Set of trace IDs that should not trigger new trace creation.
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
index cf77dbb939..6d77e21305 100644
--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
@@ -1011,6 +1011,177 @@ describe("OTel Resource Span Mapping", () => {
expect(embeddingEvent).toBeDefined();
expect(embeddingEvent?.body.model).toBe("gemini-embedding-001");
});
+
+ it("should convert a Genkit OTel span to Langfuse generation-create event", async () => {
+ const genkitInput = JSON.stringify({
+ config: {},
+ messages: [
+ {
+ role: "user",
+ content: [
+ {
+ text: "Output should be in JSON format.",
+ },
+ ],
+ },
+ ],
+ output: {
+ contentType: "application/json",
+ format: "json",
+ },
+ });
+
+ const genkitOutput = JSON.stringify({
+ finishReason: "stop",
+ latencyMs: 6270.767958,
+ message: {
+ content: [
+ {
+ text: {
+ confidence_level: 0.95,
+ },
+ },
+ ],
+ role: "model",
+ },
+ request: {
+ config: {},
+ messages: [
+ {
+ role: "user",
+ content: [
+ {
+ text: "Output should be in JSON format.",
+ },
+ ],
+ },
+ ],
+ output: {
+ contentType: "application/json",
+ format: "json",
+ },
+ },
+ usage: {
+ inputCharacters: 10667,
+ inputTokens: 1618,
+ outputCharacters: 25,
+ outputTokens: 337,
+ thoughtsTokens: 320,
+ totalTokens: 1955,
+ },
+ });
+
+ const resourceSpan = {
+ resource: {
+ attributes: [
+ { key: "service.name", value: { stringValue: "unknown_service" } },
+ {
+ key: "telemetry.sdk.language",
+ value: { stringValue: "go" },
+ },
+ {
+ key: "telemetry.sdk.name",
+ value: { stringValue: "opentelemetry" },
+ },
+ {
+ key: "telemetry.sdk.version",
+ value: { stringValue: "1.40.0" },
+ },
+ ],
+ },
+ scopeSpans: [
+ {
+ scope: { name: "genkit-tracer", version: "v1" },
+ spans: [
+ {
+ traceId: {
+ type: "Buffer",
+ data: [
+ 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154,
+ 165, 176,
+ ],
+ },
+ spanId: {
+ type: "Buffer",
+ data: [1, 2, 3, 4, 5, 6, 7, 8],
+ },
+ name: "genkit-action",
+ kind: 3,
+ startTimeUnixNano: {
+ low: 153687506,
+ high: 404677085,
+ unsigned: true,
+ },
+ endTimeUnixNano: {
+ low: 1327836088,
+ high: 404677085,
+ unsigned: true,
+ },
+ attributes: [
+ { key: "genkit:type", value: { stringValue: "action" } },
+ {
+ key: "genkit:name",
+ value: { stringValue: "openai/gpt-5-mini" },
+ },
+ {
+ key: "genkit:metadata:subtype",
+ value: { stringValue: "model" },
+ },
+ { key: "genkit:input", value: { stringValue: genkitInput } },
+ {
+ key: "genkit:output",
+ value: { stringValue: genkitOutput },
+ },
+ ],
+ status: { code: 1 },
+ },
+ ],
+ },
+ ],
+ };
+
+ const langfuseEvents = await convertOtelSpanToIngestionEvent(
+ resourceSpan,
+ new Set(),
+ );
+
+ const schema = createIngestionEventSchema();
+ const parsedEvents = langfuseEvents.map((event) => schema.parse(event));
+ expect(parsedEvents).toHaveLength(2);
+
+ const generationEvent = parsedEvents.find(
+ (event) => event.type === "generation-create",
+ );
+ expect(generationEvent).toBeDefined();
+ expect(generationEvent?.body.name).toBe("openai/gpt-5-mini");
+ expect(generationEvent?.body.model).toBe("openai/gpt-5-mini");
+ expect(generationEvent?.body.input).toEqual([
+ {
+ role: "user",
+ content: [
+ {
+ text: "Output should be in JSON format.",
+ },
+ ],
+ },
+ ]);
+ expect(generationEvent?.body.output).toEqual({
+ content: [
+ {
+ text: {
+ confidence_level: 0.95,
+ },
+ },
+ ],
+ role: "model",
+ });
+ expect(generationEvent?.body.usageDetails).toMatchObject({
+ input: 1618,
+ output_reasoning: 320,
+ output: 17,
+ total: 1955,
+ });
+ });
});
describe("Property Mapping", () => {
diff --git a/worker/src/constants/default-model-prices.json b/worker/src/constants/default-model-prices.json
index 9564347f4d..493d64e969 100644
--- a/worker/src/constants/default-model-prices.json
+++ b/worker/src/constants/default-model-prices.json
@@ -1358,9 +1358,9 @@
{
"id": "cluv2sjeo000008ih0fv23hi0",
"modelName": "gemini-1.0-pro-latest",
- "matchPattern": "(?i)^(google\/)?(gemini-1.0-pro-latest)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-1.0-pro-latest)(@[a-zA-Z0-9]+)?$",
"createdAt": "2024-04-11T10:27:46.517Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cluv2sjeo000008ih0fv23hi0_tier_default",
@@ -1378,9 +1378,9 @@
{
"id": "cluv2subq000108ih2mlrga6a",
"modelName": "gemini-1.0-pro",
- "matchPattern": "(?i)^(google\/)?(gemini-1.0-pro)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-1.0-pro)(@[a-zA-Z0-9]+)?$",
"createdAt": "2024-04-11T10:27:46.517Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cluv2subq000108ih2mlrga6a_tier_default",
@@ -1398,9 +1398,9 @@
{
"id": "cluv2sx04000208ihbek75lsz",
"modelName": "gemini-1.0-pro-001",
- "matchPattern": "(?i)^(google\/)?(gemini-1.0-pro-001)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-1.0-pro-001)(@[a-zA-Z0-9]+)?$",
"createdAt": "2024-04-11T10:27:46.517Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cluv2sx04000208ihbek75lsz_tier_default",
@@ -1418,9 +1418,9 @@
{
"id": "cluv2szw0000308ihch3n79x7",
"modelName": "gemini-pro",
- "matchPattern": "(?i)^(google\/)?(gemini-pro)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-pro)(@[a-zA-Z0-9]+)?$",
"createdAt": "2024-04-11T10:27:46.517Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cluv2szw0000308ihch3n79x7_tier_default",
@@ -1438,9 +1438,9 @@
{
"id": "cluv2t2x0000408ihfytl45l1",
"modelName": "gemini-1.5-pro-latest",
- "matchPattern": "(?i)^(google\/)?(gemini-1.5-pro-latest)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-1.5-pro-latest)(@[a-zA-Z0-9]+)?$",
"createdAt": "2024-04-11T10:27:46.517Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cluv2t2x0000408ihfytl45l1_tier_default",
@@ -2111,9 +2111,9 @@
{
"id": "cm6l8jdef0000tymz52sh0ql0",
"modelName": "gemini-2.0-flash-001",
- "matchPattern": "(?i)^(google\/)?(gemini-2.0-flash-001)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.0-flash-001)(@[a-zA-Z0-9]+)?$",
"createdAt": "2025-02-06T11:11:35.241Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cm6l8jdef0000tymz52sh0ql0_tier_default",
@@ -2131,9 +2131,9 @@
{
"id": "cm6l8jfgh0000tymz52sh0ql1",
"modelName": "gemini-2.0-flash-lite-preview-02-05",
- "matchPattern": "(?i)^(google\/)?(gemini-2.0-flash-lite-preview-02-05)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.0-flash-lite-preview-02-05)(@[a-zA-Z0-9]+)?$",
"createdAt": "2025-02-06T11:11:35.241Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cm6l8jfgh0000tymz52sh0ql1_tier_default",
@@ -2467,9 +2467,9 @@
{
"id": "cm7zsrs1327124dhjtb95w8f74",
"modelName": "gemini-2.0-flash",
- "matchPattern": "(?i)^(google\/)?(gemini-2.0-flash)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.0-flash)(@[a-zA-Z0-9]+)?$",
"createdAt": "2025-04-22T10:11:35.241Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cm7zsrs1327124dhjtb95w8f74_tier_default",
@@ -2487,9 +2487,9 @@
{
"id": "cm7ztrs1327124dhjtb95w8f19",
"modelName": "gemini-2.0-flash-lite-preview",
- "matchPattern": "(?i)^(google\/)?(gemini-2.0-flash-lite-preview)(@[a-zA-Z0-9]+)?$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.0-flash-lite-preview)(@[a-zA-Z0-9]+)?$",
"createdAt": "2025-04-22T10:11:35.241Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cm7ztrs1327124dhjtb95w8f19_tier_default",
@@ -2795,9 +2795,9 @@
{
"id": "cmcnjkfwn000107l43bf5e8ax",
"modelName": "gemini-2.5-flash",
- "matchPattern": "(?i)^(google\/)?(gemini-2.5-flash)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.5-flash)$",
"createdAt": "2025-07-03T13:44:06.964Z",
- "updatedAt": "2026-03-04T00:00:00.000Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cmcnjkfwn000107l43bf5e8ax_tier_default",
@@ -2828,9 +2828,9 @@
{
"id": "cmcnjkrfa000207l4fpnh5mnv",
"modelName": "gemini-2.5-flash-lite",
- "matchPattern": "(?i)^(google\/)?(gemini-2.5-flash-lite)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.5-flash-lite)$",
"createdAt": "2025-07-03T13:44:06.964Z",
- "updatedAt": "2026-03-04T00:00:00.000Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cmcnjkrfa000207l4fpnh5mnv_tier_default",
@@ -3361,9 +3361,9 @@
{
"id": "cmig1hb7i000104l72qrzgc6h",
"modelName": "gemini-2.5-pro",
- "matchPattern": "(?i)^(google\/)?(gemini-2.5-pro)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-2.5-pro)$",
"createdAt": "2025-11-26T13:27:53.545Z",
- "updatedAt": "2026-03-04T00:00:00.000Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cmig1hb7i000104l72qrzgc6h_tier_default",
@@ -3423,9 +3423,9 @@
{
"id": "cmig1wmep000404l7fh6q5uog",
"modelName": "gemini-3-pro-preview",
- "matchPattern": "(?i)^(google\/)?(gemini-3-pro-preview)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-3-pro-preview)$",
"createdAt": "2025-11-26T13:27:53.545Z",
- "updatedAt": "2025-12-12T15:00:06.513Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cmig1wmep000404l7fh6q5uog_tier_default",
@@ -3483,9 +3483,9 @@
{
"id": "55106bba-a5dd-441b-bc0d-5652582b349d",
"modelName": "gemini-3.1-pro-preview",
- "matchPattern": "(?i)^(google\/)?(gemini-3.1-pro-preview(-customtools)?)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-3.1-pro-preview(-customtools)?)$",
"createdAt": "2026-02-19T00:00:00.000Z",
- "updatedAt": "2026-02-19T00:00:00.000Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "55106bba-a5dd-441b-bc0d-5652582b349d_tier_default",
@@ -3887,9 +3887,9 @@
{
"id": "cmjfoeykl000004l8ffzra8c7",
"modelName": "gemini-3-flash-preview",
- "matchPattern": "(?i)^(google\/)?(gemini-3-flash-preview)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-3-flash-preview)$",
"createdAt": "2025-12-21T12:01:42.282Z",
- "updatedAt": "2025-12-21T12:01:42.282Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "cmjfoeykl000004l8ffzra8c7_tier_default",
@@ -3918,9 +3918,9 @@
{
"id": "0707bef8-10c8-46e2-a871-0436f05f0b92",
"modelName": "gemini-3.1-flash-lite-preview",
- "matchPattern": "(?i)^(google\/)?(gemini-3.1-flash-lite-preview)$",
+ "matchPattern": "(?i)^(google(ai)?\/)?(gemini-3.1-flash-lite-preview)$",
"createdAt": "2026-03-03T00:00:00.000Z",
- "updatedAt": "2026-03-03T00:00:00.000Z",
+ "updatedAt": "2026-03-06T00:00:00.000Z",
"pricingTiers": [
{
"id": "0707bef8-10c8-46e2-a871-0436f05f0b92_tier_default",