From b3b6b10c1b9a8f84b0e68ebb23900ef621433577 Mon Sep 17 00:00:00 2001 From: Mengxin Liu Date: Mon, 9 Sep 2024 05:55:24 +0000 Subject: [PATCH] add basic metrics Signed-off-by: Mengxin Liu --- package.json | 2 +- src/index.ts | 13 +++++++++++-- worker-configuration.d.ts | 6 ++++-- wrangler.toml | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 173d1ea..a5a4ad8 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "deploy": "wrangler deploy", - "dev": "wrangler dev", + "dev": "wrangler dev --remote", "start": "wrangler dev", "test": "vitest", "cf-typegen": "wrangler types" diff --git a/src/index.ts b/src/index.ts index 3a115c6..a8665d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,23 @@ import { Hono, Context } from 'hono' -const app = new Hono() +type Bindings = { + MALACCA: AnalyticsEngineDataset, +} +const app = new Hono<{ Bindings: Bindings }>() const azureOpenAI = new Hono() -app.use(async (c, next) => { +app.use(async (c: Context, next) => { const start = Date.now() + console.log(c.env) await next() console.log(c.res.status) const end = Date.now() + c.env.MALACCA.writeDataPoint({ + 'blobs': ['azure-openai', 'chat'], + 'doubles': [end-start], + 'indexes': ['azure'], + }) console.log(`${end - start}`) }) diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 5b2319b..6aea009 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -1,4 +1,6 @@ -// Generated by Wrangler -// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen` +// Generated by Wrangler on Mon Sep 09 2024 03:00:20 GMT+0000 (Coordinated Universal Time) +// by running `wrangler types` + interface Env { + MALACCA: AnalyticsEngineDataset; } diff --git a/wrangler.toml b/wrangler.toml index 6315c0b..64ed8da 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -27,8 +27,8 @@ minify = true # Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function. # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets -# [[analytics_engine_datasets]] -# binding = "MY_DATASET" +[[analytics_engine_datasets]] +binding = "MALACCA" # Bind a headless browser instance running on Cloudflare's global network. # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering