Logflare / logflare_logger_backend

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

Logflare returns a 500 with a list of tuples as a metadata value #46

Open chasers opened 3 years ago

chasers commented 3 years ago
h = [
    {"accept", "*/*"},
    {"accept-encoding", "gzip, deflate, br"},
    {"connection", "keep-alive"},
    {"host", "localhost:4320"},
    {"postman-token", "128bdbd8-3780-4a89-8b51-2a3781db6e91"},
    {"user-agent", "PostmanRuntime/7.26.5"}
  ]

LogflareLogger.info("yo", headers: h)
iex(5)> warning: Logflare API warning: HTTP response status is 500
  (logflare_logger_backend 0.7.6) lib/logflare_logger/batch_cache.ex:49: LogflareLogger.BatchCache.flush/1
  (logflare_logger_backend 0.7.6) lib/logflare_logger/http_backend.ex:113: LogflareLogger.HttpBackend.flush!/1
  (stdlib 3.13.2) gen_event.erl:620: :gen_event.server_update/4
  (stdlib 3.13.2) gen_event.erl:602: :gen_event.server_notify/4
  (stdlib 3.13.2) gen_event.erl:604: :gen_event.server_notify/4
  (stdlib 3.13.2) gen_event.erl:390: :gen_event.handle_msg/6
  (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
chasers commented 3 years ago

If you're trying to log headers you'll want to handle them, basically turning each of those tuples into a key value pair and logging them as a map. This way you can query them like m.headers.user_agent:~"Postman" for instance (this will return all requests with user agents with Postman in the string).

We're replacing dashes with underscores as BigQuery doesn't like dashes in column names. Logflare will handle this for you but it will also prepend an underscore before modified field name so you know Logflare modified that field name.

h = [
    {"accept", "*/*"},
    {"accept-encoding", "gzip, deflate, br"},
    {"connection", "keep-alive"},
    {"host", "localhost:4320"},
    {"postman-token", "128bdbd8-3780-4a89-8b51-2a3781db6e91"},
    {"user-agent", "PostmanRuntime/7.26.5"}
  ]
|> Enum.map(fn {key, value} -> {String.replace(key, "-", "_"), value} end)
|> Enum.into(%{})           

LogflareLogger.info("Request!", headers: h)