Overview

Send logs to Datadog from the renderer processes of your Electron applications. The renderers use the Browser Logs SDK, and the Electron SDK in the main process uploads their logs.

Log collection is available only in renderer processes. It is not supported in the main process.

Setup

  1. Set up the Electron SDK in the main process by following the Electron setup instructions. Logs go through the main process only for renderers listed in allowedRendererHosts.

  2. Install @datadog/browser-logs in your renderer bundle:

    npm install @datadog/browser-logs
    
    yarn add @datadog/browser-logs
    
  3. Initialize the Browser Logs SDK in each renderer page that collects logs:

    import { datadogLogs } from '@datadog/browser-logs';
    
    datadogLogs.init({
      clientToken: '<CLIENT_TOKEN>',
      site: '<DATADOG_SITE>',
      service: '<SERVICE_NAME>',
      forwardErrorsToLogs: true,
    });
    

    The Browser Logs SDK detects the Electron SDK and sends its logs to the main process, which uploads them.

  4. Send logs with the Browser Logs SDK logger API. For loggers, levels, context, and other options, see Browser Log Collection.

Sampling

Set the sampling of renderer logs with logsSampleRate in the main process init call. It defaults to 100 and applies independently to each log:

await init({
  // ...
  logsSampleRate: 25, // forwards 25% of renderer logs
});

logsSampleRate is separate from the RUM sessionSampleRate. For renderers that send logs through the main process, the Browser Logs SDK ignores its own sessionSampleRate. Only logsSampleRate in the main process init call applies.

Further Reading