diff --git a/package.json b/package.json index 7c9d79a..0755ab1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logzio-nodejs-metrics-alpha", - "version": "0.0.1", + "version": "0.0.2", "description": "Logz.io node.js metrics Exporter allows user to send collected metrics to the Logz.io using OpenTelemetry SDK ", "main": "src/index.js", "repository": "logzio/js-metrics", diff --git a/src/util.js b/src/util.js index 87475b8..3f066be 100644 --- a/src/util.js +++ b/src/util.js @@ -51,7 +51,7 @@ function exporterRetryStrategy(err, response, body, options){ catch (e) { logger.log({ level: "error", - message: e + message: err.message }) } } @@ -84,20 +84,28 @@ function send(collector, objects) { logger.log({level: 'info', message: `Sending bulk of ${write_request.wrappers_["1"].length} timeseries`}); response = request(options, function (err, response, body) { // this callback will only be called when the request succeeded or after maxAttempts or on error - if (response.statusCode != 200) { - logger.log({ - level: "warn", - message: `Export failed after ${response.attempts} attempts. Status code: ${response.statusCode}` - }) - lost += write_request.wrappers_["1"].length; - return response; - } else { + try { + if (response.statusCode < 200 || response.statusCode > 204 ) { + logger.log({ + level: "warn", + message: `Export failed after ${response.attempts} attempts. Status code: ${response.statusCode}` + }) + lost += write_request.wrappers_["1"].length; + return response; + } else { + logger.log({ + level: "info", + message: `Export Succeeded after ${response.attempts} attempts. Status code: ${response.statusCode}` + }) + lost = 0; + return response; + } + } + catch (e) { logger.log({ - level: "info", - message: `Export Succeeded after ${response.attempts} attempts. Status code: ${response.statusCode}` + level: "error", + message: `Failed to export error : ${err.message}` }) - lost = 0; - return response; } }); return response;