<!-- Cloudflare platforms — Heystack docs. Rendered: https://heystack.dev/docs/cloudflare-platforms · Index: https://heystack.dev/llms.txt -->
# Cloudflare platforms

Cloudflare products that sit next to or around Workers: Containers, Pages Functions and Workers for Platforms. Each needs a slightly different setup. See [Cloudflare Workers](https://heystack.dev/docs/cloudflare-workers) for the Worker basics and the [coverage table](https://heystack.dev/docs/cloudflare-workers#signal-coverage).

## Containers

A Container runs your code in a separate process, so it needs its own telemetry.

- The Worker in front of the Container stays on `@heystack/otel/workers`, exactly as described in [Cloudflare Workers](https://heystack.dev/docs/cloudflare-workers).
- Inside the Container, use the Node SDK (`@heystack/otel/node`) with its own `service.name`, so the Worker and the Container appear as separate services in Heystack:

```ts
import { initHeystack } from "@heystack/otel/node";

initHeystack({ apiKey: process.env.HEYSTACK_API_KEY!, service: "my-app-container" });
```

Pass the ingest key to the Container as an environment variable from a secret. The Node SDK is correct here because the Container runs a normal Node process; do not use it in the Worker. To connect the two, forward the `traceparent` header from the Worker to the Container request; the Container's spans then continue the same trace.

Arbitrary internals of the Container are not traced automatically beyond what the Node SDK instruments.

## Pages Functions

Pages Functions are supported in **direct mode only**. Native Cloudflare export is not recorded for Pages Functions, so the coverage table lists them as "Direct mode only". Use:

```ts
import { instrument } from "@heystack/otel/workers";

export const onRequest: PagesFunction<Env> = (context) =>
  instrument(
    { fetch: () => context.next() },
    { service: "my-pages-site", nativeTracing: "direct" },
  ).fetch(context.request, context.env, context);
```

Store the ingest key as a Pages secret named `HEYSTACK_API_KEY`. Enable the `nodejs_compat` compatibility flag so parent and child spans stay linked across `await`. If this changes (a verified native export for Pages), the coverage table above is where it will show first.

## Workers for Platforms

Workers for Platforms runs your customers' Workers (user workers) in a dispatch namespace.

- **Telemetry from user workers.** Give each user worker its own Heystack app, with the app's `service_name` set to the user worker's script name. That keeps one customer's traces and metrics separate from another's. Native export is configured on each user worker; the dispatch Worker in front of them uses `@heystack/otel/workers` like any other Worker.
- **Analytics connector.** When you connect a Cloudflare account, you can set a `dispatch_namespace` on the connector so Heystack reads analytics for the Workers in that namespace. Set it in the **Dispatch namespace** field under **Settings › Cloudflare**, or through the API with `PUT /api/apps/:id/cloudflare-connector` and `dispatch_namespace` (1 to 63 characters of letters, digits, `_` and `-`). Saving the connection without it clears it. See the [API reference](https://heystack.dev/docs/api).

With a dispatch namespace set, the connector imports Workers invocations for the user workers in that namespace, per script. The account-level datasets (Queues, Durable Objects, D1, KV, R2, Workflows, Hyperdrive, Workers AI and AI Gateway) are pulled once per account, not per namespace; see [Worker metrics](https://heystack.dev/docs/cloudflare-workers#worker-metrics) for the full list and where each one shows in the console.
