Skip to content

feat(cloudflare): Instrument Workflows #14158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/platforms/javascript/guides/cloudflare/features/workflows.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Cloudflare Workflows
description: "Learn how to add Sentry instrumentation for Cloudflare Workflows."
---

_(Available in version [9.32.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.32.0) and above)_

You can use the `instrumentWorkflowWithSentry` method to instrument [Cloudflare
Workflows](https://developers.cloudflare.com/workflows/).

Because workflows can be hibernated and loose all state, we use the workflows
`instanceId` as the Sentry `trace_id` to link all steps together. We also use
the last 4 characters of the `instanceId` for sampling to ensure all steps have
the same sampling decision. If you are starting your workflows with a custom
`instanceId`, ensure you use valid random UUIDs either with or without dashes.

```typescript
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
import * as Sentry from "@sentry/cloudflare";

class MyWorkflowBase extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
await step.do('fetch data', async () => {
//
});

await step.do('process data', async () => {
//
});
}
}

// Export your named class as defined in your wrangler config
export const MyWorkflow = Sentry.instrumentWorkflowWithSentry(
(env: Env) => ({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
}),
MyWorkflowBase
);
```
6 changes: 6 additions & 0 deletions docs/platforms/javascript/guides/cloudflare/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudf

See the [Cloudflare Durable Objects](features/durableobject/) guide for more information.

### Cloudflare Workflows

You can use the `instrumentWorkflowWithSentry` method to instrument [Cloudflare Workflows](https://developers.cloudflare.com/workflows/). This will need to be done alongside the worker setup.

See the [Cloudflare Workflows](features/workflows/) guide for more information.

## Add Readable Stack Traces to Errors

Depending on how you've set up your project, the stack traces in your Sentry errors probably don't look like your actual code.
Expand Down