Skip to content

Commit 1c3523b

Browse files
authored
[azure] Add 10 second timeout to Azure log submission requests (#514)
* [azure] Add 10 second timeout to Azure log submission requests * add semicolon
1 parent 2a80a58 commit 1c3523b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

azure/activity_logs_monitoring/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
var https = require('https');
77

8-
const VERSION = '0.5.5';
8+
const VERSION = '0.5.6';
99

1010
const STRING = 'string'; // example: 'some message'
1111
const STRING_ARRAY = 'string-array'; // example: ['one message', 'two message', ...]
@@ -23,6 +23,7 @@ const DD_API_KEY = process.env.DD_API_KEY || '<DATADOG_API_KEY>';
2323
const DD_SITE = process.env.DD_SITE || 'datadoghq.com';
2424
const DD_HTTP_URL = process.env.DD_URL || 'http-intake.logs.' + DD_SITE;
2525
const DD_HTTP_PORT = process.env.DD_PORT || 443;
26+
const DD_REQUEST_TIMEOUT_MS = 10000;
2627
const DD_TAGS = process.env.DD_TAGS || ''; // Replace '' by your comma-separated list of tags
2728
const DD_SERVICE = process.env.DD_SERVICE || 'azure';
2829
const DD_SOURCE = process.env.DD_SOURCE || 'azure';
@@ -138,7 +139,8 @@ class HTTPClient {
138139
'Content-Type': 'application/json',
139140
'DD-API-KEY': DD_API_KEY,
140141
'DD-EVP-ORIGIN': 'azure'
141-
}
142+
},
143+
timeout: DD_REQUEST_TIMEOUT_MS
142144
};
143145
this.scrubber = new Scrubber(this.context, SCRUBBER_RULE_CONFIGS);
144146
this.batcher = new Batcher(
@@ -193,6 +195,10 @@ class HTTPClient {
193195
.on('error', error => {
194196
reject(error);
195197
});
198+
req.on('timeout', () => {
199+
req.destroy();
200+
reject(`request timed out after ${DD_REQUEST_TIMEOUT_MS}ms`);
201+
})
196202
req.write(this.scrubber.scrub(JSON.stringify(record)));
197203
req.end();
198204
});

0 commit comments

Comments
 (0)