CloudflareTracer
Records Effect spans in the trace Cloudflare Workers already collects for
each invocation, using the Workers custom spans API (tracing from
cloudflare:workers).
Effect spans become Cloudflare spans in the invocation's trace, and the spans
the runtime creates for fetch and binding calls nest under the Effect span
that made them. Cloudflare exports the trace to the OpenTelemetry destinations
configured for the account, so there is no endpoint, exporter, or flush to
configure. Enable traces in the Wrangler configuration
(observability.traces.enabled) for spans to be recorded.
Use Otlp.layer with FetchHttpClient instead to send a separate trace
from the Worker to your own OTLP endpoint.
Compatibility
The module imports tracing from cloudflare:workers, so it only loads in
the Workers runtime.
The tracer needs tracing.startSpan and tracing.withActiveSpan.
withActiveSpan is newer than Cloudflare's custom spans documentation: it
shipped in workerd 1.20261113.1, and @cloudflare/workers-types types it
from 5.20261107.1. Local development needs a Wrangler or Miniflare release
that bundles that workerd or later.
It also needs AsyncLocalStorage from process.getBuiltinModule, which
Workers provide with the nodejs_compat flag or a compatibility date of
2026-08-04 or later. Building the layer fails without it.
Limitations
- Cloudflare decides a span's parent from the async context, so an Effect
span created with
root: trueor with a parent from another tracer, such as an incomingtraceparent, still nests under the active Cloudflare span. - Cloudflare spans have no events, links, kind, or explicit timestamps. Span events are dropped, links and kind stay on the Effect span, and Cloudflare records the timing.
- A Cloudflare span belongs to the invocation that created it. An Effect span
that outlives its invocation, such as a
Layer.spanin a module-levelManagedRuntime, stops recording, and spans created under it in later invocations nest under that invocation's root span. - A Durable Object does not reject spans from its earlier requests, so there
spans created under such a span join the earlier request's trace, which has
already been sent, and are lost. Avoid long-lived parent spans, such as a
Layer.span, in a runtime shared across a Durable Object's requests. - Sampling is Effect's decision and recording is Cloudflare's. A span
Cloudflare does not record gets random ids, so an outgoing
traceparentcan be marked sampled in an invocation Cloudflare records nothing for.
Constructors
Creates an Effect Tracer that records spans with the Workers tracing
API.
Details
Unsampled Effect spans, such as spans below the MinimumTraceLevel, create
no Cloudflare span, and work inside them nests under the nearest sampled
Effect span. An interrupted span sets the effect.fiber.interrupted
attribute; any other failure records each error as an exception and sets an
error status.
Throws when AsyncLocalStorage is not available through
process.getBuiltinModule, as on Workers with a compatibility date before
2026-08-04 and without nodejs_compat.
See
- layer for providing the tracer as a layer
Signature
declare function make(): TracerLayers
A layer that installs a tracer recording Effect spans with the Workers
tracing API.
Details
The tracer is created each time the layer is built, which fails with a
defect when AsyncLocalStorage is unavailable (see make).
See
- make for creating the tracer directly
Signature
declare const layer: Layer.Layer<never>Example Tracing a Worker
import { CloudflareTracer } from "@effect/platform-cloudflare"import { Effect, ManagedRuntime } from "effect"
const runtime = ManagedRuntime.make(CloudflareTracer.layer)
export default { fetch: (request: Request) => runtime.runPromise( Effect.promise(() => fetch("https://example.com")).pipe( Effect.map((response) => new Response(response.body)), Effect.withSpan("proxy", { attributes: { "url.full": request.url } }) ) )}