Skip to main content
Here’s a quick guide to setting up Subtrace in your Cloudflare Workers. First, add @subtrace/cloudflare to your Worker package.json:
npm install @subtrace/cloudflare
Wrap your Worker’s fetch handler to use the Subtrace middleware:
src/index.js
import { subtrace } from "@subtrace/cloudflare";

export default {
  fetch: subtrace(async (request, env, ctx) => {
    return new Response("Hello World!");
  }),
};
Set a SUBTRACE_TOKEN environment variable in your Wrangler config file:
wrangler.jsonc
{
  "name": "my-worker",
  "main": "src/index.js",
  "compatibility_date": "2025-09-27",
  "vars": {
    // Go to https://subtrace.dev/dashboard to generate a token
    "SUBTRACE_TOKEN": "subt_..."
  }
}
Deploy your Cloudflare Worker:
npx wrangler deploy
And that’s it, you can now see all inbound and outbound HTTP requests in your Cloudflare Worker via the Subtrace dashboard!