getsentry / sentry-elixir

The official Elixir SDK for Sentry (sentry.io)
https://sentry.io
MIT License
627 stars 185 forks source link

Support client reports #783

Closed stephanie-anderson closed 1 month ago

stephanie-anderson commented 2 months ago

Support https://develop.sentry.dev/sdk/client-reports/

If tracing is supported by the time this issue is handled, we would also want to report dropped spans: https://github.com/getsentry/projects/issues/70

whatyouhide commented 2 months ago

Just talked strategy with @savhappy, notes:

A client report should be a struct typed as:

@type client_report() :: %Sentry.ClientReport{
  timestamp: timestamp(),
  discarded_events: %{
    optional({type :: atom(), reason :: atom()}) => pos_integer()
  } 
}

# Example:
%ClientReport{
  timestamp: ...,
  discarded_events: %{    
    {"error", "rate_limiting"} => 3,
    {"transaction", "queue_overflow"} => 324,
    {"error", "queue_overflow"} => 1
  }
}

We don't have {type, reason} tuples in there if the count is 0, which is why it's pos_integer(). We can just add them on the fly:

def add_discarded_event(client_report, type, reason) do
  Map.update(client_report.discarded_events, {type, reason}, 1, &(&1 + 1))
end
whatyouhide commented 1 month ago

Closed in #801, thanks @savhappy 💟