Dokumentation

Error Tracking Services

NoiseGate works with any error tracking service that supports error filtering callbacks. This guide provides comprehensive integration examples for popular platforms.

Quick Reference

ServiceFiltering HookReturn to Filter
SentrybeforeSendnull
DatadogbeforeSendfalse
RaygunonBeforeSendfalse
RollbarcheckIgnoretrue
BugsnagonErrorfalse
New RelicsetErrorHandlertrue
LogRocketManual checkN/A

Datadog

Datadog RUM captures browser errors and user interactions. Use the beforeSend callback to filter noise.

Client-Side (Browser RUM)

import { datadogRum } from "@datadog/browser-rum";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

datadogRum.init({
  applicationId: process.env.NEXT_PUBLIC_DATADOG_APPLICATION_ID!,
  clientToken: process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN!,
  site: "datadoghq.com",
  service: "my-app",
  env: process.env.NODE_ENV,
  sessionSampleRate: 10,
  sessionReplaySampleRate: 10,
  trackUserInteractions: true,
  trackResources: true,
  defaultPrivacyLevel: "mask",

  beforeSend: (event, context) => {
    if (event.type === "error") {
      // Filter NoiseGate-detected errors
      const originalError = (context as { error?: unknown })?.error;
      if (originalError instanceof Error && isNoise(originalError)) {
        return false;
      }
    }
    return true;
  },
});

Server-Side (dd-trace)

// instrumentation.ts (Next.js) or server entry point
import tracer from "dd-trace";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NOISEGATE_API_KEY! });

tracer.init({
  service: "my-app",
  env: process.env.NODE_ENV,
  version: process.env.GIT_COMMIT_SHA,
  runtimeMetrics: true,
  logInjection: true,
});

// Filter errors in span processing
tracer.use("http", {
  hooks: {
    request: (span, req, res) => {
      span?.setTag("error", false); // Clear error for filtered requests
    },
  },
});

Environment Variables

NEXT_PUBLIC_DATADOG_APPLICATION_ID=your-app-id
NEXT_PUBLIC_DATADOG_CLIENT_TOKEN=your-client-token
NEXT_PUBLIC_DATADOG_SITE=datadoghq.com
DD_API_KEY=your-server-api-key

New Relic

New Relic provides browser and server-side monitoring. Use the setErrorHandler method to filter noise.

Client-Side (Browser Agent)

import { BrowserAgent } from "@newrelic/browser-agent/loaders/browser-agent";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

const agent = new BrowserAgent({
  init: {
    distributed_tracing: { enabled: true },
    privacy: { cookies_enabled: true },
    ajax: { deny_list: ["bam.nr-data.net"] },
  },
  info: {
    beacon: "bam.nr-data.net",
    errorBeacon: "bam.nr-data.net",
    licenseKey: process.env.NEXT_PUBLIC_NEW_RELIC_LICENSE_KEY!,
    applicationID: process.env.NEXT_PUBLIC_NEW_RELIC_APPLICATION_ID!,
    sa: 1,
  },
  loader_config: {
    accountID: process.env.NEXT_PUBLIC_NEW_RELIC_ACCOUNT_ID!,
    trustKey: process.env.NEXT_PUBLIC_NEW_RELIC_TRUST_KEY!,
    agentID: process.env.NEXT_PUBLIC_NEW_RELIC_AGENT_ID!,
    licenseKey: process.env.NEXT_PUBLIC_NEW_RELIC_LICENSE_KEY!,
    applicationID: process.env.NEXT_PUBLIC_NEW_RELIC_APPLICATION_ID!,
  },
});

// Filter noise errors - return true to ignore
agent.setErrorHandler((err: unknown) => {
  if (err instanceof Error && isNoise(err)) {
    return true; // Ignore the error
  }
  return false; // Allow the error through
});

Server-Side (Node.js Agent)

// newrelic.js (must be at project root)
"use strict";

