Socket
Socket
Sign inDemoInstall

@datadog/browser-logs

Package Overview
Dependencies
1
Maintainers
1
Versions
247
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-logs


Version published
Maintainers
1
Created

Package description

What is @datadog/browser-logs?

@datadog/browser-logs is an npm package that allows you to collect and monitor logs from your web applications in real-time. It integrates with Datadog's logging service to provide comprehensive insights into your application's performance, errors, and user interactions.

What are @datadog/browser-logs's main functionalities?

Basic Logging

This feature allows you to initialize the Datadog logging client and send basic log messages. The `init` method configures the client with your Datadog client token and other settings, while the `logger.info` method sends an informational log message.

const { datadogLogs } = require('@datadog/browser-logs');
datadogLogs.init({
  clientToken: 'YOUR_CLIENT_TOKEN',
  site: 'datadoghq.com',
  forwardErrorsToLogs: true,
  sampleRate: 100,
});
datadogLogs.logger.info('This is an info log');

Error Logging

This feature allows you to log errors that occur in your application. By catching exceptions and using the `logger.error` method, you can send detailed error logs to Datadog.

try {
  throw new Error('Something went wrong');
} catch (error) {
  datadogLogs.logger.error('An error occurred', { error });
}

Custom Attributes

This feature allows you to add custom attributes to your log messages. By passing an object with additional data to the logging methods, you can enrich your logs with context-specific information.

datadogLogs.logger.info('User action', { userId: '12345', action: 'click' });

Other packages similar to @datadog/browser-logs

Changelog

Source

v4.39.0

  • ♻️ [RUMF-1533] extract the Flush logic into a reusable component (#2144)
  • 🔥 Cleanup unnecessary flags (#2145)
  • [REPLAY] Add public function to get the link to current Replay (#2047)
  • 🐛 [RUMF-1544] Fix badly polyfilled URL (#2141)
  • Add an eslint rule to disallow the use of too generic utility file names (#2101)
  • ♻️ [RUMF-1517] split tools utils (#2128)
  • ♻️ [RUMF-1505] make sure we don't use Zone.js addEventListener (#2129)
  • 🏷️ improve addEventListener typings (#2127)
  • 🐛[RUMF-1517] Remove specHelper export in src code (#2126)
  • ♻️ rename performance utils (#2136)
  • ✨ Support snippet as a valid file url for stack trace computation (#2077)
  • ✅ Remove feature flag test warning noise

Readme

Source

Browser Log Collection

Send logs to Datadog from web browser pages with the browser logs SDK.

See the dedicated datadog documentation for more details.

Usage

After adding @datadog/browser-logs to your package.json file, initialize it with:

import { datadogLogs } from '@datadog/browser-logs'

datadogLogs.init({
  clientToken: '<DATADOG_CLIENT_TOKEN>',
  site: '<DATADOG_SITE>',
  forwardErrorsToLogs: true,
  sessionSampleRate: 100,
})

After the Datadog browser logs SDK is initialized, send custom log entries directly to Datadog:

import { datadogLogs } from '@datadog/browser-logs'

datadogLogs.logger.info('Button clicked', { name: 'buttonName', id: 123 })

try {
  ...
  throw new Error('Wrong behavior')
  ...
} catch (ex) {
  datadogLogs.logger.error('Error occurred', { team: 'myTeam' }, ex)
}

FAQs

Last updated on 13 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc