Open-source

cloudflare-worker-rollbar — a Rollbar client built for Workers

2 min read Isaac Rowntree

@triptech/cloudflare-worker-rollbar is a Triptech Travel open-source project — authored and released by Isaac Rowntree in his Triptech engineering capacity, and cross-posted here on the Zack Design blog. It is a lightweight, zero-dependency Rollbar client built specifically for the Cloudflare Workers runtime. It exists because Rollbar’s official JavaScript SDK is built for Node and the browser, and neither of those assumptions survives contact with Workers’ isolated V8 environment.

Why a custom client

Rollbar’s official SDK reaches for things that simply do not exist on Workers:

  • A mutable global process object.
  • Node streams and Buffer for payload serialisation.
  • Long-lived background queues that drain on their own schedule.
  • XMLHttpRequest-style timing assumptions from the browser build.

You can wedge the official package in with polyfills and nodejs_compat, but the result is a bigger bundle, slower cold starts, and an ongoing compatibility risk every time the SDK ships an update. Writing a tiny, fetch-only implementation is the cleaner path.

What the package gives you

  • Zero dependencies. Every HTTP call is a raw fetch() — nothing ships with the package except TypeScript types.
  • Full TypeScript. Comprehensive types for every API, so env.ROLLBAR_TOKEN and the request payloads are all type-checked at build time.
  • waitUntil()-friendly. Error reports fire on ctx.waitUntil(...) so they never block the response.
  • A handler wrapper. rollbar.wrap(handler) catches everything the inner handler throws and reports it with request context already attached.
  • Sensitive-data scrubbing. Passwords, tokens, and configurable header names are redacted before the payload leaves the Worker.

Minimum setup

import { Rollbar } from '@triptech/cloudflare-worker-rollbar'

export interface Env {
  ROLLBAR_TOKEN: string
}

export default {
  fetch: (request: Request, env: Env, ctx: ExecutionContext) => {
    const rollbar = new Rollbar({
      accessToken: env.ROLLBAR_TOKEN,
      environment: 'production',
      codeVersion: 'abc123',
    })

    return rollbar.wrap(async (req, env, ctx) => {
      const data = await processRequest(req)
      return Response.json(data)
    })(request, env, ctx)
  },
}

That is the whole integration for an entire Worker — every throw inside the wrapped handler is reported with the request URL, method, headers, and a sanitised body.

Why it matters

Cloudflare Workers run Triptech’s production APIs at the edge — which means the observability story cannot rely on tools built for long-running Node processes. A small, carefully-scoped client avoids the temptation to “just polyfill it” and instead leans on the runtime primitives (fetch, waitUntil, ExecutionContext) that Cloudflare already gives you. Install it from npm or read the source on GitHub.