Skip to content

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

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

dajinchu
Copy link
Contributor

@dajinchu dajinchu commented Feb 7, 2025

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.

breadcrumbs = [map | breadcrumbs]
Enum.take(breadcrumbs, -1 * Sentry.Config.max_breadcrumbs())

Similar code exists here but is actually correct because Context.get_all returns the breadcrumb list reversed.

|> Enum.take(-1 * Config.max_breadcrumbs())

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@@ -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
Copy link
Contributor Author

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.

@whatyouhide
Copy link
Collaborator

@dajinchu thanks for the PR! What do other SDKs do, like the Python or Ruby ones? 🙃

@dajinchu
Copy link
Contributor Author

dajinchu commented Feb 9, 2025

@whatyouhide Javascript lib adds crumbs to the end of the list, and slices from the end of the list, thus retaining the most recent.

https://github.com/getsentry/sentry-javascript/blob/22f841ebc38ac0e7da4ae8f6750b43c410070996/packages/core/src/scope.ts#L482-L484

Comment on lines 426 to 427
breadcrumbs = [map | breadcrumbs]
Enum.take(breadcrumbs, -1 * Sentry.Config.max_breadcrumbs())
Enum.take(breadcrumbs, 1 * Sentry.Config.max_breadcrumbs())
Copy link
Collaborator

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())

?

Copy link
Contributor Author

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

@dajinchu dajinchu requested a review from whatyouhide February 9, 2025 17:18
@whatyouhide whatyouhide merged commit 3b3ff64 into getsentry:master Feb 10, 2025
3 of 4 checks passed
@whatyouhide
Copy link
Collaborator

Thank you @dajinchu 💟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants