apminsight
Version:
monitor nodejs applications
93 lines (82 loc) • 2.64 kB
JavaScript
var transaction = require("./transaction");
var libUtil = require("util");
var metricstore = require("./metricstore");
var constants = require("./../constants");
var utils = require("./../util/utils");
/* eslint-disable no-unused-vars */
function BgTxn(reqInfo, req) {
transaction.call(this, reqInfo);
this._url = reqInfo.uri;
this._errst = null;
}
/* eslint-enable no-unused-vars */
libUtil.inherits(BgTxn, transaction);
BgTxn.prototype.endApiTxn = function (err) {
if (this.isTxnIgnored()) {
return;
}
this.updateRtMetric();
this.updateReqCountByErr(err);
this.markCompleted();
this.updateInDataStore();
};
BgTxn.prototype.getMethod = function () {
return constants.bckgrnd;
};
BgTxn.prototype.aggregate = function (txn) {
this._url = txn.getUrl();
if (txn.isErrorTxn()) {
this._errorCount += txn.getErrorCount();
this._errorRt += txn.getRt();
}
this.aggregateTxnSubResources(txn);
if (txn.getCount() > 0) {
this.aggregateNonErrorTxn(txn);
}
};
BgTxn.prototype.updateInDataStore = function () {
var txnMetric = metricstore.getBgTxnmetric();
var samplingFac = utils.getGenericThreshold().getBgTxnSamplingFactor();
var metricLimit = utils.getGenericThreshold().getBgMetricSize();
this.checkAndupdateInDataStore(txnMetric, BgTxn, samplingFac, metricLimit);
};
BgTxn.prototype.getFormattedRtData = function () {
var rtData = [
this.getRt(),
this.getMinRt(),
this.getMaxRt(),
this.getCount(),
this.getErrorCount()
];
var additinalMetric = {
components: this.getComponentDetails(),
logmetric: this.getErrorDetails(),
error_rt: this.getErrorRt()
};
return [rtData, additinalMetric];
};
BgTxn.prototype.getTraceInfo = function () {
var traceInfo = {};
traceInfo.t_name = constants.bgTxnPrefix + this.getUrl();
traceInfo.s_time = this.getStartTime();
traceInfo.r_time = this.getRt();
traceInfo.trace_reason = 4;
traceInfo.db_opn = [];
traceInfo.loginfo = [];
traceInfo.method_count = 1;
traceInfo.dt_count = 0;
traceInfo.custom_params = this.getCustomParamsAsStr();
Object.assign(traceInfo, this.getTrackerCountInfo());
traceInfo.drop_threshold = utils
.getGenericThreshold()
.getTxnTrackerDropThreshold();
this.appendCompInfoInTrace(traceInfo);
if (!utils.isEmpty(this.getError())) {
traceInfo.err_st = this.getError().getErrorStackFrames();
}
return traceInfo;
};
BgTxn.prototype.getTxnType = function () {
return "bgtxn";
};
module.exports = BgTxn;