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

Write Logging Always Returns 0 for Response #57

Open
allenwyma opened this issue Jul 28, 2020 · 2 comments
Open

Write Logging Always Returns 0 for Response #57

allenwyma opened this issue Jul 28, 2020 · 2 comments

Comments

@allenwyma
Copy link

Hi, I've been using this library for some time and I'm quite loving it for writing some tick data into influxDB. I recently ran into an issue where writes were failing cause of data type mis matches (trying to write integer to a float field).

The logs were returning response of 0, which should be okay, but then I dug deeper and saw it's ALWAYS returning 0.

Is there a way to change the log WriteEntry to actually return an error response instead of response always being set to 0?

@mneudert
Copy link
Owner

Apparently there is no direct way because for whatever reason I decided to not set the result of the write request into the log entry 🤦

The only somewhat usable way before having a more usable base logging in place (just added the result contents to the unreleased main branch) would be to hook into the writer:

config :your_app, YourConnection,
  writer: ErrorLoggingWriter

defmodule ErrorLoggingWriter do
  alias Instream.Writer.Line

  @behaviour Instream.Writer

  def write(payload, opts, worker_state) do
    payload
    |> Line.write(opts, worker_state)
    |> maybe_log_error()
  end

  defp maybe_log_error({400, _, body} = response) do
    _ = case Jason.decode!(body) do
      %{"error" => error} -> Logger.warn(error)
      _ -> :ok
    end

    response
  end

  defp maybe_log_error(response), do: response
end

This should at least log the error.

@allenwyma
Copy link
Author

This looks good, I can use this. Thanks for this! Looking forward to an update where I don't need to replace the writer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants