sendingnetwork-bot-sdk
Version:
TypeScript/JavaScript SDK for SDN bots
108 lines • 4.76 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.timedIntentFunctionCall = exports.timedIdentityClientFunctionCall = exports.timedSDNClientFunctionCall = void 0;
const names_1 = require("./names");
/**
* Times a SDNClient function call for metrics.
* @category Metrics
*/
function timedSDNClientFunctionCall() {
return function (_target, functionName, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args) {
return __awaiter(this, void 0, void 0, function* () {
const context = this.metrics.assignUniqueContextId({
functionName,
client: this,
});
this.metrics.start(names_1.METRIC_SDN_CLIENT_FUNCTION_CALL, context);
try {
const result = yield originalMethod.apply(this, args);
this.metrics.increment(names_1.METRIC_SDN_CLIENT_SUCCESSFUL_FUNCTION_CALL, context, 1);
return result;
}
catch (e) {
this.metrics.increment(names_1.METRIC_SDN_CLIENT_FAILED_FUNCTION_CALL, context, 1);
throw e;
}
finally {
this.metrics.end(names_1.METRIC_SDN_CLIENT_FUNCTION_CALL, context);
}
});
};
};
}
exports.timedSDNClientFunctionCall = timedSDNClientFunctionCall;
/**
* Times an IdentityClient function call for metrics.
* @category Metrics
*/
function timedIdentityClientFunctionCall() {
return function (_target, functionName, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args) {
return __awaiter(this, void 0, void 0, function* () {
const context = this.metrics.assignUniqueContextId({
functionName,
client: this,
});
this.metrics.start(names_1.METRIC_IDENTITY_CLIENT_FUNCTION_CALL, context);
try {
const result = yield originalMethod.apply(this, args);
this.metrics.increment(names_1.METRIC_IDENTITY_CLIENT_SUCCESSFUL_FUNCTION_CALL, context, 1);
return result;
}
catch (e) {
this.metrics.increment(names_1.METRIC_IDENTITY_CLIENT_FAILED_FUNCTION_CALL, context, 1);
throw e;
}
finally {
this.metrics.end(names_1.METRIC_IDENTITY_CLIENT_FUNCTION_CALL, context);
}
});
};
};
}
exports.timedIdentityClientFunctionCall = timedIdentityClientFunctionCall;
/**
* Times an Intent function call for metrics.
* @category Metrics
*/
function timedIntentFunctionCall() {
return function (_target, functionName, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args) {
return __awaiter(this, void 0, void 0, function* () {
const context = this.metrics.assignUniqueContextId({
functionName,
client: this.client,
intent: this,
});
this.metrics.start(names_1.METRIC_INTENT_FUNCTION_CALL, context);
try {
const result = yield originalMethod.apply(this, args);
this.metrics.increment(names_1.METRIC_INTENT_SUCCESSFUL_FUNCTION_CALL, context, 1);
return result;
}
catch (e) {
this.metrics.increment(names_1.METRIC_INTENT_FAILED_FUNCTION_CALL, context, 1);
throw e;
}
finally {
this.metrics.end(names_1.METRIC_INTENT_FUNCTION_CALL, context);
}
});
};
};
}
exports.timedIntentFunctionCall = timedIntentFunctionCall;
//# sourceMappingURL=decorators.js.map