fluent / fluent/fluent-logger-node
Error events take too much time to emit when fluentd is not available
- Dominant language
- JavaScript
- Stars
- 258
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Description
Hey,
We are using your library to send logs from our lambda functions to fluentd via Bunyan Logger.
```
// Instance style fluent-logger creation
const sender = require('fluent-logger').createFluentSender('tag-prefix', {
enableReconnect: false,
host: 'localhost',
port: 24224,
reconnectInterval: 3000,
requireAckResponse: true,
timeout: 3.0
});
// Listener for detecting error events
sender.on('error', (error) => {
console.log('Error found on stream here. ' + error);
// Printing the logs on stdout using the buffer.
});
// bunyan logger instance for sending logs to fluentd.
logger = bunyan.createLogger({
name: 'FluentdLogger',
streams: [{ stream: sender.toStream('fluentd') }]
});
logger.info('this log record is sent to fluent daemon');
```
1. Using the above mentioned approach, the logs are successfully being sent to fluentd from lambda.
2. However, when fluentd is not available, then the expected behavior is to catch the error event during the creation of bunyan instance and send the logs to stdout.
However, we have noticed that it takes a significant amount of time for the error event to be emitted when fluentd is not available, before which the lambda is completing its execution thus not reaching the error handler.
```
setTimeout(()=> sender.end(), 5000);
```
The above snippet seems to not work for me.
Therefore, is there any way to:
1. Avoid delaying the lambda execution in the case when fluentd is not available and error event needs to be caught?
2. If not, then what is the best way to perform a timeout so as to make the lambda quit after the error listener code has been executed?
It would be great if anyone could advise me on it.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at createFluentSender and follow the error event and sender.end lifecycle using the configuration shown, with fluentd unavailable at localhost:24224. Reproduce the Lambda timing behavior and establish whether the issue is fixed by a supported timeout or requires documentation of the expected shutdown behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100