Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #SB-24324 feat: Added new function for API error and success logs #48

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
35 changes: 34 additions & 1 deletion sb_telemetry_util/telemetryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var default_config = {
'batchsize': 200
}

function telemetryService () {
function telemetryService() {

}

Expand Down Expand Up @@ -295,4 +295,37 @@ telemetryService.prototype.generateApiCallLogEvent = function (data) {
})
}

/**
* This function used to generate api_ERROR log event
*/
telemetryService.prototype.getTelemetryAPIError = function (data, res, req, options) {
try {
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 { 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