How to Set Up Sentry in Next.js Using a Web Worker to Avoid Main Thread Impact? #14621
              
                Unanswered
              
          
                  
                    
                      TinaTahvildari
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 1 comment
-
| Hi, the Sentry SDK operates a lot on the basis of unserialized objects and therefore moving its logic into a web worker would be extremely hard. We currently do not support this. Have you actually found Sentry to block the main thread a lot? Cause in theory that shouldn't be the case (unless you use Session Replay without the compression worker feature). | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I’m working on a Next.js project where I want to set up Sentry for error tracking without impacting the Total Blocking Time (TBT) and main-thread performance. I’ve tried moving Sentry operations to a Web Worker, but I'm facing issues with Sentry events not being sent successfully.
Here’s the current setup:
public/sentryWorker.js): I imported Sentry and initialized it inside the worker to keep error capturing off the main thread.utils/sentryErrorHandler.js): I created a helper function to initialize the worker and send error data to it._app.js): I use global error and promise rejection handlers to capture errors across the app:Issue:
With this setup, the worker initializes, and the captureError function posts error messages to the worker, but no events are sent to Sentry. In the browser console, I see:
Sentry Web Worker initializedSending error to worker: [error message]But I don't see:
Error captured by Sentry in workerQuestion:
Thank you for any insights!
Beta Was this translation helpful? Give feedback.
All reactions