Skip to content

Commit

Permalink
add basic metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Mengxin Liu <[email protected]>
  • Loading branch information
oilbeater committed Sep 9, 2024
1 parent 8c5e551 commit b3b6b10
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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}`)
})

Expand Down
6 changes: 4 additions & 2 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3b6b10

Please sign in to comment.