Hello!
I build a LoggerExporter for elixir/phoenix. I’m on Heroku and there is no easy way to export your logs to a different logging service of the current options.
I haven’t published the library yet, here is the repo: GitHub - romariolopezc/logger_exporter all the info is in the readme and I still need to write documentation for Hex.pm.
I export logs to Grafana Loki using the http endpoint.
I couldn’t find good documentation on how to build a library and what decisions to make. I have some questions and I’ll be grateful if someone points me in the right direction / gives me feedback.
There are 3 main components in this library:
- Logger backend
- Batcher
- HTTP Client
The Logger backend sends the formatted events to the Batcher. The Batcher enqueues the events and sends it to the HTTP client every 2 seconds.
My question about the current implementation:
If the host
part of the configuration is missing, the http client fails because an error is raised here, the exception is propagated to the Batcher
GenEvent here and it pollutes the logs with the same error over an over.
The exception is logged as an error, so the same process is repeated: Logger backend → Batcher → Http client → exception → Logger backend. I have thought of these solutions:
- Validate the configuration in the Logger backend
init
callback and if a required config variable is missing return{:error, :ignore}
so the backend is not added to the logger backends. - Do not raise that a config is missing and skip the http call (not my favorite)
Same question is for the config variables that raise: app_name
and environment_name
.
- What’s the best way to handle a required configuration for the library to work?
- Is this the correct way to accept library config variables?
- What do you think of the readme?
Thanks for the feedback!