Extension logs and monitoring service
Based on DataDog and required Megatron clientHash as session ID.
Documentation: https://docs.datadoghq.com/logs/error_tracking/browser_and_mobile?tab=browser
Usage
Install package:
npm install @global-savings-group/extension-logs
Import log service and init in project:
import { ExtensionLogsService } from '@global-savings-group/extension-logs';
export const logsService = new ExtensionLogsService();
logsService.init({
clientToken: '{DataDog client token}',
env: 'production',
service: '{brand}:extension',
sessionId: '{Megatron clientHash}',
sessionSampleRate: 0.2,
threshold: 2000,
version: chrome.runtime.getManifest().version,
});
logsService.logConsoleErrors();
logsService.logUnhandledErrors();
logsService.debug({
message: 'Debug message',
data: { 'x': 'y' },
forceLog: true,
});
logsService.error({
message: 'Error message',
origin: 'custom',
stack: '{call stack as string}'
});
logsService.info({
message: 'Info message',
});
logsService.warn({
message: 'Warn message',
});
Enable session logging:
const sessionTrackAlarmName = 'session:track';
chrome.alarms.onAlarm.addListener(async (alarm) => {
if (alarm.name === sessionTrackAlarmName) {
logsService.ping();
}
});
chrome.alarms.create(sessionTrackAlarmName, { periodInMinutes: 10 });
Optionally, ping()
supports callback to add custom session data:
const getSessionData = () => ({
my_custom_session_data: 'some data',
another_key: 'more data',
});
logsService.ping(getSessionData);