Skip to content

Commit

Permalink
Add more details to error messages + Add try catch block to send()
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamloe committed Aug 5, 2021
1 parent 7d53b9d commit 67d77d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 21 additions & 13 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function exporterRetryStrategy(err, response, body, options){
catch (e) {
logger.log({
level: "error",
message: e
message: err.message
})
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 67d77d1

Please sign in to comment.