Track Browser and Mobile Errors

Overview

Error Tracking processes errors collected from browser and mobile Datadog SDKs. Whenever an error containing a stack trace is collected, Error Tracking processes and groups it under an issue, which is a grouping of similar errors.

An essential attribute for log errors is the stack trace in a log’s error.stack. If you are sending stack traces to Datadog but they are not in error.stack, you can set up a generic log remapper to remap the stack trace to the correct attribute in Datadog.

Your crash reports appear in Error Tracking.

Setup

If you have not setup the Datadog Browser SDK yet, follow the in-app setup instructions or see the Browser Logs setup documentation.

  1. Download the latest version of the Logs Browser SDK.

  2. Configure your application’s version, env, and service when initializing the SDK.

  3. Initialize your SDK, for example, with NPM:

    import { datadogLogs } from '@datadog/browser-logs'
    
    datadogLogs.init({
      clientToken: '<DATADOG_CLIENT_TOKEN>',
      site: '<DATADOG_SITE>',
      service: '<MY_SERVICE>',
      env: '<MY_ENV>'
      forwardErrorsToLogs: true,
      sampleRate: 100,
    })
    
  4. You must add the following snippet near initialization to catch and submit all uncaught exceptions to Datadog:

    window.onerror = function (message, source, lineno, colno, error) {
        datadogLogs.logger.error(error?.message || '', {
            error: { stack: error?.stack },
        });
    };
    
  5. To log a caught exception yourself, you may optionally use:

    const e = new Error('an exception occurred');
    datadogLogs.logger.error(e.message, {'error': {'stack': e.stack}});
    

If you have not setup the Datadog Android SDK yet, follow the in-app setup instructions or see the Android Logs setup documentation.

  1. Download the latest version of the Datadog Android SDK for Logs.

  2. Configure your application’s version, env, and service when initializing the SDK.

  3. To log a caught exception yourself, you may optionally use:

    try {
      doSomething();
    } catch (IOException e) {
      logger.e("an exception occurred", e);
    }
    

If you have not setup the Datadog iOS SDK yet, follow the in-app setup instructions or see the iOS Logs setup documentation.

  1. Download the latest version of the Datadog iOS SDK for Logs.

  2. Configure your application’s version, env, and service when initializing the SDK.

  3. To log a caught exception yourself, you may optionally use:

    do {
      // ...
    } catch {
      logger.error("an exception occurred", error)
    }
    

Further Reading