UNPKG

@dynatrace/react-native-plugin

Version:

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

113 lines (112 loc) 5.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynatraceAction = void 0; const StringUtils_1 = require("./util/StringUtils"); const DynatraceBridge_1 = require("./DynatraceBridge"); const ConsoleLogger_1 = require("./logging/ConsoleLogger"); class DynatraceAction { constructor(key, name, manual) { this.key = key; this.name = name; this.manual = manual; this.closed = false; this.logger = new ConsoleLogger_1.ConsoleLogger('DynatraceAction'); } reportError(errorName, errorCode, platform) { if (this.closed) { this.logger.debug(`reportError(${errorName}, ${errorCode}): Action was closed already!`); return; } if (!StringUtils_1.StringUtils.isStringNullEmptyOrUndefined(errorName)) { DynatraceBridge_1.DynatraceNative.reportErrorInAction(this.key, errorName, errorCode, platform === null || platform === void 0 ? void 0 : platform.toString()); this.logger.debug(`reportError(${errorName}, ${errorCode}): in Action - ${this.name}`); } else { this.logger.debug(`reportError(errorName, errorCode): Error will not be reported because errorName is invalid! errorName: ${errorName}, errorCode: ${errorCode}`); } } reportEvent(eventName, platform) { if (this.closed) { this.logger.debug(`reportEvent(${eventName}): Action was closed already!`); return; } if (!StringUtils_1.StringUtils.isStringNullEmptyOrUndefined(eventName)) { DynatraceBridge_1.DynatraceNative.reportEventInAction(this.key, eventName, platform === null || platform === void 0 ? void 0 : platform.toString()); this.logger.debug(`reportEvent(${eventName}): in Action - ${this.name}`); } else { this.logger.debug(`reportEvent(eventName): Event will not be reported because eventName is invalid! eventName: ${eventName} in Action - ${this.name}`); } } reportStringValue(valueName, value, platform) { if (this.closed) { this.logger.debug(`reportStringValue(${valueName}, ${value}): Action was closed already!`); return; } if (!StringUtils_1.StringUtils.isStringNullEmptyOrUndefined(valueName)) { DynatraceBridge_1.DynatraceNative.reportStringValueInAction(this.key, valueName, value, platform === null || platform === void 0 ? void 0 : platform.toString()); this.logger.debug(`reportStringValue(${valueName}, ${value}): in Action - ${this.name}`); } else { this.logger.debug(`reportStringValue(valueName, value): String value will not be reported because valueName is invalid! valueName: ${valueName}, value: ${value} in Action - ${this.name}`); } } reportIntValue(valueName, value, platform) { if (this.closed) { this.logger.debug(`reportIntValue(${valueName}, ${value}): Action was closed already!`); return; } if (!StringUtils_1.StringUtils.isStringNullEmptyOrUndefined(valueName)) { DynatraceBridge_1.DynatraceNative.reportIntValueInAction(this.key, valueName, value, platform === null || platform === void 0 ? void 0 : platform.toString()); this.logger.debug(`reportIntValue(${valueName}, ${value}): in Action - ${this.name}`); } else { this.logger.debug(`reportIntValue(valueName, value): Int value will not be reported because valueName is invalid! valueName: ${valueName}, value: ${value} in Action - ${this.name}`); } } reportDoubleValue(valueName, value, platform) { if (this.closed) { this.logger.debug(`reportDoubleValue(${valueName}, ${value}): Action was closed already!`); return; } if (!StringUtils_1.StringUtils.isStringNullEmptyOrUndefined(valueName)) { DynatraceBridge_1.DynatraceNative.reportDoubleValueInAction(this.key, valueName, value, platform === null || platform === void 0 ? void 0 : platform.toString()); this.logger.debug(`reportDoubleValue(${valueName}, ${value}): in Action - ${this.name}`); } else { this.logger.debug(`reportDoubleValue(valueName, value): Double value will not be reported because valueName is invalid! valueName: ${valueName}, value: ${value} in Action - ${this.name}`); } } leaveAction(platform) { if (this.closed) { this.logger.debug('leaveAction(): Action was closed already!'); return; } this.closed = true; this.logger.debug(`leaveAction(): ${this.name}`); DynatraceBridge_1.DynatraceNative.leaveAction(this.key, this.manual, platform === null || platform === void 0 ? void 0 : platform.toString()); } cancel(platform) { if (this.closed) { this.logger.debug('cancelAction(): Action was closed already!'); return; } this.closed = true; this.logger.debug(`cancelAction(): ${this.name}`); DynatraceBridge_1.DynatraceNative.cancelAction(this.key, platform === null || platform === void 0 ? void 0 : platform.toString()); } getRequestTag(url) { if (this.closed) { this.logger.debug(`getRequestTag(${url}): Action was closed already!`); return new Promise((resolve) => { resolve(''); }); } this.logger.debug(`getRequestTag(${url}): in Action - ${this.name}`); return DynatraceBridge_1.DynatraceNative.getRequestTag(this.key, url); } getRequestTagHeader() { return 'x-dynatrace'; } } exports.DynatraceAction = DynatraceAction;