Skip to content
You are reading the v2 docs, currently in beta.V1 docs
oRPC
Esc
navigateopen⌘Jpreview
On this page

Cloudflare Workers Traces Integration

Record oRPC procedure, middleware, and stream spans in Cloudflare Workers Traces through the Workers custom spans API, with no OpenTelemetry SDK.

Installation

npm install @orpc/cloudflare@beta
pnpm add @orpc/cloudflare@beta
yarn add @orpc/cloudflare@beta
bun add @orpc/cloudflare@beta

Setup

Enable traces in your Wrangler configuration, then register CloudflareTracer once at module scope. oRPC then records the same spans as the OpenTelemetry integration, nested under the spans Workers create automatically.

{
  "observability": {
    "traces": {
      "enabled": true
    }
  }
}
import { experimental_CloudflareTracer as CloudflareTracer } from '@orpc/cloudflare'

new CloudflareTracer().enable()

Middleware Span

oRPC creates a span for each middleware execution. Use tracing.getActiveSpan() to add attributes to it:

import { tracing } from 'cloudflare:workers'

export const someMiddleware = os.middleware(async (ctx, next) => {
  tracing.getActiveSpan()?.setAttribute('someAttribute', 'someValue')

  return next()
})

Object.defineProperty(someMiddleware, 'name', {
  value: 'someName',
})

Limitations

Workers Traces still lack some APIs oRPC relies on, so:

  • Request spans are not renamed to the procedure path. The path is still recorded in the rpc.method attribute.
  • Streamed inputs and outputs record no yielded and enqueued events.
  • Trace context propagation is not configurable by oRPC.

Last updated on September 8, 2026

Was this page helpful?