Skip to content

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

chore: add pricing tier propagation on dual write (#10781)

Steffen Schmitz4ac0b97eacd0
diff --git a/packages/shared/src/server/repositories/definitions.ts b/packages/shared/src/server/repositories/definitions.ts
index 73c3ca6926..9629c16e78 100644
--- a/packages/shared/src/server/repositories/definitions.ts
+++ b/packages/shared/src/server/repositories/definitions.ts
@@ -653,6 +653,9 @@ export const eventRecordBaseSchema = z.object({
provided_cost_details: UsageCostSchema,
cost_details: UsageCostSchema,
+ usage_pricing_tier_id: z.string().nullish(),
+ usage_pricing_tier_name: z.string().nullish(),
+
// I/O
input: z.string().nullish(),
output: z.string().nullish(),
diff --git a/worker/src/features/eventPropagation/handleEventPropagationJob.ts b/worker/src/features/eventPropagation/handleEventPropagationJob.ts
index 2b0c89b880..af5a6d2f4b 100644
--- a/worker/src/features/eventPropagation/handleEventPropagationJob.ts
+++ b/worker/src/features/eventPropagation/handleEventPropagationJob.ts
@@ -275,6 +275,8 @@ export const handleEventPropagationJob = async (
usage_details,
provided_cost_details,
cost_details,
+ usage_pricing_tier_id,
+ usage_pricing_tier_name,
input,
output,
metadata,
@@ -324,6 +326,8 @@ export const handleEventPropagationJob = async (
obs.usage_details,
obs.provided_cost_details,
obs.cost_details,
+ obs.usage_pricing_tier_id,
+ obs.usage_pricing_tier_name,
coalesce(obs.input, '') AS input,
coalesce(obs.output, '') AS output,
-- Merge trace and observation metadata, with observation taking precedence (first map wins)
diff --git a/worker/src/features/eventPropagation/handleExperimentBackfill.ts b/worker/src/features/eventPropagation/handleExperimentBackfill.ts
index eec1bb3d08..54825ca4f0 100644
--- a/worker/src/features/eventPropagation/handleExperimentBackfill.ts
+++ b/worker/src/features/eventPropagation/handleExperimentBackfill.ts
@@ -62,6 +62,8 @@ interface SpanRecord {
provided_cost_details: Record<string, number> | null;
cost_details: Record<string, number> | null;
total_cost: number;
+ usage_pricing_tier_id: string | null;
+ usage_pricing_tier_name: string | null;
metadata: Record<string, unknown>;
source: string;
tags: Array<string>;
@@ -202,6 +204,8 @@ export async function getRelevantObservations(
o.provided_cost_details AS provided_cost_details,
o.cost_details AS cost_details,
coalesce(o.total_cost, 0) AS total_cost,
+ o.usage_pricing_tier_id,
+ o.usage_pricing_tier_name,
o.metadata,
multiIf(mapContains(o.metadata, 'resourceAttributes'), 'otel', 'ingestion-api') AS source,
[] as tags,
@@ -514,6 +518,9 @@ async function writeEnrichedSpans(spans: EnrichedSpan[]): Promise<void> {
costDetails: span.cost_details || undefined,
totalCost: span.total_cost || undefined,
+ usagePricingTierId: span.usage_pricing_tier_id || undefined,
+ usagePricingTierName: span.usage_pricing_tier_name || undefined,
+
// I/O
input: span.input || undefined,
output: span.output || undefined,
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index 2605f84d8f..3a7b9349e9 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -384,6 +384,9 @@ export class IngestionService {
cost_details:
generationUsage?.cost_details ?? eventData.costDetails ?? {},
+ usage_pricing_tier_id: generationUsage?.usage_pricing_tier_id,
+ usage_pricing_tier_name: generationUsage?.usage_pricing_tier_name,
+
// I/O
input: eventData.input,
output: eventData.output,