Socket
Socket
Sign inDemoInstall

@datadog/browser-logs

Package Overview
Dependencies
4
Maintainers
1
Versions
247
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @datadog/browser-logs

Datadog browser logs library.


Version published
Weekly downloads
894K
increased by10.21%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v1.2.6

  • [RUMF-188] add traceId to fetch calls (#221)
  • 🐛 [RUMF-201] use timing.navigationStart to compute fake timings (#217)
  • ✅ fix e2e cbt tests on Edge (#222)

Readme

Source

logs

Datadog browser logs library.

Browser support

Setup

NPM

import { datadogLogs } from '@datadog/browser-logs'
datadogLogs.init({
  clientToken: 'XXX',
  datacenter: 'us',
  forwardErrorsToLogs: true,
  sampleRate: 100
})

Bundle

<script src = 'https://www.datadoghq-browser-agent.com/datadog-logs-us.js'>
<script>
    window.DD_LOGS.init({
        clientToken: 'XXX',
        datacenter: 'us',
        forwardErrorsToLogs: true,
        sampleRate: 100
    });
</script>

Public API

What we call Context is a map {key: value} that will be added to the message context.

  • Init must be called before other methods. Configurable options:

    • isCollectingError: when truthy, we'll automatically forward console.error logs, uncaught exceptions and network errors.
    • sampleRate: percentage of sessions to track. Only tracked sessions send logs.
    • datacenter: defined to which datacenter we'll send collected data ('us' | 'eu')
    init(configuration: {
        clientToken: string,
        datacenter?: string,
        isCollectingError?: boolean,
        sampleRate?: number
    })
    
  • Default logger

    logger.debug | info | warn | error (message: string, messageContext = Context)`
    logger.log (message: string, messageContext: Context, status? = 'debug' | 'info' | 'warn' | 'error')
    logger.setLevel (level?: 'debug' | 'info' | 'warn' | 'error')
    logger.setHandler (handler?: 'http' | 'console' | 'silent')
    logger.addContext (key: string, value: any)  # add one key-value to the logger context
    logger.setContext (context: Context)  # entirely replace the logger context
    
  • Custom loggers

    Custom loggers have the same API than the default logger

    createLogger (name: string, conf?: {
        level?: 'debug' | 'info' | 'warn' | 'error'
        handler?: 'http' | 'console' | 'silent'
        context?: Context
    })  # create a new logger
    getLogger (name: string)  # retrieve a previously created logger
    
  • Modify the global context for all loggers

    addLoggerGlobalContext (key: string, value: any)  # add one key-value to the default context
    setLoggerGlobalContext (context: Context)  # entirely replace the default context
    

FAQs

Last updated on 06 Jan 2020

Did you know?

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