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?

Last Post!

martosaur

martosaur

Ah okay then, this probably means you don’t have control over the process to not make it crash over a somewhat expected error. In this case you probably want to filter this error from all logs, not just Sentry. Adding a primary logger filter might be the solution!

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics 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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement