Skip to content

webWorkerIntegration: breadcrumbs/tags/context set in worker thread get lost #18704

@medmunds

Description

@medmunds

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

10.32.1

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "@sentry/browser";
Sentry.init({
  dsn: import.meta.env.VITE_SENTRY_DSN,
  sendDefaultPii: false,
  integrations: [Sentry.browserTracingIntegration()],
});

// then in the module that creates workers...
const sentryWebWorkerIntegration = Sentry.webWorkerIntegration({ worker: [] });
Sentry.addIntegration(sentryWebWorkerIntegration);

// and when a worker is created...
const worker = new Worker(new URL("./worker.ts", import.meta.url), {...});
sentryWebWorkerIntegration.addWorker(worker);

// and in worker.ts...
import * as Sentry from "@sentry/browser";
Sentry.registerWebWorker({ self });

(I'd be happy to extract a minimal reproducible project if this is a bug that's likely to be fixed. You can see the actual code I'm running here: Sentry.init, webWorkerIntegration, addWorker, registerWebWorker, worker call to addBreadcrumb.)

Steps to Reproduce

  1. Create a project that uses web workers with the Sentry.webWorkerIntegration as documented, including calling Sentry.registerWebWorker in the worker
  2. In the worker, call Sentry.addBreadcrumb({...})
  3. Do something that captures an exception (in the worker or on the main thread)
  4. Examine the breadcrumbs in the recorded event for the data you added in step 2

Expected Result

The breadcrumb you added in step 2 should be present on the recorded event.

When using webWorkerIntegration, calls in the web worker thread to Sentry.addBreadcrumb (and setTags, setContext, addAttachment, etc.) should get forwarded to the main thread and attached to events there.

(Ideally, calling Sentry.registerWebWorker in the worker would also instrument console, fetch, and other worker-thread functions that Sentry normally hooks in the main thread.)

Actual Result

Calling Sentry.addBreadcrumb from a web worker appears to succeed, but the data is not attached to later captured events.

Additional Context

If enriching events from the worker isn't meant to be supported, perhaps Sentry could throw an error (or at least console.warn) when those APIs are called from the worker. (Presumably Sentry in the worker knows whether it is being used with registerWebWorker—so the APIs won't work—or separately with Sentry.init.)

The same probably goes for calling other APIs (like Sentry.addIntegration) that wouldn't be forwardable from the worker.

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

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions