question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throw errors instead of logging to stdout

See original GitHub issue

Snippet 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
astormcommented, Nov 2, 2020

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:

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.

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.

0reactions
watsoncommented, Mar 22, 2018

@dicarlo2 Thanks for raising this. I’ve created an issue on it: #289

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found