Skip to content

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

fix(ingestion): promote model-less provided costs (#15717)

Hassieb Pakzad4798b4a823d7
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index d9fee0aa02..577a1d9734 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -265,6 +265,11 @@ export class IngestionService {
"events",
);
+ const shouldEnrichUsageAndCost =
+ Boolean(eventData.modelName) ||
+ Object.keys(eventData.providedUsageDetails ?? {}).length > 0 ||
+ Object.keys(eventData.providedCostDetails ?? {}).length > 0;
+
// Perform lookups for prompt and model/usage enrichment
const [prompt, generationUsage] = await Promise.all([
// Lookup prompt by name and version
@@ -279,8 +284,8 @@ export class IngestionService {
label: undefined,
})
: null,
- // Lookup model and enrich usage/cost details (includes tokenization if needed)
- eventData.modelName
+ // Promote provided usage/cost and enrich from the model when available.
+ shouldEnrichUsageAndCost
? this.getGenerationUsage({
projectId: eventData.projectId,
observationRecord: {
diff --git a/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts b/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
index 633b7b5897..c0d1c3cc6d 100644
--- a/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
+++ b/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
@@ -125,6 +125,38 @@ describe("IngestionService unit tests", () => {
});
});
+ it("promotes provided usage and cost for model-less direct events", async () => {
+ const ingestionService = new IngestionService(
+ {} as any,
+ {} as any,
+ {} as any,
+ {} as any,
+ );
+
+ const eventRecord = await ingestionService.createEventRecord(
+ {
+ projectId: "project-id",
+ traceId: "trace-id",
+ spanId: "observation-id",
+ name: "provided-cost",
+ type: "GENERATION",
+ environment: "default",
+ startTimeISO: "2026-08-03T00:00:00.000Z",
+ endTimeISO: "2026-08-03T00:00:01.000Z",
+ providedUsageDetails: { total: 3 },
+ providedCostDetails: { total: 0.03 },
+ metadata: {},
+ source: "otel",
+ },
+ "otel/project-id/raw-event.json",
+ );
+
+ expect(eventRecord.provided_usage_details).toEqual({ total: 3 });
+ expect(eventRecord.usage_details).toEqual({ total: 3 });
+ expect(eventRecord.provided_cost_details).toEqual({ total: 0.03 });
+ expect(eventRecord.cost_details).toEqual({ total: 0.03 });
+ });
+
it("does not overflow legacy observation or dual-write staging records", async () => {
const addToQueue = vi.fn();
const ingestionService = new IngestionService(