Newbie Paintball Master

    use-datadog

    1.0.7 • Public • Published

    use-datadog

    🐶 use datadog from a hook Build Status Coverage Status GitHub tag (latest by date)

    Usage

    npm i use-datadog
    import { useDatadog } from 'use-datadog';
    import { StatusType } from '@datadog/browser-logs';
    
    export function DogText ({ context }) {
        // destructure any method from `datadogLogs`
        const {logger} = useDatadog({
            // accepts any arguments that `datadogLogs` does
            clientToken: '<CLIENT_TOKEN>',
            site: '<DATADOG_SITE>',
        });
        logger.log('Log a result to datadog', context, StatusType.info);
        
        return <div>🐕</div>
    }
    const DogText = () => {
        // destructure any method from `datadogRum`
        const {addRumGlobalContext} = useDatadogRum({
            // accepts any arguments that `datadogRum` does
            clientToken: '<CLIENT_TOKEN>',
            applicationId: '<APP_ID>',
        });
        
        addRumGlobalContext('Poodle', { poodle: '🐩' });
        
        return <div>🐕</div>
    }

    Gotchas

    Note that the silentMultipleInit argument is automatically passed during initialization, but can be overwritten.

    Motivation

    In some contexts, a server-side rendered React application will not have access to the window object, which causes a silent failure in Datadog. This library seeks to remedy that by placing it in a useEffect wrapper. The resulting destructuring from the hook is nice too.

    Install

    npm i use-datadog

    DownloadsWeekly Downloads

    26

    Version

    1.0.7

    License

    MIT

    Unpacked Size

    15.7 kB

    Total Files

    11

    Last publish

    Collaborators

    • emmaramirez