From 9c66b94e2c6db97533a668f86ec3a83d2799e52e Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Mon, 22 Mar 2021 16:56:23 +0530 Subject: [PATCH 1/5] Issue SB:23223 fix: added the function to get telemetry edata --- sb_telemetry_util/telemetryService.js | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sb_telemetry_util/telemetryService.js b/sb_telemetry_util/telemetryService.js index 0df845a..9e790bb 100644 --- a/sb_telemetry_util/telemetryService.js +++ b/sb_telemetry_util/telemetryService.js @@ -1,5 +1,7 @@ var Telemetry = require('./telemetryLibrary.js') var telemetrySyncManager = require('./telemetrySyncManager.js') +const telemetryHelper = require('../../helpers/telemetryHelper.js') +const _ = require('lodash') var default_config = { 'runningEnv': 'server', @@ -7,7 +9,7 @@ var default_config = { 'batchsize': 200 } -function telemetryService () { +function telemetryService() { } @@ -295,4 +297,31 @@ telemetryService.prototype.generateApiCallLogEvent = function (data) { }) } +/** + * This function used to generate api_ERROR log event + */ +/** + * This function used to generate api_ERROR log event + */ +telemetryService.prototype.getTelemetryAPIError = function (data, res, context) { + try { + if ((data.responseCode !== 'OK' && data.responseCode !== 200) || res.statusCode !== 200) { + const result = data.params; + if (result) { + const edata = { + err: data.responseCode || res.statusCode, + errtype: result.err || res.statusMessage, + requestid: result.resmsgid || 'null', + errmsg: result.errmsg || 'null' + } + const option = { edata, context } + return option; + } + } + return; + } catch (error) { + console.log('error', error) + } +} + module.exports = telemetryService From a1afcf5919ab11e17113ec8d16a9956d326115f6 Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Mon, 22 Mar 2021 16:59:27 +0530 Subject: [PATCH 2/5] Issue SB:23223 fix: minor change --- sb_telemetry_util/telemetryService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/sb_telemetry_util/telemetryService.js b/sb_telemetry_util/telemetryService.js index 9e790bb..f7f1f53 100644 --- a/sb_telemetry_util/telemetryService.js +++ b/sb_telemetry_util/telemetryService.js @@ -1,6 +1,5 @@ var Telemetry = require('./telemetryLibrary.js') var telemetrySyncManager = require('./telemetrySyncManager.js') -const telemetryHelper = require('../../helpers/telemetryHelper.js') const _ = require('lodash') var default_config = { From 71ff6de93762345fb27871592020c6319f81968e Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Wed, 24 Mar 2021 11:52:57 +0530 Subject: [PATCH 3/5] Issue SB:23223 fix: removed unnecessary dependency --- sb_telemetry_util/telemetryService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/sb_telemetry_util/telemetryService.js b/sb_telemetry_util/telemetryService.js index f7f1f53..0db4bf2 100644 --- a/sb_telemetry_util/telemetryService.js +++ b/sb_telemetry_util/telemetryService.js @@ -1,6 +1,5 @@ var Telemetry = require('./telemetryLibrary.js') var telemetrySyncManager = require('./telemetrySyncManager.js') -const _ = require('lodash') var default_config = { 'runningEnv': 'server', From ea8c0fe82788139a814b891e93ba56c6cb232f25 Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Fri, 25 Jun 2021 13:29:21 +0530 Subject: [PATCH 4/5] Issue #SB-24324 feat: Added new function for API error and success logs --- sb_telemetry_util/telemetryService.js | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/sb_telemetry_util/telemetryService.js b/sb_telemetry_util/telemetryService.js index 0db4bf2..d267b42 100644 --- a/sb_telemetry_util/telemetryService.js +++ b/sb_telemetry_util/telemetryService.js @@ -298,28 +298,34 @@ telemetryService.prototype.generateApiCallLogEvent = function (data) { /** * This function used to generate api_ERROR log event */ -/** - * This function used to generate api_ERROR log event - */ -telemetryService.prototype.getTelemetryAPIError = function (data, res, context) { +telemetryService.prototype.getTelemetryAPIError = function (data, res, req, options) { try { - if ((data.responseCode !== 'OK' && data.responseCode !== 200) || res.statusCode !== 200) { - const result = data.params; - if (result) { - const edata = { - err: data.responseCode || res.statusCode, - errtype: result.err || res.statusMessage, - requestid: result.resmsgid || 'null', - errmsg: result.errmsg || 'null' - } - const option = { edata, context } - return option; - } + const result = options ? options : data.params + const edata = { + err: result.err || res.statusMessage, + errtype: result.errtype || data.responseCode || res.statusCode, + traceid: result.msgid || 'null', + status: result.status || '', + errmsg: result.errmsg || '', + params: JSON.stringify([{ url: req.path }]) } - return; + return { edata }; } catch (error) { console.log('error', error) } } +/** + * This function used to generate api_call log telemetryData +*/ +telemetryService.prototype.getTelemetryAPISuceessData = function (req, result, uri) { + const telemetryData = { + reqObj: req, + statusCode: '200', + resp: result, + uri: uri, + channel: req.get('x-channel-id') || '' + } + return telemetryData; +} module.exports = telemetryService From 2a17aeba09004d41e71a3ce6fd51662a53461474 Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Mon, 28 Jun 2021 18:55:10 +0530 Subject: [PATCH 5/5] Issue #SB-24324 feat: Added new function for API error and success logs --- sb_telemetry_util/telemetryService.js | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/sb_telemetry_util/telemetryService.js b/sb_telemetry_util/telemetryService.js index 0db4bf2..3d1b627 100644 --- a/sb_telemetry_util/telemetryService.js +++ b/sb_telemetry_util/telemetryService.js @@ -298,28 +298,34 @@ telemetryService.prototype.generateApiCallLogEvent = function (data) { /** * This function used to generate api_ERROR log event */ -/** - * This function used to generate api_ERROR log event - */ -telemetryService.prototype.getTelemetryAPIError = function (data, res, context) { + telemetryService.prototype.getTelemetryAPIError = function (data, res, req, options) { try { - if ((data.responseCode !== 'OK' && data.responseCode !== 200) || res.statusCode !== 200) { - const result = data.params; - if (result) { - const edata = { - err: data.responseCode || res.statusCode, - errtype: result.err || res.statusMessage, - requestid: result.resmsgid || 'null', - errmsg: result.errmsg || 'null' - } - const option = { edata, context } - return option; - } + const result = options ? options : data.params + const edata = { + err: result.err || res.statusMessage, + errtype: result.errtype || data.responseCode || res.statusCode, + traceid: result.msgid || 'null', + status: result.status || '', + errmsg: result.errmsg || '', + params: JSON.stringify([{ url: req.path }]) } - return; + return { edata }; } catch (error) { console.log('error', error) } } +/** + * This function used to generate api_call log telemetryData +*/ +telemetryService.prototype.getTelemetryAPISuceessData = function (req, result, uri) { + const telemetryData = { + reqObj: req, + statusCode: '200', + resp: result, + uri: uri, + channel: req.get('x-channel-id') || '' + } + return telemetryData; +} module.exports = telemetryService