-
-
Notifications
You must be signed in to change notification settings - Fork 200
Keep Newest Breadcrumbs Instead of Oldest #858
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
Keep Newest Breadcrumbs Instead of Oldest #858
Conversation
@@ -39,6 +39,16 @@ defmodule Sentry.ContextTest do | |||
assert first_breadcrumb.timestamp <= second_breadcrumb.timestamp | |||
end | |||
|
|||
test "retains most recent breadcrumbs when exceeding max" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails on master.
@dajinchu thanks for the PR! What do other SDKs do, like the Python or Ruby ones? 🙃 |
@whatyouhide Javascript lib adds crumbs to the end of the list, and slices from the end of the list, thus retaining the most recent. |
lib/sentry/context.ex
Outdated
breadcrumbs = [map | breadcrumbs] | ||
Enum.take(breadcrumbs, -1 * Sentry.Config.max_breadcrumbs()) | ||
Enum.take(breadcrumbs, 1 * Sentry.Config.max_breadcrumbs()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you maybe rewrite this code to
Enum.take([map | breadcrumbs], Sentry.Config.max_breadcrumbs())
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah haha what was I even thinking
Thank you @dajinchu 💟 |
Currently, exceeding max_breadcrumbs causes only the oldest breadcrumbs to be retained, instead of the newest, as I would have expected. I believe this is a bug?
It's caused by the following code, which inserts the newest breadcrumb at the front of the list, but then trims the list from the back.
sentry-elixir/lib/sentry/context.ex
Lines 426 to 427 in 8ee657f
Similar code exists here but is actually correct because
Context.get_all
returns the breadcrumb list reversed.sentry-elixir/lib/sentry/event.ex
Line 216 in 8ee657f