Skip to content
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

Fix max breadcrumbs limit when MaxBreadcrumbs is zero or lower #1145

Merged
merged 2 commits into from Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

## Fixes

- Fix max breadcrumbs limit when MaxBreadcrumbs is zero or lower ([#1145](https://github.com/getsentry/sentry-dotnet/pull/1145))

## 3.8.3

### Features
Expand Down
9 changes: 6 additions & 3 deletions src/Sentry/Scope.cs
Expand Up @@ -226,9 +226,12 @@ public void AddBreadcrumb(Breadcrumb breadcrumb)
}
}

var overflow = Breadcrumbs.Count - Options.MaxBreadcrumbs + 1;

if (overflow > 0)
if (Options.MaxBreadcrumbs <= 0)
{
//Always drop the breadcrumb.
return;
}
else if (Breadcrumbs.Count - Options.MaxBreadcrumbs + 1 > 0)
{
_breadcrumbs.TryDequeue(out _);
}
Expand Down
25 changes: 25 additions & 0 deletions test/Sentry.Tests/ScopeTests.cs
Expand Up @@ -254,5 +254,30 @@ public void ClearAttachments_HasAttachments_EmptyList()
//Assert
scope.Attachments.Should().BeEmpty();
}

[Theory]
[InlineData(0, -2, 0)]
[InlineData(0, -1, 0)]
[InlineData(0, 0, 0)]
[InlineData(0, 1, 1)]
[InlineData(0, 2, 1)]
[InlineData(1, 2, 2)]
[InlineData(2, 2, 2)]
public void AddBreadcrumb__AddBreadcrumb_RespectLimits(int initialCount, int maxBreadcrumbs, int expectedCount)
{
//Arrange
var scope = new Scope(new SentryOptions() { MaxBreadcrumbs = maxBreadcrumbs });

for (int i = 0; i < initialCount; i++)
{
scope.AddBreadcrumb(new Breadcrumb());
}

//Act
scope.AddBreadcrumb(new Breadcrumb());

//Assert
Assert.Equal(expectedCount, scope.Breadcrumbs.Count);
}
}
}