diff --git a/docs/platforms/javascript/guides/cloudflare/features/workflows.mdx b/docs/platforms/javascript/guides/cloudflare/features/workflows.mdx new file mode 100644 index 0000000000000..f18a94c0e73fc --- /dev/null +++ b/docs/platforms/javascript/guides/cloudflare/features/workflows.mdx @@ -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 { + async run(event: WorkflowEvent, 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 +); +``` diff --git a/docs/platforms/javascript/guides/cloudflare/index.mdx b/docs/platforms/javascript/guides/cloudflare/index.mdx index 62599c36a25be..599e75a45077d 100644 --- a/docs/platforms/javascript/guides/cloudflare/index.mdx +++ b/docs/platforms/javascript/guides/cloudflare/index.mdx @@ -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.