Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chasers opened this issue Oct 19, 2020 · 1 comment
Open

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

chasers opened this issue Oct 19, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@chasers
Copy link
Contributor

chasers commented Oct 19, 2020

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 chasers added the bug Something isn't working label Oct 19, 2020
@chasers
Copy link
Contributor Author

chasers commented Oct 19, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant