先日(ついに) Cloudflare Workers に公式のエラートラッキングツールが来たので導入したい。
wrangler / cf のどちらからでも使える。
[observability.issues]
enabled = true
import { bindings, defineConfig, triggers } from 'cf/config';
export default defineConfig({
worker: {
observability: {
issues: {
enabled: true,
},
},
},
});
設定をしてデプロイすれば Web 上の Dashboard から使うことができる。
新しくなった CLI である cf では issues がサポートされていて、 CLI 経由でアクセスすることができる。
$ cf o11y issues summary --service backend
{
"lastIssue": 1792801050441,
"activeIssues": 6,
"activeOccurrences": 301,
"resolvedIssues": 0
}
$ cf o11y issues list --service backend
[
{
"id": "xxxxxxxx",
"service": "backend",
"fingerprint": "xxxxxxxxxx",
"title": "D1_ERROR: Network connection lost. · at D1DatabaseSessionAlwaysPrimary._sendOrThrow (cloudflare-internal:d1-api)",
"type": "exception",
"status": "active",
"statusUpdated": 1790895691282,
"count": 4,
"firstObserved": 1790895671634,
"lastObserved": 1792479050223,
"created": 1790895691282,
"updated": 1792479067779,
"activity": []
},
....
}
$ cf o11y issues occurrences xxxxxxxx --per-page 5
[
{
"id": "xxxxxxxx",
"timestamp": 1792479050223,
"error": {
"name": "Error",
"message": "D1_ERROR: Network connection lost.",
"mechanism": "exception",
"handled": false,
"stack": " at D1DatabaseSessionAlwaysPrimary._sendOrThrow (cloudflare-internal:d1-api:193:19)\n at async cloudflare-internal:d1-api:142:19\n at async insertEnrichment (index.js:71:572)\n at async Object.scheduled (index.js:79:261)",
"signature": "error|D1_ERROR: Network connection lost.|at D1DatabaseSessionAlwaysPrimary._sendOrThrow (cloudflare-internal:d1-api)"
},
"worker": {
"scriptName": "backend",
"executionModel": "stateless",
"scriptVersion": {
"id": "xxxxxxxx"
},
"scriptTags": []
},
"invocation": {
"id": "xxxxxxxx",
"type": "scheduled",
"traceId": "xxxxxxxx",
"spanId": "xxxxxxxx",
"cron": "*/10 * * * *",
"scheduledTime": 1792479042000
},
"trail": [
{
"type": "span",
"timestamp": 1792479050021,
"name": "fetch",
"spanId": "5da42485edd6d236",
"parentSpanId": "8145d02c35590c0f",
"ongoing": false
},
...
]
}
]
