Skip to content

Cloudflare Secrets Store and wrangler bindings, withSentry callback is syncronous #19897

@vv-z84

Description

@vv-z84

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

10.45.0

Framework Version

wrangler 4.75.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

export default Sentry.withSentry(
  (env: Env) => ({
    dsn: env.SENTRY_DSN.get(), // SENTRY_DSN is a SecretsStoreSecret, .get() returns a Promise<string>
    tracesSampleRate: 1.0,
    enableLogs: true,
    sendDefaultPii: true,
  }),
  {
    fetch: app.fetch
  } satisfies ExportedHandler<Env>,
);

Sentry.withSentry() doesn't handle promises. link

export function withSentry<
  Env = typeof env,
  QueueHandlerMessage = unknown,
  CfHostMetadata = unknown,
  T extends ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata> = ExportedHandler<
    Env,
    QueueHandlerMessage,
    CfHostMetadata
  >,
>(optionsCallback: (env: Env) => CloudflareOptions | undefined, handler: T): T {
  setAsyncLocalStorageAsyncContextStrategy();

  try {
    instrumentExportedHandlerFetch(handler, optionsCallback);
    instrumentHonoErrorHandler(handler);
    instrumentExportedHandlerScheduled(handler, optionsCallback);
    instrumentExportedHandlerEmail(handler, optionsCallback);
    instrumentExportedHandlerQueue(handler, optionsCallback);
    instrumentExportedHandlerTail(handler, optionsCallback);
    // This is here because Miniflare sometimes cannot get instrumented
  } catch {
    // Do not console anything here, we don't want to spam the console with errors
  }

  return handler;
}

Steps to Reproduce

Use Sentry in a Cloudflare Worker, in my case with Hono, where you need to use @sentry/cloudflare and export Sentry.withSentry() returned handler, but you need to use Cloudflare Secret Store bindings.

Expected Result

Get the SENTRY_DSN string value from the secret store.

Actual Result

Image

Additional Context

No response

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions