// "Use this skill whenever the user wants to improve or set up logging, tracing, metrics, and monitoring for Cloudflare Workers/Pages (e.g. Hono + TypeScript), including Wrangler tail, Workers Analytics, log structure, and integration with external tools like Sentry."
| name | cloudflare-observability-logging-monitoring |
| description | Use this skill whenever the user wants to improve or set up logging, tracing, metrics, and monitoring for Cloudflare Workers/Pages (e.g. Hono + TypeScript), including Wrangler tail, Workers Analytics, log structure, and integration with external tools like Sentry. |
You are a specialized assistant for making Cloudflare Workers/Pages apps observable:
Use this skill to:
Do not use this skill for:
cloudflare-worker-deployment, cloudflare-ci-cd-github-actionsIf CLAUDE.md has logging or observability standards (log format, correlation IDs, tools), follow them.
Trigger this skill when the user says things like:
Avoid when:
Workers use console.log, console.error, etc., with output viewable via:
wrangler dev (local)wrangler tail (live logs from deployed Worker)This skill should:
Example structured log in a Hono handler:
app.use("*", async (c, next) => {
const start = Date.now();
const requestId = crypto.randomUUID();
c.set("requestId", requestId);
await next();
const ms = Date.now() - start;
console.log(
JSON.stringify({
level: "info",
msg: "request_completed",
requestId,
method: c.req.method,
path: c.req.path,
status: c.res.status,
durationMs: ms,
}),
);
});
This skill will:
JSON.stringify for log messages where structured parsing is helpful.Combine hono-app-scaffold error middleware with structured logging.
Example error handler middleware:
// src/middlewares/error-handler.ts
import type { MiddlewareHandler } from "hono";
export const errorHandler: MiddlewareHandler = async (c, next) => {
try {
await next();
} catch (err) {
const requestId = c.get("requestId");
console.error(
JSON.stringify({
level: "error",
msg: "unhandled_error",
requestId,
error: String(err),
stack: err instanceof Error ? err.stack : undefined,
}),
);
return c.json(
{
message: "Internal Server Error",
requestId,
},
500,
);
}
};
This skill should:
requestId to aid debugging.This skill helps you leverage wrangler tail effectively:
To view logs from live Workers:
wrangler tail
With environment:
wrangler tail --env production
With log formatting or filters (where available) to focus on errors.
It should recommend typical debugging flow:
wrangler tail --env staging while hitting the endpoint.requestId from client error to find matching logs.Cloudflare provides Workers metrics (requests, errors, duration, CPU time).
This skill should:
Where appropriate, this skill can suggest exporting analytics via:
Workers don’t have built-in Prometheus-style counters, but this skill can suggest:
metric: fields).Example metric event in logs:
console.log(
JSON.stringify({
level: "info",
metric: "user_signup",
userId: newUser.id,
}),
);
Then logs can be filtered or exported to build dashboards.
For heavier metrics, this skill may suggest specialized observability tools rather than re-inventing a metrics store inside Workers.
For error tracking, this skill can sketch a Sentry integration pattern:
Pseudo-example:
import * as Sentry from "@sentry/browser"; // or Workers-compatible SDK
Sentry.init({
dsn: c.env.SENTRY_DSN,
tracesSampleRate: 0.1,
});
export const errorHandler: MiddlewareHandler = async (c, next) => {
try {
await next();
} catch (err) {
Sentry.captureException(err);
console.error("Unhandled error", err);
return c.json({ message: "Internal Server Error" }, 500);
}
};
This skill will:
c.env.SENTRY_DSN), not in source.For other providers (e.g., Logflare, Datadog, Honeycomb), use a similar pattern: emit HTTP events from Workers using fetch, observing rate limits and privacy constraints.
This skill must emphasize:
Example sanitization helper:
function safeLogRequest(c: any) {
const url = new URL(c.req.url);
console.log(
JSON.stringify({
level: "info",
msg: "request",
method: c.req.method,
path: url.pathname,
// DO NOT log full body or sensitive headers by default
}),
);
}
Use this in middleware when you need to log incoming request metadata.
When using hono-d1-integration and hono-r2-integration, this skill can:
Suggest logging queries at a high level (not full SQL with params in prod).
Log key metadata for R2 operations:
console.log(
JSON.stringify({
level: "info",
msg: "r2_put",
key,
size: fileSize,
requestId,
}),
);
For D1, log slow queries and errors with durationMs and table names.
Ensure logs remain high-level and don’t leak personal data.
This skill can connect with cloudflare-ci-cd-github-actions by:
Recommending that deploy workflows:
This helps correlate incidents with releases.
Example: log release info in Worker startup or CI:
console.log(
JSON.stringify({
level: "info",
msg: "worker_deployed",
commit: process.env.GIT_COMMIT ?? "unknown",
env: process.env.NODE_ENV,
}),
);
In Workers, use vars from wrangler.toml like GIT_COMMIT set during CI.
This skill can support:
So code can branch based on NODE_ENV or APP_ENV from c.env.
Example:
const isDev = c.env.NODE_ENV === "development";
if (isDev) {
console.log("Debug info:", { body: await c.req.text() });
}
Be extra careful not to ship verbose logging into production accidentally.
When something goes wrong in prod, this skill should guide the steps:
requestId if the client saw a structured error.wrangler tail --env production and filter by requestId.This gives a repeatable incident debugging recipe.
hono-app-scaffold:
app setup to add logging & error-handling.cloudflare-worker-deployment:
cloudflare-ci-cd-github-actions:
hono-d1-integration / hono-r2-integration:
For such tasks, rely on this skill to make your Cloudflare Workers observable, debuggable, and safe in production, without overwhelming you with noisy or sensitive logs.