Skip to content

Commit 2186381

Browse files
timfishbitsandfoxes
authored andcommitted
feat(cloudflare): Instrument Workflows (#14158)
1 parent cf7fd31 commit 2186381

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Cloudflare Workflows
3+
description: "Learn how to add Sentry instrumentation for Cloudflare Workflows."
4+
---
5+
6+
_(Available in version [9.32.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.32.0) and above)_
7+
8+
You can use the `instrumentWorkflowWithSentry` method to instrument [Cloudflare
9+
Workflows](https://developers.cloudflare.com/workflows/).
10+
11+
Because workflows can be hibernated and loose all state, we use the workflows
12+
`instanceId` as the Sentry `trace_id` to link all steps together. We also use
13+
the last 4 characters of the `instanceId` for sampling to ensure all steps have
14+
the same sampling decision. If you are starting your workflows with a custom
15+
`instanceId`, ensure you use valid random UUIDs either with or without dashes.
16+
17+
```typescript
18+
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
19+
import * as Sentry from "@sentry/cloudflare";
20+
21+
class MyWorkflowBase extends WorkflowEntrypoint<Env, Params> {
22+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
23+
await step.do('fetch data', async () => {
24+
//
25+
});
26+
27+
await step.do('process data', async () => {
28+
//
29+
});
30+
}
31+
}
32+
33+
// Export your named class as defined in your wrangler config
34+
export const MyWorkflow = Sentry.instrumentWorkflowWithSentry(
35+
(env: Env) => ({
36+
dsn: "___PUBLIC_DSN___",
37+
tracesSampleRate: 1.0,
38+
}),
39+
MyWorkflowBase
40+
);
41+
```

docs/platforms/javascript/guides/cloudflare/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudf
109109

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

112+
### Cloudflare Workflows
113+
114+
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.
115+
116+
See the [Cloudflare Workflows](features/workflows/) guide for more information.
117+
112118
## Add Readable Stack Traces to Errors
113119

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

0 commit comments

Comments
 (0)