Throw errors instead of logging to stdout
See original GitHub issueSnippet from my nodejs log:
2018-02-07 11:07:23 - info: Config loaded: 'marketbot.ini'
Elastic APM isn't correctly configured: Missing serviceName
2018-02-07 11:07:23 - info: Elastic APM enabled, logging to 'http://localhost:8200'
2018-02-07 11:07:23 - info: Starting bot activation
Elastic APM is started with this:
elastic.start({
appName: 'marketbot',
secretToken: configuration.getProperty('elastic.token'),
serverUrl: configuration.getProperty('elastic.url')
});
If Elastic APM cannot start because of some reason (for example an error in configuration), I expect to get an error. Instead the module logs directly to stdout, bypassing my custom logger.
I’d like Elastic APM to throw errors instead of logging to stdout, this way I can choose to react to the error, do nothing or let the application crash.
The same behaviour happens when calling transaction.end();
. If the request fails then I expect an error here as well.
Instead of this output:
Error: connect ECONNREFUSED 127.0.0.1:8200
at Object._errnoException (util.js:1003:13)
at _exceptionWithHostPort (util.js:1024:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Throw exception vs Logging - java - Stack Overflow
Normally, I'd argue that you should either log or rethrow. Doing both will just cause every layer to log the exception again and...
Read more >Should I log errors on exception throwing constructors?
Instead of this I suggest to log errors not when the exception is created, but when it is caught. (For this, of course,...
Read more >A Complete Guide to Winston Logging in Node.js - Better Stack
Learn how to start logging with Winston in Node.js and go from basics to best ... You can try this out by throwing...
Read more >Ability to console.log output from test files to stdout ... - GitHub
as a hacky partial workaround for debugging index.js setup and some other situations, you can throw an error instead of using console.log.
Read more >Error Handling in JavaScript: a Quick Guide | by Bret Cameron
So, when would we consider returning or logging an error instead of throwing it? For some errors, which are predictable and occur commonly, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Coming back to this a few years later, it looks like our customer logger was fixed, so that aspect of this issue is completed.
Re:
Speaking broadly the agent goes out of its way not to throw an exception that might not be caught. We do this out of an abundance of caution for not crashing the application under instrumentation.
Closing this out for now, but we’re always happy to revisit here in old 2020.
@dicarlo2 Thanks for raising this. I’ve created an issue on it: #289