Skip to content

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

fix(otel): map OpenInference total cost (#14472)

Hassieb Pakzada15b2d00a600
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index bc7fa135ba..54fb9f4ee6 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -2588,9 +2588,16 @@ export class OtelIngestionProcessor {
);
if (fromAttribute !== null) return fromAttribute;
- if (attributes["gen_ai.usage.cost"]) {
- return { total: attributes["gen_ai.usage.cost"] };
+ const genAiUsageCost = attributes["gen_ai.usage.cost"];
+ if (genAiUsageCost != null && genAiUsageCost !== "") {
+ return { total: genAiUsageCost };
}
+
+ const openInferenceTotalCost = attributes["llm.cost.total"];
+ if (openInferenceTotalCost != null && openInferenceTotalCost !== "") {
+ return { total: openInferenceTotalCost };
+ }
+
return {};
}
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
index 6312ee606d..24ba6030ab 100644
--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
@@ -3064,6 +3064,18 @@ describe("OTel Resource Span Mapping", () => {
entityAttributeValue: 0.000151,
},
],
+ [
+ "should extract cost from OpenInference llm.cost.total",
+ {
+ entity: "observation",
+ otelAttributeKey: "llm.cost.total",
+ otelAttributeValue: {
+ doubleValue: 0.000151,
+ },
+ entityAttributeKey: "costDetails.total",
+ entityAttributeValue: 0.000151,
+ },
+ ],
[
"should not treat usage.cost as usage",
{