GeezerVison is showing github.com — Reapply "feat(stats): add user ids to inference metrics" · sujee/opencode@f416f52
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: infra/stats.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -56,6 +56,7 @@ const inferenceEventTable = new aws.s3tables.Table( | 56 | 56 | { name: "error_cause2", type: "string", required: false }, | 57 | 57 | { name: "api_key", type: "string", required: false }, | 58 | 58 | { name: "workspace", type: "string", required: false }, | | 59 | + { name: "user_id", type: "string", required: false }, | 59 | 60 | { name: "is_subscription", type: "boolean", required: false }, | 60 | 61 | { name: "subscription", type: "string", required: false }, | 61 | 62 | { name: "response_length", type: "long", required: false }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/zen/util/handler.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -697,6 +697,7 @@ export async function handler( | 697 | 697 | logger.metric({ | 698 | 698 | api_key: data.apiKey, | 699 | 699 | workspace: data.workspaceID, | | 700 | + user_id: data.user.id, | 700 | 701 | ...(() => { | 701 | 702 | if (data.billing.subscription) | 702 | 703 | return { | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/function/src/log-processor.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -132,6 +132,7 @@ function toLakeEvent(time: string, data: Record<string, unknown>) { | 132 | 132 | error_cause2: string(data, "error.cause2"), | 133 | 133 | api_key: string(data, "api_key"), | 134 | 134 | workspace: string(data, "workspace"), | | 135 | + user_id: string(data, "user_id"), | 135 | 136 | is_subscription: boolean(data, "isSubscription"), // removed | 136 | 137 | subscription: string(data, "subscription"), | 137 | 138 | response_length: integer(data, "response_length"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/inference.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,6 +75,7 @@ WITH normalized AS ( | 75 | 75 | session, | 76 | 76 | COALESCE(NULLIF(workspace, ''), '') AS workspace, | 77 | 77 | COALESCE(NULLIF(api_key, ''), '') AS api_key, | | 78 | + COALESCE(NULLIF(user_id, ''), '') AS user_id, | 78 | 79 | status, | 79 | 80 | duration AS duration_ms, | 80 | 81 | time_to_first_byte AS ttfb_ms, | @@ -116,7 +117,7 @@ WITH normalized AS ( | 116 | 117 | country, | 117 | 118 | continent, | 118 | 119 | session, | 119 | | - COALESCE(NULLIF(workspace, ''), NULLIF(api_key, '')) AS user_key, | | 120 | + COALESCE(NULLIF(user_id, ''), NULLIF(workspace, ''), NULLIF(api_key, '')) AS user_key, | 120 | 121 | status, | 121 | 122 | duration_ms, | 122 | 123 | ttfb_ms, | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/honeycomb-backfill.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -454,7 +454,11 @@ function baseAggregate(row: RawRow, grain: Grain, opts: ImportOptions): StatBase | 454 | 454 | tier: tier(row), | 455 | 455 | sessions: integer(row, "sessions", ["COUNT_DISTINCT(session)"]), | 456 | 456 | requests: integer(row, "requests", ["COUNT", "COUNT()"]), | 457 | | - unique_users: integer(row, "unique_users", ["COUNT_DISTINCT(workspace)", "COUNT_DISTINCT(api_key)"]), | | 457 | + unique_users: integer(row, "unique_users", [ | | 458 | + "COUNT_DISTINCT(user_id)", | | 459 | + "COUNT_DISTINCT(workspace)", | | 460 | + "COUNT_DISTINCT(api_key)", | | 461 | + ]), | 458 | 462 | input_tokens: integer(row, "input_tokens", ["SUM(tokens.input)", "SUM(tokens_input)"]), | 459 | 463 | output_tokens: integer(row, "output_tokens", ["SUM(tokens.output)", "SUM(tokens_output)"]), | 460 | 464 | reasoning_tokens: integer(row, "reasoning_tokens", ["SUM(tokens.reasoning)", "SUM(tokens_reasoning)"]), | |
Collapse file Copy file name to clipboardExpand all lines: sst-env.d.ts +52-8Lines changed: 52 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,14 +26,6 @@ declare module "sst" { | 26 | 26 | "AuthApi": import("@cloudflare/workers-types").Service | 27 | 27 | "AuthStorage": import("@cloudflare/workers-types").KVNamespace | 28 | 28 | "Bucket": import("@cloudflare/workers-types").R2Bucket | 29 | | - "CLOUDFLARE_API_TOKEN": { | 30 | | - "type": "sst.sst.Secret" | 31 | | - "value": string | 32 | | - } | 33 | | - "CLOUDFLARE_DEFAULT_ACCOUNT_ID": { | 34 | | - "type": "sst.sst.Secret" | 35 | | - "value": string | 36 | | - } | 37 | 29 | "Console": { | 38 | 30 | "type": "sst.cloudflare.SolidStart" | 39 | 31 | "url": string | @@ -99,6 +91,37 @@ declare module "sst" { | 99 | 91 | "type": "random.index/randomPassword.RandomPassword" | 100 | 92 | "value": string | 101 | 93 | } | | 94 | + "InferenceEvent": { | | 95 | + "catalog": string | | 96 | + "database": string | | 97 | + "region": string | | 98 | + "table": string | | 99 | + "tableBucket": string | | 100 | + "type": "sst.sst.Linkable" | | 101 | + "workgroup": string | | 102 | + } | | 103 | + "LakeIngest": { | | 104 | + "secret": string | | 105 | + "type": "sst.sst.Linkable" | | 106 | + "url": string | | 107 | + } | | 108 | + "LakeIngestConfig": { | | 109 | + "secret": string | | 110 | + "streamName": string | | 111 | + "type": "sst.sst.Linkable" | | 112 | + } | | 113 | + "LakeIngestSecret": { | | 114 | + "type": "random.index/randomPassword.RandomPassword" | | 115 | + "value": string | | 116 | + } | | 117 | + "LakeIngestService": { | | 118 | + "service": string | | 119 | + "type": "sst.aws.Service" | | 120 | + "url": string | | 121 | + } | | 122 | + "LakeVpc": { | | 123 | + "type": "sst.aws.Vpc" | | 124 | + } | 102 | 125 | "LogProcessor": import("@cloudflare/workers-types").Service | 103 | 126 | "R2AccessKey": { | 104 | 127 | "type": "sst.sst.Secret" | @@ -133,6 +156,27 @@ declare module "sst" { | 133 | 156 | "value": string | 134 | 157 | } | 135 | 158 | "Stat": import("@cloudflare/workers-types").Service | | 159 | + "Stats": { | | 160 | + "type": "sst.cloudflare.SolidStart" | | 161 | + "url": string | | 162 | + } | | 163 | + "StatsDatabase": { | | 164 | + "database": string | | 165 | + "host": string | | 166 | + "password": string | | 167 | + "port": number | | 168 | + "type": "sst.sst.Linkable" | | 169 | + "url": string | | 170 | + "username": string | | 171 | + } | | 172 | + "StatsSyncConfig": { | | 173 | + "dataset": string | | 174 | + "type": "sst.sst.Linkable" | | 175 | + } | | 176 | + "StatsSyncService": { | | 177 | + "service": string | | 178 | + "type": "sst.aws.Service" | | 179 | + } | 136 | 180 | "Teams": { | 137 | 181 | "type": "sst.cloudflare.SolidStart" | 138 | 182 | "url": string | |
|