use-datadog
v1.0.7
Published
use datadog from a react-hook
Downloads
9
Readme
use-datadog
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.