Skip to content

Commit

Permalink
allow users to configure maximum number of breadcrumbs
Browse files Browse the repository at this point in the history
This configuration option allows a user to specify the maximum number of
breadcrumbs when posting events to Sentry. The default value is 100.

This is helpful in situations in which long running processes can add a
large number of breadcrumbs resulting in failures to create Sentry
events when the message becomes too large.

Fixes #407
  • Loading branch information
jfmyers9 authored and mitchellhenke committed Aug 11, 2020
1 parent 8701e9d commit 3425b79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ The full range of options is the following:
| `filter` | False | | Module where the filter rules are defined (see [Filtering Exceptions](https://hexdocs.pm/sentry/Sentry.html#module-filtering-exceptions)) |
| `json_library` | False | `Jason` | |
| `log_level` | False | `:warn` | This sets the log level used when Sentry fails to send an event due to an invalid event or API error |
| `max_breadcrumbs` | False | 100 | This sets the maximum number of breadcrumbs to send to Sentry when creating an event |

Sentry uses the [hackney HTTP client](https://github.com/benoitc/hackney) for HTTP requests. Sentry starts its own hackney pool named `:sentry_pool` with a default connection pool of 50, and a connection timeout of 5000 milliseconds. The pool can be configured with the `hackney_pool_max_connections` and `hackney_pool_timeout` configuration keys. If you need to set other [hackney configurations](https://github.com/benoitc/hackney/blob/master/doc/hackney.md#request5) for things like a proxy, using your own pool or response timeouts, the `hackney_opts` configuration is passed directly to hackney for each request.

Expand Down
4 changes: 4 additions & 0 deletions lib/sentry/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ defmodule Sentry.Config do
get_config(:log_level, default: :warn, check_dsn: false)
end

def max_breadcrumbs do
get_config(:max_breadcrumbs, default: 100, check_dsn: false)
end

def permitted_log_level_values, do: @permitted_log_level_values

defp get_config(key, opts \\ []) when is_atom(key) do
Expand Down
5 changes: 4 additions & 1 deletion lib/sentry/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ defmodule Sentry.Event do
request_context
|> Map.merge(Keyword.get(opts, :request, %{}))

breadcrumbs = Keyword.get(opts, :breadcrumbs, []) ++ breadcrumbs_context
breadcrumbs =
Keyword.get(opts, :breadcrumbs, [])
|> Kernel.++(breadcrumbs_context)
|> Enum.take(-1 * Config.max_breadcrumbs())

level = Keyword.get(opts, :level, "error")

Expand Down
10 changes: 10 additions & 0 deletions test/event_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ defmodule Sentry.EventTest do
} = Event.create_event(message: "Test message")
end

test "respects the max_breadcrumbs configuration" do
breadcrumbs =
1..150
|> Enum.map(fn x -> %{message: "breadcrumb-#{x}"} end)

event = Event.create_event(message: "Test message", breadcrumbs: breadcrumbs)
assert length(event.breadcrumbs) == 100
assert event.breadcrumbs == Enum.take(breadcrumbs, -100)
end

test "only sending fingerprint when set" do
exception = RuntimeError.exception("error")
event = Sentry.Event.transform_exception(exception, fingerprint: ["hello", "world"])
Expand Down

0 comments on commit 3425b79

Please sign in to comment.