exports.config = {
  app_name: ["my-app"],
  license_key: process.env.NEW_RELIC_LICENSE_KEY,
  distributed_tracing: { enabled: true },
  logging: { level: "info" },

  // Exclude sensitive headers
  attributes: {
    exclude: [
      "request.headers.cookie",
      "request.headers.authorization",
    ],
  },

  error_collector: {
    enabled: true,
    ignore_status_codes: [404],
  },
};
// instrumentation.ts
import newrelic from "newrelic";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NOISEGATE_API_KEY! });

// Custom error handler
export function captureError(error: Error, customAttributes?: Record<string, unknown>) {
  if (isNoise(error)) {
    return; // Don't report noise
  }
  newrelic.noticeError(error, customAttributes);
}

Environment Variables

NEXT_PUBLIC_NEW_RELIC_ACCOUNT_ID=your-account-id
NEXT_PUBLIC_NEW_RELIC_APPLICATION_ID=your-app-id
NEXT_PUBLIC_NEW_RELIC_LICENSE_KEY=your-browser-license-key
NEXT_PUBLIC_NEW_RELIC_AGENT_ID=your-agent-id
NEXT_PUBLIC_NEW_RELIC_TRUST_KEY=your-trust-key
NEW_RELIC_LICENSE_KEY=your-server-license-key

Raygun

Raygun provides crash reporting with the onBeforeSend callback for filtering.

Client-Side (raygun4js)

import rg4js from "raygun4js";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

rg4js("apiKey", process.env.NEXT_PUBLIC_RAYGUN_API_KEY!);
rg4js("enableCrashReporting", true);
rg4js("setVersion", process.env.NEXT_PUBLIC_APP_VERSION || "1.0.0");

rg4js("options", {
  ignore3rdPartyErrors: true,
  captureUnhandledRejections: true,
});

// Filter noise errors - return false to drop
rg4js("onBeforeSend", (payload) => {
  const errorMessage = payload?.Details?.Error?.Message || "";
  const errorClassName = payload?.Details?.Error?.ClassName || "";

  if (errorMessage || errorClassName) {
    const syntheticError = new Error(errorMessage);
    syntheticError.name = errorClassName;

    if (isNoise(syntheticError)) {
      return false; // Drop the error
    }
  }

  return payload; // Send the error
});

Server-Side (raygun)

import raygun from "raygun";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NOISEGATE_API_KEY! });

const raygunClient = new raygun.Client().init({
  apiKey: process.env.RAYGUN_API_KEY!,
});

// Custom send function with filtering
export function captureError(error: Error, customData?: Record<string, unknown>) {
  if (isNoise(error)) {
    return; // Don't report noise
  }
  raygunClient.send(error, customData);
}

// Or use with Express middleware
export const raygunErrorHandler = raygun.expressHandler(raygunClient, {
  filters: ["password", "creditCard", "authorization"],
});

Environment Variables

NEXT_PUBLIC_RAYGUN_API_KEY=your-client-api-key
RAYGUN_API_KEY=your-server-api-key

Rollbar

Rollbar uses the checkIgnore callback. Return true to ignore errors.

Client-Side

import Rollbar from "rollbar";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

const rollbar = new Rollbar({
  accessToken: process.env.NEXT_PUBLIC_ROLLBAR_CLIENT_TOKEN!,
  environment: process.env.NODE_ENV,
  captureUncaught: true,
  captureUnhandledRejections: true,

  payload: {
    client: {
      javascript: {
        source_map_enabled: true,
        code_version: process.env.NEXT_PUBLIC_GIT_COMMIT_SHA,
      },
    },
  },

  // Return true to ignore the error
  checkIgnore: (_isUncaught, args, _item) => {
    const error = args[0];
    if (error instanceof Error && isNoise(error)) {
      return true; // Ignore
    }
    return false; // Report
  },
});

export default rollbar;

Server-Side

import Rollbar from "rollbar";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NOISEGATE_API_KEY! });

