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 for the Worker basics and the coverage table.
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. - Inside the Container, use the Node SDK (
@heystack/otel/node) with its ownservice.name, so the Worker and the Container appear as separate services in Heystack:
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:
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_nameset 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/workerslike any other Worker. - Analytics connector. When you connect a Cloudflare account, you can set a
dispatch_namespaceon 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 withPUT /api/apps/:id/cloudflare-connectoranddispatch_namespace(1 to 63 characters of letters, digits,_and-). Saving the connection without it clears it. See the API reference.
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 for the full list and where each one shows in the console.