Skip to content

DataDog Browser Logs Transport

NPM Version

@datadog/browser-logs is Datadog's official browser-side logging library.

Transport Source

Important Notes

  • Only works in browser environments (not in Node.js)
  • You will not get any console output since this sends directly to DataDog. Use the onDebug option to log out messages.

Installation

Install the required packages:

sh
npm i loglayer @loglayer/transport-datadog-browser-logs @datadog/browser-logs
sh
pnpm add loglayer @loglayer/transport-datadog-browser-logs @datadog/browser-logs
sh
yarn add loglayer @loglayer/transport-datadog-browser-logs @datadog/browser-logs

Setup

typescript
import { datadogLogs } from '@datadog/browser-logs'
import { LogLayer } from 'loglayer'
import { DatadogBrowserLogsTransport } from "@loglayer/transport-datadog-browser-logs"

// Initialize Datadog
datadogLogs.init({
  clientToken: '<CLIENT_TOKEN>',
  site: '<DATADOG_SITE>',
  forwardErrorsToLogs: true,
  sampleRate: 100
})

// Basic setup
const log = new LogLayer({
  transport: new DatadogBrowserLogsTransport({
    id: "datadog",
    logger: datadogLogs
  })
})

// Or with a custom logger instance
const logger = datadogLogs.createLogger('my-logger')
const log = new LogLayer({
  transport: new DatadogBrowserLogsTransport({
    id: "datadog",
    logger
  })
})

Log Level Mapping

LogLayerDatadog
tracedebug
debugdebug
infoinfo
warnwarn
errorerror
fatalerror