Improve error reporting
umpirsky opened this issue · 5 comments
In cases when something goes wrong, errors are not reported, just logged (e.g. https://github.com/zumba/amplitude-php/blob/master/src/Amplitude.php#L491, https://github.com/zumba/amplitude-php/blob/master/src/Amplitude.php#L507).
This makes library unusable IMO.
I want to know when something bad happens, exception thrown for example.
Sorry for the late reply, somehow I had notification turned off for this project. I wanted to reply for posterity though:
Both of the examples given are possibly connection related so they do log an error but do not throw an exception.
I want to know when something bad happens, exception thrown for example.
You can, just register your own logger (use $amplitude-> setLogger()
mentioned in troubleshooting tips), it uses PSR-2 logger interface. That gives you the option to inject your own logger so you can do anything you want (including throwing an exception) for any critical log messages.
The library is meant for production environments, where most of the time a connection issue to analytics tracking should be logged but not cause the site to go down. So following that, it does throw an exception for anything caused by coding errors (say you try to send an event without setting the api key or something). Anything else, it logs a message you can see with a logger.
The library is meant for production environments, where most of the time a connection issue to analytics tracking should be logged but not cause the site to go down.
It's easier to catch exception then writing your own logger.
It's easier to catch exception then writing your own logger.
Here is one for you with working code on the docs you can use as a starting point:
https://github.com/zumba/amplitude-php#stand-alone-troubleshooting-script
It's not a problem to implement, just saying. :)
@umpirsky It's also easy to forget to catch an exception and having an analytics server outage cause an outage on your site. However, perhaps it could be something configurable where the default is the current behavior, but you could provide an option to have error logs throw exceptions. I wouldn't turn down a PR for giving the option.