Skip to content

Commit

Permalink
Add option to fail exuection on batch and send errors
Browse files Browse the repository at this point in the history
  • Loading branch information
parsons90 committed Feb 14, 2024
1 parent bf612fa commit 431a913
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion azure/blobs_logs_monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2021 Datadog, Inc.
var https = require('https');

const VERSION = '1.0.0';
const VERSION = '1.1.0';

const STRING = 'string'; // example: 'some message'
const STRING_ARRAY = 'string-array'; // example: ['one message', 'two message', ...]
Expand All @@ -26,6 +26,20 @@ const DD_SERVICE = process.env.DD_SERVICE || 'azure';
const DD_SOURCE = process.env.DD_SOURCE || 'azure';
const DD_SOURCE_CATEGORY = process.env.DD_SOURCE_CATEGORY || 'azure';

// Whether to fail the function execution on any error batching and sending logs
const DD_SHOULD_FAIL_EXECUTION_ON_ERROR = process.env.DD_SHOULD_FAIL_EXECUTION_ON_ERROR;


function shouldFailExecutionOnError() {
// Default to false if the env variable is not set, is null, etc
if (typeof DD_SHOULD_FAIL_EXECUTION_ON_ERROR !== 'string') {
return false;
}
const should_fail_exeution_on_error = DD_SHOULD_FAIL_EXECUTION_ON_ERROR.toLowerCase();
return (should_fail_exeution_on_error === 'true' || should_fail_exeution_on_error === 't');
}


/*
To scrub PII from your logs, uncomment the applicable configs below. If you'd like to scrub more than just
emails and IP addresses, add your own config to this map in the format
Expand Down Expand Up @@ -625,6 +639,10 @@ module.exports = async function (context, blobContent) {
} catch (err) {
context.log.error('Error raised when sending logs: ', err);
allLogsSentSuccessfully = false;
if (shouldFailExecutionOnError()) {
context.log.error('Failing execution of the function.')
throw err;
}
}

if (allLogsSentSuccessfully) {
Expand Down

0 comments on commit 431a913

Please sign in to comment.