Skip to content

thirdPartyErrorFilterIntegration does not filter errors correctly #13835

Open
@gabrielecirulli

Description

@gabrielecirulli

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

8.32.0

Framework Version

Svelte 4.2.19

Link to Sentry event

https://2048-ip-holding-bv.sentry.io/issues/7739542/?project=4507408148856912&query=is%3Aunresolved%20issue.priority%3A%5Bhigh%2C%20medium%5D&referrer=issue-stream&statsPeriod=24h&stream_index=7

Reproduction Example/SDK Setup

No response

Steps to Reproduce

Reproduction is difficult because the issue stems from third-party ad code injected by the Ezoic Standalone SDK. The quality and error rate are unpredictable during user sessions, and we have no control over when the errors occur since the code is injected by third parties.

However, the problem should be visible through the provided event link in Sentry. If you look at the stack trace you'll notice that:

  • All except 1 of the stack frames are from a script /ym.0.js. This is a third-party script
  • The bottom stack frame is considered part of my node_modules: node_modules/.pnpm/@[email protected]/node_modules/@sentry/browser/build/npm/esm/helpers.js

My thirdPartyErrorFilterIntegration is set to "drop-error-if-exclusively-contains-third-party-frames" and it should be dropping these errors completely, but I believe it doesn't due to that one stack frame at the bottom.

This is thoroughly overwhelming my quotas: within 24 hours I've blown through the 50k errors in my account and I'm at a loss for how to continue. I've switched the mode to "drop-error-if-contains-third-party-frames" for now but this will kill my visibility on errors that are partially related to my code. It is ok as a temporary measure, but I need a long-term fix.


Here is a description of my setup:

  • Vite TypeScript app.
  • Using Svelte as a front-end framework
  • Svelte is initialized by importing the SDK into my bundled code and with the following config:
// This module is a convenience to ensure config across main and worker initializations
import { init, thirdPartyErrorFilterIntegration } from "@sentry/svelte";

declare global {
  const SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE: string;
}

init({
  dsn: "<snip>",
  maxBreadcrumbs: 200,
  integrations: [
    thirdPartyErrorFilterIntegration({
      filterKeys: [SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE],
      behaviour: "drop-error-if-contains-third-party-frames",
    }),
  ],
});

Then, the Sentry fingerprint is set up as follows in vite.config.ts (this snippet is heavily altered to avoid listing the other plugins):

import { sentryVitePlugin } from '@sentry/vite-plugin';
import { defineConfig, loadEnv } from 'vite';

const SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE =
  '<my_key_here>';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // ... Other unrelated plugins ...

    // Last plugin
    sentryVitePlugin({
      applicationKey:
        SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE,
      org: '<snip>',
      project: '<snip>',
    }),
  ],
  define: {
    SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE:
      JSON.stringify(
        SENTRY_FINGERPRINT_FOR_FILTERING_OUT_ERRORS_FROM_THIRD_PARTY_CODE
      ),
  },
});

Just to be sure, I also verified that my bundled code also contains the following bits of JS that should be identifying the modules. Notice how the app key is in there:

!(function () {
  try {
    var e =
        "undefined" != typeof window
          ? window
          : "undefined" != typeof global
            ? global
            : "undefined" != typeof self
              ? self
              : {},
      t = new e.Error().stack;
    t &&
      ((e._sentryDebugIds = e._sentryDebugIds || {}),
      (e._sentryDebugIds[t] = "<snip>"),
      (e._sentryDebugIdIdentifier = "<snip>"));
  } catch (i) {}
})();
var e =
  "undefined" != typeof window
    ? window
    : "undefined" != typeof global
      ? global
      : "undefined" != typeof self
        ? self
        : {};
(e._sentryModuleMetadata = e._sentryModuleMetadata || {}),
  (e._sentryModuleMetadata[new e.Error().stack] = Object.assign(
    {},
    e._sentryModuleMetadata[new e.Error().stack],
    { "_sentryBundlerPluginAppKey:<my_key_here>": !0 },
  ));

Dependencies:

  • svelte 4.2.19
  • @sentry/svelte 8.32.0
  • @sentry/vite-plugin 2.22.4
  • @sveltejs/vite-plugin-svelte 3.0.2
  • typescript 5.6.2
  • vite 5.4.8

...and a couple more

Expected Result

Errors such as the one linked, and many more in my dashboard, should have been discarded clientside, but somehow the snippet shown in the bottom stack frame, presumably causes them to be included (I say presumably because I don't know for sure this is the case but I presume so from reading the source of thirdPartyErrorFilterIntegration)

Here's the relevant snippet being included in the stack trace, from file node_modules/.pnpm/@[email protected]/node_modules/@sentry/browser/build/npm/esm/helpers.js

      // Attempt to invoke user-land function
      // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
      //       means the sentry.javascript SDK caught an error invoking your application code. This
      //       is expected behavior and NOT indicative of a bug with sentry.javascript.
      return fn.apply(this, wrappedArguments);

Here's a link to the file in question in this repo.

I don't know why this function is part of the stack trace.

Actual Result

Errors that should be filtered according to "drop-error-if-exclusively-contains-third-party-frames" are not filtered, overwhelming my quota. About 40k of the 50k errors I've received in the last 24 hours should have been dropped. It seems like a single stack frame is preventing them from being dropped.

You can review the following samples. Please note how the last stack frame always originates from some Sentry code and is presumably blocking the event from being dropped.

Metadata

Metadata

Assignees

Labels

BugPackage: browserIssues related to the Sentry Browser SDK

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions