Skip to content

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

fix: detect openinference LLM calls as generations (#5833)

Steffen Schmitz9b237d40412d
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
index ed8176a765..307ebbc2d2 100644
--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
@@ -360,6 +360,35 @@ describe("OTel Resource Span Mapping", () => {
expect(langfuseEvents).toHaveLength(2);
});
+ it("should interpret openinference LLM calls as a generation", async () => {
+ const resourceSpan = {
+ scopeSpans: [
+ {
+ spans: [
+ {
+ ...defaultSpanProps,
+ attributes: [
+ {
+ key: "openinference.span.kind",
+ value: { stringValue: "LLM" },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+
+ // When
+ const langfuseEvents = convertOtelSpanToIngestionEvent(resourceSpan);
+
+ // Then
+ // Check that we create a generation
+ expect(
+ langfuseEvents.some((event) => event.type === "generation-create"),
+ ).toBe(true);
+ });
+
it.each([
[
"should cast input_tokens from string to number",
@@ -481,6 +510,16 @@ describe("OTel Resource Span Mapping", () => {
entityAttributeValue: "gpt-4",
},
],
+ [
+ "should extract providedModelName from llm.model_name",
+ {
+ entity: "observation",
+ otelAttributeKey: "llm.model_name",
+ otelAttributeValue: { stringValue: "gpt-4" },
+ entityAttributeKey: "model",
+ entityAttributeValue: "gpt-4",
+ },
+ ],
[
"should extract modelParameters from gen_ai.request (request.temperature)",
{
@@ -503,6 +542,18 @@ describe("OTel Resource Span Mapping", () => {
entityAttributeValue: 100,
},
],
+ [
+ "should extract usage from llm.token_count (input_tokens)",
+ {
+ entity: "observation",
+ otelAttributeKey: "llm.token_count.prompt",
+ otelAttributeValue: {
+ intValue: { low: 100, high: 0, unsigned: false },
+ },
+ entityAttributeKey: "usageDetails.input",
+ entityAttributeValue: 100,
+ },
+ ],
[
"should extract usage from gen_ai.usage (input_tokens)",
{
diff --git a/web/src/features/otel/server/index.ts b/web/src/features/otel/server/index.ts
index 8559adf7eb..f6fffd37f2 100644
--- a/web/src/features/otel/server/index.ts
+++ b/web/src/features/otel/server/index.ts
@@ -429,7 +429,10 @@ export const convertOtelSpanToIngestionEvent = (
// If the span has a model property, we consider it a generation.
// Just checking for llm.* or gen_ai.* attributes leads to overreporting and wrong
// aggregations for costs.
- const isGeneration = Boolean(observation.model);
+ const isGeneration =
+ Boolean(observation.model) ||
+ ("openinference.span.kind" in attributes &&
+ attributes["openinference.span.kind"] === "LLM");
events.push({
id: randomUUID(),
type: isGeneration ? "generation-create" : "span-create",