Browse Source

fix(replay): Handle invalid canvas id uniformly (#70047)

Change to always handle exceptions from `processEvent` in a uniform
manner. Will always use a metric if canvas id was not found, otherwise
capture exception to Sentry.

Fixes JAVASCRIPT-2SWZ
Fixes JAVASCRIPT-2SHT
Billy Vong 10 months ago
parent
commit
e355dc07fe
1 changed files with 13 additions and 19 deletions
  1. 13 19
      static/app/components/replays/canvasReplayerPlugin.tsx

+ 13 - 19
static/app/components/replays/canvasReplayerPlugin.tsx

@@ -208,9 +208,7 @@ export function CanvasReplayerPlugin(events: eventWithTime[]): ReplayPlugin {
           await processEvent(e, {replayer});
           handleQueue.delete(id);
         } catch (err) {
-          if (!(err instanceof InvalidCanvasNodeError)) {
-            Sentry.captureException(err);
-          }
+          handleProcessEventError(err);
         }
       });
     },
@@ -296,11 +294,7 @@ export function CanvasReplayerPlugin(events: eventWithTime[]): ReplayPlugin {
         return;
       }
       const [event, replayer] = queueItem;
-      try {
-        processEvent(event, {replayer});
-      } catch (err) {
-        Sentry.captureException(err);
-      }
+      processEvent(event, {replayer}).catch(handleProcessEventError);
     },
 
     /**
@@ -336,17 +330,17 @@ export function CanvasReplayerPlugin(events: eventWithTime[]): ReplayPlugin {
         return;
       }
 
-      try {
-        processEvent(e, {replayer});
-      } catch (err) {
-        if (err instanceof InvalidCanvasNodeError) {
-          // This can throw if mirror DOM is not ready
-          Sentry.metrics.increment('replay.canvas_player.no_canvas_id');
-          return;
-        }
-
-        Sentry.captureException(err);
-      }
+      processEvent(e, {replayer}).catch(handleProcessEventError);
     },
   };
 }
+
+function handleProcessEventError(err: unknown) {
+  if (err instanceof InvalidCanvasNodeError) {
+    // This can throw if mirror DOM is not ready
+    Sentry.metrics.increment('replay.canvas_player.no_canvas_id');
+    return;
+  }
+
+  Sentry.captureException(err);
+}