Star us on GitHub
Star
Menu

Logging in Cloudflare Workers

Learn how to set up highlight.io log ingestion in Cloudflare Workers.
1
Set up your frontend highlight.io integration.

First, make sure you've followed the frontend getting started guide.

2
Add the Cloudflare Worker Highlight integration.

All you need to start recording your console methods is call H.init. All Highlight data submission uses waitUntil to make sure that we have no impact on request handling performance.

import { H } from '@highlight-run/cloudflare' export default { async fetch(request: Request, env: {}, ctx: ExecutionContext) { H.init(request, { HIGHLIGHT_PROJECT_ID: '<YOUR_PROJECT_ID>' }, ctx) console.log('starting some work...') // ... }, }
Copy
3
Having TypeScript issues?

Using our library requires setting skipLibCheck because of one of our dependencies that references node types. At runtime, this does not cause issues because of dynamic imports and other polyfilling done to ensure the sdk works in the cloud flare worker runtime, but the types are still referenced.

{ /* ... your other options ... */ "compilerOptions": { /* required due to our sdk's usage of 'opentelemetry-sdk-workers' which works around node syntax in its dependencies by dynamically replacing the imported javascript bundle, but does not replace the '@types/node' dependency */ "skipLibCheck": true, "types": ["@cloudflare/workers-types"] }, }
Copy
4
Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.