Skip to content

Cloudflare Workers

This guide configures logs. Replace YOUR_INGEST_KEY with your key on your server, never in a public example.

Enter the ingest key at the prompt. Keep service and environment in Worker vars. This example sends logs through the JSON adapter without a Node.js SDK.

Terminal window
npx wrangler secret put SQ_INGEST_KEY

waitUntil extends the request lifetime but is not a durable queue. Batch and use a durable queue with bounded retries for production. Avoid logging full URLs, authorization headers or personal data. To export platform logs instead, use the Cloudflare Logpush guide.

export default {
async fetch(request, env, ctx) {
ctx.waitUntil((async () => {
const response = await fetch("https://otlp.siteqwality.com/ingest", {
method: "POST",
headers: {"Content-Type": "application/json", "Authorization": "Bearer " + env.SQ_INGEST_KEY},
body: JSON.stringify({message: "Worker request", level: "info", service: "my-service", env: "production"})
});
if (!response.ok) throw new Error("Telemetry send failed with status " + response.status);
const result = await response.json();
if (result.rejected) throw new Error("Telemetry record rejected");
})());
return new Response("ok");
}
};

Make one request and inspect Logs. This does not automatically emit traces or metrics.

Terminal window
npx wrangler deploy

Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own. Nothing arriving? See what each status code means in failure handling.

Store the key in your platform secret mechanism, rotate it when exposed and remove test keys. Set a stable service.name and deployment.environment.name; avoid user IDs or unbounded values in metric labels. Prefer a persistent queue, bounded retries and exporter failure monitoring. Review redaction and processors before increasing traffic.