Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore list to beforeSend callback #3271

Open
DonikaV opened this issue Jan 9, 2025 · 1 comment
Open

Add ignore list to beforeSend callback #3271

DonikaV opened this issue Jan 9, 2025 · 1 comment

Comments

@DonikaV
Copy link

DonikaV commented Jan 9, 2025

Hello guys, i am using both
import { datadogRum } from '@datadog/browser-rum';
import { datadogLogs } from '@datadog/browser-logs';
In my NextJS application and I see a lot of errors in the data dog console, I want to ignore some errors but it does not work.

This is what I have

const ignorePatterns = [
  /\/attributions\//, // Matches "/attributions/"
  /Load failed/i, // Matches "Load failed" (case-insensitive)
  /utm_source=/, // Matches "utm_source="
  /DatafileManager/, // Matches "DatafileManager"
  /_rsc/, // Matches "_rsc"
  /HierarchyRequestError/, // Matches "HierarchyRequestError"
  /Failed to fetch RSC payload for/i, // Matches "Failed to fetch RSC payload for" (case-insensitive)
  /\/attributions\/visits/, // Add this to match "attributions/visits"
];

inside the datadogLogs.init({}) I have added

 beforeSend: (event, context) => {
          const msg = event?.error?.message;
          const url = context?.http?.url; // Check if the event context contains a URL.
          console.log(url, msg);

          // Ignore based on the message or URL patterns.
          if (
            (msg && ignorePatterns.some((pattern) => pattern.test(msg))) ||
            (url && ignorePatterns.some((pattern) => pattern.test(url)))
          ) {
            return false;
          }

          // Optionally ignore aborted events.
          if (context && 'isAborted' in context && context.isAborted) {
            return false;
          }
        },

But my data dog still full of errors
Like

XHR error POST domain.com/attributions/events
Failed to load

How I can ignore this errors? Thanks

@amortemousque
Copy link
Collaborator

Hello @DonikaV,
FMU, the error you're trying to filter is an HTTP error. In this case to filter on the message "XHR error POST domain.com/attributions/events" you need to check event.message not event.error.massage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants