Skip to content

Commit f416f52

Browse files
committed
Reapply "feat(stats): add user ids to inference metrics"
This reverts commit e0ff4fd.
1 parent e0ff4fd commit f416f52

6 files changed

Lines changed: 62 additions & 10 deletions

File tree

infra/stats.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const inferenceEventTable = new aws.s3tables.Table(
5656
{ name: "error_cause2", type: "string", required: false },
5757
{ name: "api_key", type: "string", required: false },
5858
{ name: "workspace", type: "string", required: false },
59+
{ name: "user_id", type: "string", required: false },
5960
{ name: "is_subscription", type: "boolean", required: false },
6061
{ name: "subscription", type: "string", required: false },
6162
{ name: "response_length", type: "long", required: false },

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ export async function handler(
697697
logger.metric({
698698
api_key: data.apiKey,
699699
workspace: data.workspaceID,
700+
user_id: data.user.id,
700701
...(() => {
701702
if (data.billing.subscription)
702703
return {

packages/console/function/src/log-processor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function toLakeEvent(time: string, data: Record<string, unknown>) {
132132
error_cause2: string(data, "error.cause2"),
133133
api_key: string(data, "api_key"),
134134
workspace: string(data, "workspace"),
135+
user_id: string(data, "user_id"),
135136
is_subscription: boolean(data, "isSubscription"), // removed
136137
subscription: string(data, "subscription"),
137138
response_length: integer(data, "response_length"),

packages/stats/core/src/domain/inference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ WITH normalized AS (
7575
session,
7676
COALESCE(NULLIF(workspace, ''), '') AS workspace,
7777
COALESCE(NULLIF(api_key, ''), '') AS api_key,
78+
COALESCE(NULLIF(user_id, ''), '') AS user_id,
7879
status,
7980
duration AS duration_ms,
8081
time_to_first_byte AS ttfb_ms,
@@ -116,7 +117,7 @@ WITH normalized AS (
116117
country,
117118
continent,
118119
session,
119-
COALESCE(NULLIF(workspace, ''), NULLIF(api_key, '')) AS user_key,
120+
COALESCE(NULLIF(user_id, ''), NULLIF(workspace, ''), NULLIF(api_key, '')) AS user_key,
120121
status,
121122
duration_ms,
122123
ttfb_ms,

packages/stats/core/src/honeycomb-backfill.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ function baseAggregate(row: RawRow, grain: Grain, opts: ImportOptions): StatBase
454454
tier: tier(row),
455455
sessions: integer(row, "sessions", ["COUNT_DISTINCT(session)"]),
456456
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+
]),
458462
input_tokens: integer(row, "input_tokens", ["SUM(tokens.input)", "SUM(tokens_input)"]),
459463
output_tokens: integer(row, "output_tokens", ["SUM(tokens.output)", "SUM(tokens_output)"]),
460464
reasoning_tokens: integer(row, "reasoning_tokens", ["SUM(tokens.reasoning)", "SUM(tokens_reasoning)"]),

sst-env.d.ts

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ declare module "sst" {
2626
"AuthApi": import("@cloudflare/workers-types").Service
2727
"AuthStorage": import("@cloudflare/workers-types").KVNamespace
2828
"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-
}
3729
"Console": {
3830
"type": "sst.cloudflare.SolidStart"
3931
"url": string
@@ -99,6 +91,37 @@ declare module "sst" {
9991
"type": "random.index/randomPassword.RandomPassword"
10092
"value": string
10193
}
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+
}
102125
"LogProcessor": import("@cloudflare/workers-types").Service
103126
"R2AccessKey": {
104127
"type": "sst.sst.Secret"
@@ -133,6 +156,27 @@ declare module "sst" {
133156
"value": string
134157
}
135158
"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+
}
136180
"Teams": {
137181
"type": "sst.cloudflare.SolidStart"
138182
"url": string

0 commit comments

Comments
 (0)