const rollbar = new Rollbar({
  accessToken: process.env.ROLLBAR_SERVER_TOKEN!,
  environment: process.env.NODE_ENV,
  codeVersion: process.env.GIT_COMMIT_SHA,

  scrubFields: ["password", "secret", "token", "authorization"],

  checkIgnore: (_isUncaught, args, _item) => {
    const error = args[0];
    if (error instanceof Error && isNoise(error)) {
      return true;
    }
    return false;
  },
});

export default rollbar;

Environment Variables

NEXT_PUBLIC_ROLLBAR_CLIENT_TOKEN=your-client-token
ROLLBAR_SERVER_TOKEN=your-server-token

Bugsnag

Bugsnag uses the onError callback. Return false to drop errors.

Client-Side

import Bugsnag from "@bugsnag/js";
import BugsnagPluginReact from "@bugsnag/plugin-react";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

Bugsnag.start({
  apiKey: process.env.NEXT_PUBLIC_BUGSNAG_API_KEY!,
  plugins: [new BugsnagPluginReact()],
  appVersion: process.env.NEXT_PUBLIC_APP_VERSION,
  releaseStage: process.env.NODE_ENV,
  enabledReleaseStages: ["production", "staging"],

  // Return false to drop the error
  onError: (event) => {
    const error = event.originalError;
    if (error instanceof Error && isNoise(error)) {
      return false; // Don't send
    }
    return true; // Send
  },
});

export default Bugsnag;

Server-Side

import Bugsnag from "@bugsnag/js";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NOISEGATE_API_KEY! });

Bugsnag.start({
  apiKey: process.env.BUGSNAG_API_KEY!,
  appVersion: process.env.APP_VERSION,
  releaseStage: process.env.NODE_ENV,
  enabledReleaseStages: ["production"],

  onError: (event) => {
    const error = event.originalError;
    if (error instanceof Error && isNoise(error)) {
      return false;
    }
    return true;
  },
});

export default Bugsnag;

Environment Variables

NEXT_PUBLIC_BUGSNAG_API_KEY=your-client-api-key
BUGSNAG_API_KEY=your-server-api-key

LogRocket

LogRocket is primarily a session replay tool. Filter errors before calling captureException.

Client-Side

import LogRocket from "logrocket";
import { initNoisegate, isNoise } from "@noisegate/sdk";

initNoisegate({ apiKey: process.env.NEXT_PUBLIC_NOISEGATE_API_KEY! });

LogRocket.init(process.env.NEXT_PUBLIC_LOGROCKET_APP_ID!, {
  release: process.env.NEXT_PUBLIC_APP_VERSION,
  dom: {
    textSanitizer: true,
    inputSanitizer: true,
  },
  network: {
    requestSanitizer: (request) => {
      if (request.headers?.Authorization) {
        request.headers.Authorization = "[REDACTED]";
      }
      return request;
    },
  },
});

// Helper function that applies NoiseGate filtering
export function captureLogRocketException(error: unknown): void {
  if (typeof window === "undefined") return;
  if (error instanceof Error && isNoise(error)) return;
  LogRocket.captureException(error as Error);
}

Integration with Sentry

Link LogRocket sessions to Sentry events for full context:

import LogRocket from "logrocket";
import * as Sentry from "@sentry/browser";

// After LogRocket.init()
LogRocket.getSessionURL((sessionURL) => {
  Sentry.setContext("logrocket", { sessionURL });
  Sentry.setTag("logrocket", sessionURL);
});

Environment Variables

NEXT_PUBLIC_LOGROCKET_APP_ID=your-app-id/your-project

Multi-Provider Setup

If you use multiple error tracking services, create a shared error capture function:

// lib/error-capture.ts
import { isNoise } from "@noisegate/sdk";
import * as Sentry from "@sentry/browser";
import Rollbar from "./rollbar";
import Bugsnag from "./bugsnag";

export function captureException(error: unknown, context?: Record<string, unknown>) {
  if (!(error instanceof Error)) return;
  if (isNoise(error)) return; // Single noise check for all providers

  // Report to all providers
  Sentry.captureException(error, { extra: context });
  Rollbar.error(error, context);
  Bugsnag.notify(error, (event) => {
    event.addMetadata("context", context || {});
  });
}

Next Steps