Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
timestamp
);
},
gauge: (key: string, value: number, tags?: Tags, timestamp?: number) => {
log('gauge', key, value, tags, timestamp);
},
};
if (
!process.env.DATADOG_API_KEY ||
process.env.DATADOG_API_KEY === 'undefined'
) {
console.warn('No DATADOG_API_KEY provided, not tracking metrics.');
} else {
console.warn('Tracking metrics to DataDog.');
const metrics = require('datadog-metrics');
metrics.init({
defaultTags: [
`server:${process.env.SENTRY_NAME || 'unknown_server'}`,
`hostname: ${os.hostname() || 'unknown_instance_hostname'}`,
],
});
// This is necessary for express-hot-shots to work
const handleObjectTags = method => {
const original = metrics[method];
metrics[method] = (key, val, tags, timestamp) => {
return original.call(
metrics,
key,
val,
Array.isArray(tags) ? tags : stringify(tags),
timestamp
// "target": "https://shop.nordstrom.com",
// "mobile": false
// }
console.log(event)
// Flags for launching lighhouse
// ref: https://github.com/GoogleChrome/lighthouse/blob/HEAD/docs/configuration.md
const flags = {
disableDeviceEmulation: !event.mobile || true,
disableCpuThrottling: true,
disableNetworkThrottling: true
}
// Initialize datadog metrics collection
// ref: https://github.com/dbader/node-datadog-metrics#initialization
metrics.init({
host: 'host',
prefix: 'prefix.',
flushIntervalSeconds: 0,
apiKey: process.env.DATADOG_API_KEY,
appKey: process.env.DATADOG_APP_KEY,
defaultTags: [ `audit-target:${event.target}` ]
})
// Attach lighthouse to chrome and run an audit.
// ref: https://github.com/GoogleChrome/lighthouse/blob/master/docs/readme.md#using-programmatically
lighthouse(event.target, flags).then(function(results) {
// Increment the lighthouse counter
metrics.increment('lighthouse.invoke')
// Get total page load time metric
// push metric to datadog, ref: https://github.com/dbader/node-datadog-metrics#gauges