@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
128 lines (127 loc) • 6.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dynatrace = void 0;
const DynatraceBridge_1 = require("../core/DynatraceBridge");
const ConsoleLogger_1 = require("../core/logging/ConsoleLogger");
const EventCreator_1 = require("./events/EventCreator");
const EventPipeline_1 = require("./events/EventPipeline");
const EventTimestamp_1 = require("./events/EventTimestamp");
const EventModifierUtil_1 = require("./events/modifier/EventModifierUtil");
const TimestampProvider_1 = require("./provider/TimestampProvider");
const EventData_1 = require("./events/EventData");
const SessionPropertyEventData_1 = require("./events/SessionPropertyEventData");
const ExceptionEventData_1 = require("./events/ExceptionEventData");
const HttpRequestEventData_1 = require("./events/HttpRequestEventData");
const DynatraceArgValidators_1 = require("./DynatraceArgValidators");
class DynatraceImpl {
constructor(timestampProvider) {
this.timestampProvider = timestampProvider;
this.logger = new ConsoleLogger_1.ConsoleLogger('Dynatrace');
}
addEventModifier(eventModifier) {
if (!(0, DynatraceArgValidators_1.isEventModifier)(eventModifier)) {
this.logger.info('addEventModifier(eventModifier): eventModifier is not of type IEventModifier');
return {
modifyEvent: (event) => event,
};
}
this.logger.debug('addEventModifier()');
return EventPipeline_1.EventPipeline.addEventModifier(eventModifier);
}
removeEventModifier(eventModifier) {
if (!(0, DynatraceArgValidators_1.isEventModifier)(eventModifier)) {
this.logger.info('removeEventModifier(eventModifier): eventModifier is not of type IEventModifier');
return false;
}
this.logger.debug('removeEventModifier()');
return EventPipeline_1.EventPipeline.removeEventModifier(eventModifier);
}
startView(name) {
if (typeof name !== 'string') {
this.logger.info(`startView(name): Name must be a string!`);
return;
}
this.logger.debug(`startView(${name})`);
if (name != null && name.length > 0) {
DynatraceBridge_1.DynatraceNative.startView(name);
}
else {
this.logger.debug(`startView(${name}): Name can't be used. Either empty or null!`);
}
}
reportCrash(crash, isApiReported, isFatal = true) {
this.logger.debug(`reportCrash(${JSON.stringify(crash)}, ${isFatal})`);
const eventTimestamp = new EventTimestamp_1.EventTimestamp(this.timestampProvider);
const event = Object.assign(Object.assign({}, (0, EventCreator_1.createCrashEvent)(crash.name, crash.message, crash.stack, isFatal)), eventTimestamp.getEventTimeInfo());
if (isApiReported) {
(0, EventModifierUtil_1.addIsApiReported)(event);
event["dt.support.is_legacy_api_reported"] = true;
}
EventPipeline_1.EventPipeline.insertEvent(event);
}
reportErrorCode(errorName, errorCode, isApiReported) {
this.logger.debug(`reportErrorCode(${errorName}, ${errorCode})`);
const eventTimestamp = new EventTimestamp_1.EventTimestamp(this.timestampProvider);
const event = Object.assign(Object.assign({}, (0, EventCreator_1.createErrorCodeEvent)(errorName, errorCode)), eventTimestamp.getEventTimeInfo());
if (isApiReported) {
(0, EventModifierUtil_1.addIsApiReported)(event);
event["dt.support.is_legacy_api_reported"] = true;
}
EventPipeline_1.EventPipeline.insertEvent(event);
}
reportError(error, isApiReported) {
this.logger.debug(`reportError(${JSON.stringify(error)})`);
const eventTimestamp = new EventTimestamp_1.EventTimestamp(this.timestampProvider);
const event = Object.assign(Object.assign({}, (0, EventCreator_1.createErrorEvent)(error.name, error.message, error.stack)), eventTimestamp.getEventTimeInfo());
if (isApiReported) {
(0, EventModifierUtil_1.addIsApiReported)(event);
event["dt.support.is_legacy_api_reported"] = true;
}
EventPipeline_1.EventPipeline.insertEvent(event);
}
sendExceptionEvent(exceptionEventData) {
if (!(exceptionEventData instanceof ExceptionEventData_1.default)) {
this.logger.info('sendExceptionEvent(exceptionEventData): exceptionEventData is not of type ExceptionEventData');
return;
}
this.logger.debug('sendExceptionEvent(exceptionEventData)');
const eventValidated = exceptionEventData.toJSON();
if (eventValidated !== null) {
EventPipeline_1.EventPipeline.insertEvent(eventValidated);
}
}
sendEvent(eventData) {
if (!(eventData instanceof EventData_1.default)) {
this.logger.info('sendEvent(eventData): eventData is not of type EventData');
return;
}
this.logger.debug('sendEvent(eventData)');
const eventValidated = eventData.toJSON();
if (eventValidated !== null) {
EventPipeline_1.EventPipeline.insertEvent(eventValidated);
}
}
sendSessionPropertyEvent(sessionPropertyEventData) {
if (!(sessionPropertyEventData instanceof SessionPropertyEventData_1.default)) {
this.logger.info('sendSessionPropertyEvent(SessionPropertyEventData): sessionPropertyEventData is not of type SessionPropertyEventData');
return;
}
this.logger.debug('sendSessionPropertyEvent(SessionPropertyEventData)');
const eventValidated = sessionPropertyEventData.toJSON();
if (eventValidated !== null) {
EventPipeline_1.EventPipeline.insertEvent(eventValidated);
}
}
sendHttpRequestEvent(httpRequestEvent) {
if (!(httpRequestEvent instanceof HttpRequestEventData_1.default)) {
this.logger.info('sendHttpRequestEvent(HttpRequestEventData): httpRequestEvent is not of type HttpRequestEventData');
return;
}
this.logger.debug('sendHttpRequestEvent(HttpRequestEventData)');
const sanitizedEvent = httpRequestEvent.toJSON();
if (sanitizedEvent !== null) {
EventPipeline_1.EventPipeline.insertEvent(sanitizedEvent);
}
}
}
exports.Dynatrace = new DynatraceImpl(TimestampProvider_1.defaultTimestampProvider);