UNPKG

@dynatrace/react-native-plugin

Version:

This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.

84 lines (83 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createAppStartEvent = exports.createErrorEvent = exports.createErrorCodeEvent = exports.createCrashEvent = void 0; const AppStartType_1 = require("../appstart/AppStartType"); const createCrashEvent = (type, message, stacktrace, isFatal) => { const event = { 'characteristics.has_crash': true, 'characteristics.has_error': true, 'error.is_fatal': isFatal, }; if (type != null) { event["exception.type"] = type; } if (message != null) { event["exception.message"] = message; } if (stacktrace != null) { event["exception.stack_trace"] = stacktrace; } return event; }; exports.createCrashEvent = createCrashEvent; const createErrorCodeEvent = (errorName, errorCode) => { const event = { 'characteristics.has_error': true, 'error.is_fatal': false, }; if (errorName != null) { event["name"] = errorName; } if (errorCode != null) { event["error.code"] = errorCode; } return event; }; exports.createErrorCodeEvent = createErrorCodeEvent; const createErrorEvent = (type, message, stacktrace) => { const event = { 'characteristics.has_error': true, 'characteristics.has_exception': true, 'error.is_fatal': false, }; if (type != null) { event["exception.type"] = type; } if (message != null) { event["exception.message"] = message; } if (stacktrace != null) { event["exception.stack_trace"] = stacktrace; } return event; }; exports.createErrorEvent = createErrorEvent; const createAppStartEvent = (appStartMeasurements) => { const event = { 'characteristics.has_app_start': true, }; let timingsApp = []; for (const { type, key } of AppStartType_1.AppStartTypeKeyMapping) { if (appStartMeasurements[type] !== undefined) { timingsApp.push({ name: key, timestamp: appStartMeasurements[type], }); } } timingsApp = timingsApp.sort((a, b) => a.timestamp - b.timestamp); if (timingsApp.length > 0) { event["start_time"] = timingsApp[0].timestamp; event["duration"] = timingsApp[timingsApp.length - 1].timestamp - timingsApp[0].timestamp; for (const timing of timingsApp) { event[timing.name] = timing.timestamp - timingsApp[0].timestamp; } } else { return null; } return event; }; exports.createAppStartEvent = createAppStartEvent;