krisleech

krisleech

Preventing GenServer terminating errors being reported to Sentry

On a regular basis I’m seeing errors reported to Sentry such as GenServer #PID<0.106725.0> terminating

The “crash reason” reported in Sentry is {{%RuntimeError{message: "cannot fetch records from Kafka (topic=spaces partition=0 offset=520536). Reason: :not_leader_for_partition"}.

We filter our the above RuntimeError (see code below) so it’s not reported to Sentry, since it’s transient and resolves itself.

But we still end up with the GenServer error being reported.

It actually doesn’t look like an exception, so I’m not sure how we can filter it out.

Our working filtering code looks like this:

defmodule Shared.Infrastructure.Errors.EventFilter do
  @behaviour Sentry.EventFilter
  require Logger

   @spec exclude_exception?(Exception.t(), atom()) :: boolean()
  def exclude_exception?(exception, source) do
    (kafka_not_leader_for_partition_error?(exception) ||
       kafka_cannot_fetch_records?(exception) ||
       kafka_cannot_resolve_offset?(exception) ||
       invalid_path_error?(exception) ||
       malformed_request_error?(exception) ||
       no_route_error?(exception) ||
       invalid_query_error?(exception))
    |> tap(&maybe_log(exception, source, &1))
  end

  defp kafka_not_leader_for_partition_error?(exception) do
    exception_type?(exception, RuntimeError) &&
      message_includes?(exception, [
        "cannot fetch records from Kafka",
        "Reason: :not_leader_for_partition"
      ])
  end

  # <SNIP>

  defp maybe_log(exception, source, excluded) do
    if excluded do
      Logger.info(
        "Sentry exception excluded from being reported (source: #{inspect(source)}): #{inspect(exception)}"
      )
    end
  end
end

Any suggestions or pointers welcome…

First Post!

martosaur

martosaur

is this your genserver crashing or is it part of some library?

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement