/collect? API); for example:const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',beforeReport(log) {// Listen on the reported error belowconsole.log(log); // {level: "4", msg: "An error occurred."}return log;}});throw new Error('An error occurred.');
log will have the following fields: level: log level. For example, '4' indicates error log. { level: '1', name: 'API request log (allowed log)' }{ level: '2', name: 'General log' }{ level: '4', name: 'JavaScript execution error' }{ level: '8', name: 'Promise error' }{ level: '16', name: 'Ajax request exception' }{ level: '32', name: 'JavaScript loading exception' }{ level: '64', name: 'Image loading exception' }{ level: '128', name: 'CSS loading exception' }{ level: '256', name: 'console.error (reserved)' }{ level: '512', name: 'Audio/Video resource exception' }{ level: '1024', name: 'retcode exception' }{ level: '2048', name: 'aegis report' false, the log won't be reported. This feature can be used to filter out errors that don't need to be reported; for example:const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',beforeReport(log) {if (log.level === '4' && log.msg && log.msg.indexOf('An error that doesn't need to be reported') !== -1) {return false}}});throw new Error('An error that doesn't need to be reported'); // This error will not be reported
An error that doesn't need to be reported keywords, it won't be reported to the RUM backend.beforeReport. Their only difference is that all parameters received by this hook are of an already reported log, but the parameters received by beforeReport are of a log to be reported.const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',reportApiSpeed: true,reportAssetSpeed: true,beforeReportSpeed(msg) {console.log(msg); // {url: "https://localhost:3001/example.e31bb0bc.js", method: "get", duration: 7.4, status: 200, type: "static"}return msg}});
msg will have the following fields: url: request address of this resource. type: resource type. Valid values: fetch: Aegis will report the resource as an API request; static: Aegis will report the resource as a static resource. duration: resource request duration. method: http method used when the resource is requested. status: status code returned by the server.msg returned above) as parameters to call the beforeReportSpeed hook.const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',reportApiSpeed: true,reportAssetSpeed: true,beforeReportSpeed(msg) {msg.type = 'static';}});
msg.type parameters are set to static, indicating that all resources, even API requests, will be reported as static resources.https://example.com/api whose response header Content-Type is text/html. In normal case, RUM will report this API as a static resource; however, it must be reported as an API request in your business. Then, you can configure Aegis with following hook for correction:const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',reportApiSpeed: true,reportAssetSpeed: true,beforeReportSpeed(msg) {if (msg.url === 'https://example.com/api') {msg.type = 'fetch';}}});
const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',reportApiSpeed: true,reportAssetSpeed: true,beforeReportSpeed(msg) {// Speed test logs for resources whose address contains `https://example.com/api` will not be reportedif (msg.url.indexOf('https://example.com/api') !== -1) {// If `false` is returned, the reporting of the speed test log will be blockedreturn false}}});
const aegis = new Aegis({id: 'pGUVFTCZyewxxxxx',beforeRequest: function(msg) {if (msg.logs && msg.logs.level === '4' && msg.logs.msg && msg.logs.msg.indexOf('An error that doesn't need to be reported') !== -1) {return false}return msg;}});
msg will have the following fields:logType is 'custom', logs will be in the format of {name: "white screen time", duration: 3015.7000000178814, ext1: '', ext2: '', ext3: ''}.logType is 'event', logs will be in the format of {name: "ios", ext1: "", ext2: "", ext3: ""}.logType is 'performance', logs will be in the format of {contentDownload: 2, dnsLookup: 0, domParse: 501, firstScreenTiming: 2315, resourceDownload: 260, ssl: 4, tcp: 4, ttfb: 5}.logType is 'speed', logs will be in the format of {connectTime: 0, domainLookup: 0, duration: 508.2, isHttps: true, method: "get", status: 200, type: "tatic", url: "https://xxxxxx", urlQuery: "max_age=1296000"}.logType is 'vitals', logs will be in the format of {delta: 1100, entries: [PerformancePaintTiming], id: "v1-1629344653118-4916457684758", name: "CP", value: 1100}.logType is 'log', logs will be in the format of {msg: "log details", level: '4', ext1: '', ext2: '', ext3: '', trace: ''}.level:{ level: '1', name: 'API request log (allowed log)' }{ level: '2', name: 'General log' }{ level: '4', name: 'JavaScript execution error' }{ level: '8', name: 'Promise error' }{ level: '16', name: 'Ajax request exception' }{ level: '32', name: 'JavaScript loading exception' }{ level: '64', name: 'Image loading exception' }{ level: '128', name: 'CSS loading exception' }{ level: '256', name: 'console.error (reserved)' }{ level: '512', name: 'Audio/Video resource exception' }{ level: '1024', name: 'retcode exception' }{ level: '2048', name: 'aegis report' }false, the log won't be reported. This feature can be used to filter out errors and logs that don't need to be reported.const aegis = new Aegis({id: "pGUVFTCZyewxxxxx",afterRequest: function(msg) {// {isErr: false, result: Array(1), logType: "log", logs: Array(4)}console.log(msg);}});
msg will have the following fields:logType in beforeRequest.Feedback