rlopzc

rlopzc

LoggerExporter - Export your logs to Grafana Loki or other external services

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:

  1. 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.
  2. 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.

  1. What’s the best way to handle a required configuration for the library to work?
  2. Is this the correct way to accept library config variables?
  3. What do you think of the readme?

Thanks for the feedback!

Most Liked

rlopzc

rlopzc

Bumping it to see if someone has a guide/opinion on the lib config part

Thanks!

Where Next?

Popular in Libraries Top

marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. [demo] The distributed characteristics of Elixir and the low memory foo...
New
Antrater
Hi everyone! I’m thrilled to announce a huge thing. We have been developing Elixir Moon Design System for quite a while. We are finally ...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Sub Categories:

We're in Beta

About us Mission Statement