默认启用生产日志和追踪可能记录敏感请求或错误信息
原文依据:5 处该 Skill 要求生产 Worker 启用日志和追踪,并提供记录请求路径及原始错误消息的结构化日志示例。路径可能包含用户或资源标识,异常消息也可能包含输入、内部服务信息或其他敏感数据;正文没有要求脱敏、访问限制或保留期限。
若代理照此修改处理敏感流量的 Worker,Cloudflare 日志系统及有权查看日志的人可能获得原本不应长期保存的请求或错误数据。全量日志采样还可能增加可观测性费用。
该要求属于正常的生产可观测性配置,并非秘密收集机制;但风险有实际依据:Skill 要求在生产部署前启用日志和追踪,并示例把请求路径和原始异常消息写入日志。如果路径含用户/资源标识,或异常消息回显输入、令牌及内部信息,这些内容会进入 Cloudflare 日志;所示指导未同时要求脱敏、限制访问或设置保留期。用户可要求作者明确敏感字段过滤、日志访问权限、采样和保留策略。
## Enable ObservabilityEnable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/) and [Traces](https://developers.cloudflare.com/workers/observability/traces/) when creating or preparing a Worker for production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).查看另外 4 个位置
Enable Workers Logs and Traces in Wrangler config before deploying to production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use `head_sampling_rate` to control volume and cost. Use structured JSON logging — `console.log(JSON.stringify({...}))` — so logs are searchable. Use `console.error` for errors (appears at error severity in the dashboard).**Check**: logs and traces are enabled in the target deployment environment, with neither disabled by an environment override. Check `observability.enabled`, `observability.logs.enabled`, and `observability.traces.enabled`, accounting for their defaults. Logging uses structured JSON, not string concatenation.```ts// Structured JSON — searchable and filterableconsole.log(JSON.stringify({ message: "incoming request", method: request.method, path: url.pathname }));// Error severityconsole.error(JSON.stringify({ message: "request failed", error: e instanceof Error ? e.message : String(e) }));```{ "observability": { "enabled": true, "logs": { "enabled": true, "head_sampling_rate": 1 }, "traces": { "enabled": true, "head_sampling_rate": 0.01 } }} return Response.json(result); } catch (error) { const message = error instanceof Error ? error.message : "Unknown error"; console.error(JSON.stringify({ message: "unhandled error", error: message, path: new URL(request.url).pathname })); return Response.json({ error: "Internal server error" }, { status: 500 }); }