GeezerVison is showing github.com — zen: log error · gregoryg/opencode@8c56571
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/console.ts +5-9Lines changed: 5 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -166,14 +166,10 @@ const bucketNew = new sst.cloudflare.Bucket("ZenDataNew") | 166 | 166 | const AWS_SES_ACCESS_KEY_ID = new sst.Secret("AWS_SES_ACCESS_KEY_ID") | 167 | 167 | const AWS_SES_SECRET_ACCESS_KEY = new sst.Secret("AWS_SES_SECRET_ACCESS_KEY") | 168 | 168 |
| 169 | | -let logProcessor | 170 | | -if ($app.stage === "production" || $app.stage === "frank") { | 171 | | - const HONEYCOMB_API_KEY = new sst.Secret("HONEYCOMB_API_KEY") | 172 | | - logProcessor = new sst.cloudflare.Worker("LogProcessor", { | 173 | | - handler: "packages/console/function/src/log-processor.ts", | 174 | | - link: [HONEYCOMB_API_KEY], | 175 | | - }) | 176 | | -} | | 169 | +const logProcessor = new sst.cloudflare.Worker("LogProcessor", { | | 170 | + handler: "packages/console/function/src/log-processor.ts", | | 171 | + link: [new sst.Secret("HONEYCOMB_API_KEY")], | | 172 | +}) | 177 | 173 |
| 178 | 174 | new sst.cloudflare.x.SolidStart("Console", { | 179 | 175 | domain, | @@ -211,7 +207,7 @@ new sst.cloudflare.x.SolidStart("Console", { | 211 | 207 | transform: { | 212 | 208 | worker: { | 213 | 209 | placement: { mode: "smart" }, | 214 | | - tailConsumers: logProcessor ? [{ service: logProcessor.nodes.worker.scriptName }] : [], | | 210 | + tailConsumers: [{ service: logProcessor.nodes.worker.scriptName }], | 215 | 211 | }, | 216 | 212 | }, | 217 | 213 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/zen/util/handler.ts +19-13Lines changed: 19 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,20 +134,26 @@ export async function handler( | 134 | 134 | body: reqBody, | 135 | 135 | }) | 136 | 136 |
| 137 | | - // Try another provider => stop retrying if using fallback provider | 138 | | - if ( | 139 | | - res.status !== 200 && | 140 | | - // ie. openai 404 error: Item with id 'msg_0ead8b004a3b165d0069436a6b6834819896da85b63b196a3f' not found. | 141 | | - res.status !== 404 && | 142 | | - // ie. cannot change codex model providers mid-session | 143 | | - modelInfo.stickyProvider !== "strict" && | 144 | | - modelInfo.fallbackProvider && | 145 | | - providerInfo.id !== modelInfo.fallbackProvider | 146 | | - ) { | 147 | | - return retriableRequest({ | 148 | | - excludeProviders: [...retry.excludeProviders, providerInfo.id], | 149 | | - retryCount: retry.retryCount + 1, | | 137 | + if (res.status !== 200) { | | 138 | + logger.metric({ | | 139 | + "llm.error.code": res.status, | | 140 | + "llm.error.message": res.statusText, | 150 | 141 | }) | | 142 | + | | 143 | + // Try another provider => stop retrying if using fallback provider | | 144 | + if ( | | 145 | + // ie. openai 404 error: Item with id 'msg_0ead8b004a3b165d0069436a6b6834819896da85b63b196a3f' not found. | | 146 | + res.status !== 404 && | | 147 | + // ie. cannot change codex model providers mid-session | | 148 | + modelInfo.stickyProvider !== "strict" && | | 149 | + modelInfo.fallbackProvider && | | 150 | + providerInfo.id !== modelInfo.fallbackProvider | | 151 | + ) { | | 152 | + return retriableRequest({ | | 153 | + excludeProviders: [...retry.excludeProviders, providerInfo.id], | | 154 | + retryCount: retry.retryCount + 1, | | 155 | + }) | | 156 | + } | 151 | 157 | } | 152 | 158 |
| 153 | 159 | return { providerInfo, reqBody, res, startTimestamp } | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/function/src/log-processor.ts +12-6Lines changed: 12 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ export default { | 17 | 17 | ) | 18 | 18 | return | 19 | 19 |
| 20 | | - let metrics = { | | 20 | + let data = { | 21 | 21 | event_type: "completions", | 22 | 22 | "cf.continent": event.event.request.cf?.continent, | 23 | 23 | "cf.country": event.event.request.cf?.country, | @@ -31,22 +31,28 @@ export default { | 31 | 31 | status: event.event.response?.status ?? 0, | 32 | 32 | ip: event.event.request.headers["x-real-ip"], | 33 | 33 | } | | 34 | + const time = event.eventTimestamp ?? Date.now() | | 35 | + const events = [] | 34 | 36 | for (const log of event.logs) { | 35 | 37 | for (const message of log.message) { | 36 | 38 | if (!message.startsWith("_metric:")) continue | 37 | | - metrics = { ...metrics, ...JSON.parse(message.slice(8)) } | | 39 | + const json = JSON.parse(message.slice(8)) | | 40 | + data = { ...data, ...json } | | 41 | + if ("llm.error.code" in json) { | | 42 | + events.push({ time, data: { ...data } }) | | 43 | + } | 38 | 44 | } | 39 | 45 | } | 40 | | - console.log(JSON.stringify(metrics, null, 2)) | | 46 | + events.push({ time, data }) | | 47 | + console.log(JSON.stringify(data, null, 2)) | 41 | 48 |
| 42 | | - const ret = await fetch("https://api.honeycomb.io/1/events/zen", { | | 49 | + const ret = await fetch("https://api.honeycomb.io/1/batch/zen", { | 43 | 50 | method: "POST", | 44 | 51 | headers: { | 45 | 52 | "Content-Type": "application/json", | 46 | | - "X-Honeycomb-Event-Time": (event.eventTimestamp ?? Date.now()).toString(), | 47 | 53 | "X-Honeycomb-Team": Resource.HONEYCOMB_API_KEY.value, | 48 | 54 | }, | 49 | | - body: JSON.stringify(metrics), | | 55 | + body: JSON.stringify(events), | 50 | 56 | }) | 51 | 57 | console.log(ret.status) | 52 | 58 | console.log(await ret.text()) | |
|