Logflare / logflare_logger_backend

Logger backend to send Elixir logs to Logflare.
MIT License
88 stars 17 forks source link

No source_id found when booting nerves release #70

Closed tsloughter closed 3 years ago

tsloughter commented 3 years ago

I'm not sure if this is exactly #42 or not, and one issue is that with nerves I can't yet use runtime.exs, so the fix found there isn't usable.

But it is essentially the same error, running locally with iex everything works fine but when I burn firmware to an sd card and boot it on the device I get crashes on boot because it says source_id isn't configured.

The generated sys.config in the release that nerves creates appears fine, I see the logflare_logger_backend section with the source_id as I 'd expect when it translates config.exs to sys.config.

I'm new to nerves and still get confused by how Elixir's does configuration (at least seems reasonable now with runtime.exs, but not an option in this case because of the use of nerves).

The configuration done when the backend boots looke reasonable, it reads it in from the application env in init, so I'm curious why was it necessary in the other case to move it to runtime.exs instead of config.exs. Aren't they both going to result in application env variables in sys.config? Maybe that'll lead me down the path to figuring out what is going on :)

chasers commented 3 years ago

I mean if you don't understand it, I'm wondering if I'll be able to figure it out :)

But this will give me a chance to play with Nerves today! I have a few PIs laying around so let me see what I can do.

chasers commented 3 years ago

I'm thinking we can merge in system env variables also, so people can set them there as a fallback no matter what.

chasers commented 3 years ago

@tsloughter can you try this one?

https://github.com/Logflare/logflare_logger_backend/releases/tag/v0.10.1

chasers commented 3 years ago

Try setting these via your system envs:

export LOGFLARE_URL="https://api.logflare.app"
export LOGFLARE_API_KEY="..."
export LOGFLARE_SOURCE_ID="..."
tsloughter commented 3 years ago

Yup, will give it a try in a bit.

tsloughter commented 3 years ago

Woo, that worked! Well, almost :). I no longer get the source id error but logs return a 406 status, something about source name.

chasers commented 3 years ago

Can you confirm you exported the source_id?

export LOGFLARE_SOURCE_ID="..."
chasers commented 3 years ago

The source ID is the UUID so it'll look like this, and you can copy it from your Logflare dashboard. I will improve that error message a bit.

export LOGFLARE_SOURCE_ID=UUID
tsloughter commented 3 years ago

Yes, it must be being set, the error messages I got when it wasn't have gone away. I even at first had been setting OGFLARE_SOURCE_ID and got an error about source id not being set. And the source id works fine when I am using it by setting the usual way in config.exs and running iex.

So is the error that the source id must be wrong? Maybe it is an issue with how I'm setting it through erlinit:

config :nerves, :erlinit,
  hang_on_exit: true,
  env: "LOGFLARE_URL=https://api.logflare.app;LOGFLARE_API_KEY=...;LOGFLARE_SOURCE_ID=..."

I guess I'll try putting escaped quotes around the value.

tsloughter commented 3 years ago

Darn, still get "Source or source_name is nil, empty or not found".

chasers commented 3 years ago

Try to copy it again from your Logflare dashboard and make sure that source_id is in your account?

I verified that it's pulling correctly from the system env on my machine here.

tsloughter commented 3 years ago

Yes, it works fine for me from the system env too.. It only fails when I run the nerves release with it being set as shown in the above config.

If that error message means the source_id is wrong then I can be fairly certain it is an issue of how erlinit is parsing this key/value pair.

tsloughter commented 3 years ago

Alright, I finally got it :) thanks for all the help and the release.

I did it by overriding the erlinit config file with one that uses -e to set the environment variables https://hexdocs.pm/nerves/advanced-configuration.html#overwriting-files-in-the-root-filesystem

Don't now why it didn't work when I was setting them in erlinit section of config.exs, or when setting the config directly in the logflare_logger_backend section of config.exs, but atleast it is working now :)