Skip to content

feat(o11y): add kilo_user_id to API metrics for usage reconciliation#3239

Merged
iscekic merged 2 commits into
mainfrom
feat/o11y-api-metrics-kilo-user-id
May 19, 2026
Merged

feat(o11y): add kilo_user_id to API metrics for usage reconciliation#3239
iscekic merged 2 commits into
mainfrom
feat/o11y-api-metrics-kilo-user-id

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented May 14, 2026

Summary

  • kiloUserId was already a required field in ApiMetricsParamsSchema (populated by the caller) but was never written to either the Analytics Engine dataset (O11Y_API_METRICS) or the Cloudflare Pipeline stream (API_METRICS_STREAM).
  • This PR adds kiloUserId as blob7 in the Analytics Engine writeDataPoint call and as kilo_user_id in the stream payload, making it available in both AE queries and Snowflake exports.
  • The api-metrics-schema.json pipeline schema definition is updated accordingly to reflect the new kilo_user_id: string field.
  • The purpose is to enable reconciliation of o11y API metrics records with microdollar usage records by user.

Note: The Cloudflare Pipeline stream schema is immutable. The existing stream must be recreated with the updated schema before the new field appears in R2/Snowflake. Run:

./pipelines/recreate-stream.sh o11y_api_metrics_stream pipelines/api-metrics-schema.json \
  o11y_api_metrics_pipeline o11y_api_metrics_sink

Verification

  • Deploy the o11y Worker and send an /ingest/api-metrics request; confirm kilo_user_id appears in AE query results and in the stream batch.
  • After recreating the Pipeline stream, verify the field lands in Snowflake.

Visual Changes

N/A

Reviewer Notes

  • No schema changes to ApiMetricsParamsSchema were needed — kiloUserId was already required there.
  • The AE blobs array ordering is positional, so blob7 = kiloUserId appends without shifting existing fields.
  • The stream schema change requires the recreate script to be run in production before the field is persisted.

Built for Igor Šćekić by Kilo for Slack

Include kiloUserId (already present in ApiMetricsParamsSchema) as
blob7 in the Analytics Engine data point and as kilo_user_id in the
Pipeline stream payload so that o11y API metrics records can be
reconciled with microdollar usage records by user.
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented May 14, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This is a clean, minimal change that correctly wires up kiloUserIdblob7 (AE) and kilo_user_id (Pipeline stream), consistent with the existing blob ordering and the already-required field in ApiMetricsParamsSchema.

Key points verified:

  • kiloUserId is z.string().min(1) — always a non-empty string, no null/undefined risk.
  • blob7 appends after blob6 (userByok) without shifting any existing positional blobs.
  • kilo_user_id is correctly placed between user_byok and ttfb_ms in api-metrics-schema.json, matching the stream payload field ordering.
  • The operational requirement to recreate the Pipeline stream before the field lands in R2/Snowflake is clearly documented in both the PR description and the inline comment in o11y-analytics.ts.
  • required: true in the pipeline schema is appropriate since the Zod schema guarantees the field is always present.
  • New commit (incremental): Adds matching test assertions for blob7 = 'user_123' in the AE blobs array and kilo_user_id: 'user_123' in the pipeline payload — makeValidApiMetricsBody() already included kiloUserId: 'user_123', so no fixture changes were needed. Coverage is complete and correct.
Files Reviewed (3 files)
  • services/o11y/pipelines/api-metrics-schema.json
  • services/o11y/src/o11y-analytics.ts
  • services/o11y/test/index.spec.ts

Reviewed by claude-sonnet-4.6 · 166,553 tokens

Review guidance: REVIEW.md from base branch main

@iscekic iscekic self-assigned this May 14, 2026
@iscekic iscekic requested a review from jeanduplessis May 19, 2026 15:03
@iscekic iscekic enabled auto-merge (squash) May 19, 2026 15:09
@iscekic iscekic merged commit fbd1dce into main May 19, 2026
12 checks passed
@iscekic iscekic deleted the feat/o11y-api-metrics-kilo-user-id branch May 19, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants