sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Add support for Cloudflare Workflows

Open AbhiPrasad opened this issue 7 months ago • 5 comments

We've got some requests for supporting Cloudflare Workflows, so tracking this here.

https://developers.cloudflare.com/workflows/

Please upvote this issue and leave a comment if you want to see support for this functionality. Thanks!

AbhiPrasad avatar Jun 02 '25 20:06 AbhiPrasad

Would love to see support for this! Workflows are an important part of our infrastructure and surfacing exceptions from them is really important.

andycrum avatar Jun 02 '25 20:06 andycrum

Yes! Would love to see Workflows supported.

torybriggs avatar Jun 02 '25 20:06 torybriggs

Alright thanks for the comments and reacts everyone! We're going to start working on this :)

AbhiPrasad avatar Jun 05 '25 16:06 AbhiPrasad

We need this FEATURE! Please set a high priority for this one!

amiranvarov avatar Jun 06 '25 08:06 amiranvarov

just my two cents for anyone who needs it NOW

you can still use Sentry using the browser version, you just have to call it at the beginning of your cron or workflow.

this is my implementation, a bit wordy but it works perfectly:

import * as SentryBrowser from '@sentry/browser';
import * as Sentry from '@sentry/cloudflare';

/**
 * Init reporting clients
 * @param root named parameters
 * @param root.sentryDSN the DSN for Sentry (if not in the http worker)
 */
export function initReportingClients({
  sentryDSN,
}: {
  sentryDSN: string | undefined;
}): void {
  // ...

  if (sentryDSN) {
    SentryBrowser.init({
      attachStacktrace: true,
      dsn: sentryDSN,
      integrations: [
        SentryBrowser.captureConsoleIntegration(),
        SentryBrowser.extraErrorDataIntegration({
          captureErrorCause: true,
          depth: 10,
        }),
      ],
      // @ts-expect-error This is defined by the bundler
      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- This is defined by the bundler
      release: GITHUB_SHA,
      sendDefaultPii: true,
      tracesSampleRate: 1,
    });
  }
}

/**
 * Capture an exception
 * @param root named parameters
 * @param root.error the error to capture
 * @param root.userID the user ID
 * @param root.additionalData additional data to send to the error tracking services
 */
export function captureException({
  additionalData,
  error,
  userID,
}: {
  additionalData?: { [key: string]: unknown };
  error: unknown;
  userID: string | undefined;
}): void {
  if (Sentry.isEnabled()) {
    Sentry.captureException(error, {
      extra: additionalData,
      user: userID
        ? {
            id: userID,
          }
        : undefined,
    });
  } else if (SentryBrowser.isEnabled()) {
    SentryBrowser.captureException(error, {
      extra: additionalData,
      user: userID
        ? {
            id: userID,
          }
        : undefined,
    });
  } else {
    logger.error('No error tracking service enabled!');
  }
}

Mael-Abgrall avatar Jun 06 '25 09:06 Mael-Abgrall

This will go out with the next release!

AbhiPrasad avatar Jun 23 '25 17:06 AbhiPrasad

Great! Any ETA on when the next release is expected?

amiranvarov avatar Jun 23 '25 18:06 amiranvarov

Wednesday afternoon at the latest

AbhiPrasad avatar Jun 23 '25 18:06 AbhiPrasad

A PR closing this issue has just been released 🚀

This issue was referenced by PR #16672, which was included in the 9.32.0 release.

github-actions[bot] avatar Jun 25 '25 10:06 github-actions[bot]

Docs are now live! https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/workflows/

AbhiPrasad avatar Jun 26 '25 15:06 AbhiPrasad

and here's what it looks like:

Image

AbhiPrasad avatar Jun 26 '25 15:06 AbhiPrasad