Skip to content

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

Open
kilo-code-bot[bot] wants to merge 1 commit into
mainfrom
feat/o11y-api-metrics-kilo-user-id
Open

feat(o11y): add kilo_user_id to API metrics for usage reconciliation#3239
kilo-code-bot[bot] wants to merge 1 commit 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.
Files Reviewed (2 files)
  • services/o11y/pipelines/api-metrics-schema.json
  • services/o11y/src/o11y-analytics.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 213,182 tokens

@iscekic iscekic self-assigned this May 14, 2026
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.

1 participant