File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ has tags => sub { {} };
2020has transaction_name => undef ;
2121has user => undef ;
2222
23+ my $DEFAULT_MAX_BREADCRUMBS = 100;
24+
2325sub set_span ($self , $span ) {
2426 $self -> span($span );
2527 return $self ;
@@ -92,7 +94,15 @@ sub clear ($self) {
9294
9395sub add_breadcrumb ($self , $breadcrumb ) {
9496 $breadcrumb -> {timestamp } //= time ;
95- push @{ $self -> breadcrumbs }, $breadcrumb ;
97+
98+ my $breadcrumbs = $self -> breadcrumbs;
99+
100+ my $max_crumbs = $ENV {SENTRY_MAX_BREADCRUMBS } || $DEFAULT_MAX_BREADCRUMBS ;
101+ if (scalar $breadcrumbs -> @* >= $max_crumbs ) {
102+ shift $breadcrumbs -> @*;
103+ }
104+
105+ push $breadcrumbs -> @*, $breadcrumb ;
96106}
97107
98108sub clear_breadcrumbs ($self ) {
Original file line number Diff line number Diff line change @@ -89,6 +89,20 @@ describe 'Sentry::Hub::Scope' => sub {
8989 lives_ok { Sentry::Hub::Scope-> new-> set_extras({ foo => ' bar' }) };
9090 };
9191 };
92+
93+ describe ' add_breadcrumb' => sub {
94+ it ' limits breadcrumb items' => sub {
95+ local $ENV {SENTRY_MAX_BREADCRUMBS } = 2;
96+
97+ $scope -> add_breadcrumb({ message => ' foo' });
98+ $scope -> add_breadcrumb({ message => ' bar' });
99+ $scope -> add_breadcrumb({ message => ' baz' });
100+
101+ is scalar $scope -> breadcrumbs-> @*, 2;
102+ is $scope -> breadcrumbs-> [0]-> {message }, ' bar' ;
103+ is $scope -> breadcrumbs-> [1]-> {message }, ' baz' ;
104+ };
105+ };
92106};
93107
94108runtests;
You can’t perform that action at this time.
0 commit comments