Skip to content

Commit 2dc3b97

Browse files
authored
feat!: remove MaxBreadcrumbs hard limit and change default to 100 (#1106)
1 parent c24b748 commit 2dc3b97

File tree

5 files changed

+37
-48
lines changed

5 files changed

+37
-48
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.36.0
4+
5+
### Breaking Changes
6+
7+
- Behavioral change for the `MaxBreadcrumbs` client option. Removed the hard limit of 100 breadcrumbs, allowing users to set a larger limit and also changed the default limit from 30 to 100 ([#1106](https://github.com/getsentry/sentry-go/pull/1106)))
8+
39
## 0.35.3
410

511
The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.35.3.

client.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ import (
2020
// The identifier of the SDK.
2121
const sdkIdentifier = "sentry.go"
2222

23-
// maxErrorDepth is the maximum number of errors reported in a chain of errors.
24-
// This protects the SDK from an arbitrarily long chain of wrapped errors.
25-
//
26-
// An additional consideration is that arguably reporting a long chain of errors
27-
// is of little use when debugging production errors with Sentry. The Sentry UI
28-
// is not optimized for long chains either. The top-level error together with a
29-
// stack trace is often the most useful information.
30-
const maxErrorDepth = 10
31-
32-
// defaultMaxSpans limits the default number of recorded spans per transaction. The limit is
33-
// meant to bound memory usage and prevent too large transaction events that
34-
// would be rejected by Sentry.
35-
const defaultMaxSpans = 1000
23+
const (
24+
// maxErrorDepth is the maximum number of errors reported in a chain of errors.
25+
// This protects the SDK from an arbitrarily long chain of wrapped errors.
26+
//
27+
// An additional consideration is that arguably reporting a long chain of errors
28+
// is of little use when debugging production errors with Sentry. The Sentry UI
29+
// is not optimized for long chains either. The top-level error together with a
30+
// stack trace is often the most useful information.
31+
maxErrorDepth = 10
32+
33+
// defaultMaxSpans limits the default number of recorded spans per transaction. The limit is
34+
// meant to bound memory usage and prevent too large transaction events that
35+
// would be rejected by Sentry.
36+
defaultMaxSpans = 1000
37+
38+
// defaultMaxBreadcrumbs is the default maximum number of breadcrumbs added to
39+
// an event. Can be overwritten with the MaxBreadcrumbs option.
40+
defaultMaxBreadcrumbs = 100
41+
)
3642

3743
// hostname is the host name reported by the kernel. It is precomputed once to
3844
// avoid syscalls when capturing events.

hub.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ const (
2020
RequestContextKey = contextKey(2)
2121
)
2222

23-
// defaultMaxBreadcrumbs is the default maximum number of breadcrumbs added to
24-
// an event. Can be overwritten with the maxBreadcrumbs option.
25-
const defaultMaxBreadcrumbs = 30
26-
27-
// maxBreadcrumbs is the absolute maximum number of breadcrumbs added to an
28-
// event. The maxBreadcrumbs option cannot be set higher than this value.
29-
const maxBreadcrumbs = 100
30-
3123
// currentHub is the initial Hub with no Client bound and an empty Scope.
3224
var currentHub = NewHub(nil, NewScope())
3325

@@ -291,7 +283,7 @@ func (hub *Hub) AddBreadcrumb(breadcrumb *Breadcrumb, hint *BreadcrumbHint) {
291283

292284
// If there's no client, just store it on the scope straight away
293285
if client == nil {
294-
hub.Scope().AddBreadcrumb(breadcrumb, maxBreadcrumbs)
286+
hub.Scope().AddBreadcrumb(breadcrumb, defaultMaxBreadcrumbs)
295287
return
296288
}
297289

@@ -301,8 +293,6 @@ func (hub *Hub) AddBreadcrumb(breadcrumb *Breadcrumb, hint *BreadcrumbHint) {
301293
return
302294
case limit == 0:
303295
limit = defaultMaxBreadcrumbs
304-
case limit > maxBreadcrumbs:
305-
limit = maxBreadcrumbs
306296
}
307297

308298
if client.options.BeforeBreadcrumb != nil {

hub_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,6 @@ func TestAddBreadcrumbSkipAllBreadcrumbsIfMaxBreadcrumbsIsLessThanZero(t *testin
247247
assertEqual(t, len(scope.breadcrumbs), 0)
248248
}
249249

250-
func TestAddBreadcrumbShouldNeverExceedMaxBreadcrumbsConst(t *testing.T) {
251-
hub, client, scope := setupHubTest()
252-
client.options.MaxBreadcrumbs = 1000
253-
254-
breadcrumb := &Breadcrumb{Message: "Breadcrumb"}
255-
256-
for i := 0; i < 111; i++ {
257-
hub.AddBreadcrumb(breadcrumb, nil)
258-
}
259-
260-
assertEqual(t, len(scope.breadcrumbs), 100)
261-
}
262-
263250
func TestAddBreadcrumbShouldWorkWithoutClient(t *testing.T) {
264251
scope := NewScope()
265252
hub := NewHub(nil, scope)

scope_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,15 @@ func TestScopeSetLevelOverrides(t *testing.T) {
330330

331331
func TestAddBreadcrumbAddsBreadcrumb(t *testing.T) {
332332
scope := NewScope()
333-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test"}, maxBreadcrumbs)
333+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test"}, defaultMaxBreadcrumbs)
334334
assertEqual(t, []*Breadcrumb{{Timestamp: testNow, Message: "test"}}, scope.breadcrumbs)
335335
}
336336

337337
func TestAddBreadcrumbAppendsBreadcrumb(t *testing.T) {
338338
scope := NewScope()
339-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test1"}, maxBreadcrumbs)
340-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test2"}, maxBreadcrumbs)
341-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test3"}, maxBreadcrumbs)
339+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test1"}, defaultMaxBreadcrumbs)
340+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test2"}, defaultMaxBreadcrumbs)
341+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test3"}, defaultMaxBreadcrumbs)
342342

343343
assertEqual(t, []*Breadcrumb{
344344
{Timestamp: testNow, Message: "test1"},
@@ -350,7 +350,7 @@ func TestAddBreadcrumbAppendsBreadcrumb(t *testing.T) {
350350
func TestAddBreadcrumbDefaultLimit(t *testing.T) {
351351
scope := NewScope()
352352
for i := 0; i < 101; i++ {
353-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test"}, maxBreadcrumbs)
353+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "test"}, defaultMaxBreadcrumbs)
354354
}
355355

356356
if len(scope.breadcrumbs) != 100 {
@@ -361,7 +361,7 @@ func TestAddBreadcrumbDefaultLimit(t *testing.T) {
361361
func TestAddBreadcrumbAddsTimestamp(t *testing.T) {
362362
scope := NewScope()
363363
before := time.Now()
364-
scope.AddBreadcrumb(&Breadcrumb{Message: "test"}, maxBreadcrumbs)
364+
scope.AddBreadcrumb(&Breadcrumb{Message: "test"}, defaultMaxBreadcrumbs)
365365
after := time.Now()
366366
ts := scope.breadcrumbs[0].Timestamp
367367

@@ -412,7 +412,7 @@ func TestScopeParentChangedInheritance(t *testing.T) {
412412
clone.SetExtra("foo", "bar")
413413
clone.SetLevel(LevelDebug)
414414
clone.SetFingerprint([]string{"foo"})
415-
clone.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, maxBreadcrumbs)
415+
clone.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, defaultMaxBreadcrumbs)
416416
clone.AddAttachment(&Attachment{Filename: "foo.txt", Payload: []byte("foo")})
417417
clone.SetUser(User{ID: "foo"})
418418
r1 := httptest.NewRequest("GET", "/foo", nil)
@@ -427,7 +427,7 @@ func TestScopeParentChangedInheritance(t *testing.T) {
427427
scope.SetExtra("foo", "baz")
428428
scope.SetLevel(LevelFatal)
429429
scope.SetFingerprint([]string{"bar"})
430-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "bar"}, maxBreadcrumbs)
430+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "bar"}, defaultMaxBreadcrumbs)
431431
scope.AddAttachment(&Attachment{Filename: "bar.txt", Payload: []byte("bar")})
432432
scope.SetUser(User{ID: "bar"})
433433
r2 := httptest.NewRequest("GET", "/bar", nil)
@@ -469,7 +469,7 @@ func TestScopeChildOverrideInheritance(t *testing.T) {
469469
scope.SetExtra("foo", "baz")
470470
scope.SetLevel(LevelFatal)
471471
scope.SetFingerprint([]string{"bar"})
472-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "bar"}, maxBreadcrumbs)
472+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "bar"}, defaultMaxBreadcrumbs)
473473
scope.AddAttachment(&Attachment{Filename: "bar.txt", Payload: []byte("bar")})
474474
scope.SetUser(User{ID: "bar"})
475475
r1 := httptest.NewRequest("GET", "/bar", nil)
@@ -488,7 +488,7 @@ func TestScopeChildOverrideInheritance(t *testing.T) {
488488
clone.SetExtra("foo", "bar")
489489
clone.SetLevel(LevelDebug)
490490
clone.SetFingerprint([]string{"foo"})
491-
clone.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, maxBreadcrumbs)
491+
clone.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, defaultMaxBreadcrumbs)
492492
clone.AddAttachment(&Attachment{Filename: "foo.txt", Payload: []byte("foo")})
493493
clone.SetUser(User{ID: "foo"})
494494
r2 := httptest.NewRequest("GET", "/foo", nil)
@@ -560,7 +560,7 @@ func TestClearAndReconfigure(t *testing.T) {
560560
scope.SetExtra("foo", "bar")
561561
scope.SetLevel(LevelDebug)
562562
scope.SetFingerprint([]string{"foo"})
563-
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, maxBreadcrumbs)
563+
scope.AddBreadcrumb(&Breadcrumb{Timestamp: testNow, Message: "foo"}, defaultMaxBreadcrumbs)
564564
scope.AddAttachment(&Attachment{Filename: "foo.txt", Payload: []byte("foo")})
565565
scope.SetUser(User{ID: "foo"})
566566
r := httptest.NewRequest("GET", "/foo", nil)

0 commit comments

Comments
 (0)