Skeletal tail worker
This commit is contained in:
@@ -33,3 +33,8 @@ To import an existing worker from the Cloudflare dashboard, use
|
||||
```sh
|
||||
npm create cloudflare@2 existing-worker-name -- --type pre-existing --existing-script existing-worker-name
|
||||
```
|
||||
|
||||
## Logging
|
||||
|
||||
Attach our tail worker (called `tail`) to your worker. Then, any `console.log`
|
||||
statements called by your worker will be forwarded to Grafana.
|
||||
|
||||
10
infra/workers/tail/package.json
Normal file
10
infra/workers/tail/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "tail",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20240614.0",
|
||||
"typescript": "^5",
|
||||
"wrangler": "^3"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22"
|
||||
}
|
||||
19
infra/workers/tail/src/index.ts
Normal file
19
infra/workers/tail/src/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* A tail worker that forwards all `console.log`s to Loki.
|
||||
*
|
||||
* https://developers.cloudflare.com/workers/observability/logging/tail-workers/
|
||||
*/
|
||||
export default {
|
||||
async tail(events: TailItems[], env: Env) {
|
||||
// If the tail worker itself throws an exception (it shouldn't, unless
|
||||
// Loki is down), we don't catch it so that it counts as an "error" in
|
||||
// the worker stats.
|
||||
return handleTail(events, env.LOKI_URL);
|
||||
},
|
||||
} satisfies ExportedHander<Env>;
|
||||
|
||||
interface Env {
|
||||
LOKI_URL: string;
|
||||
}
|
||||
|
||||
const handleTail = (events: TailItems[], lokiURL: string) => {};
|
||||
1
infra/workers/tail/tsconfig.json
Normal file
1
infra/workers/tail/tsconfig.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tsconfig.base.json", "include": ["src"] }
|
||||
7
infra/workers/tail/wrangler.toml
Normal file
7
infra/workers/tail/wrangler.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
name = "tail"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2024-06-14"
|
||||
|
||||
[vars]
|
||||
# Added as a secret via the Cloudflare dashboard
|
||||
# LOKI_URL = "https://discord.com/api/webhooks/{webhook.id}/{webhook.token}"
|
||||
Reference in New Issue
Block a user