Skip to content

Commit 362b93b

Browse files
authored
Release v3.29.0
2 parents 88bac64 + 54f2e34 commit 362b93b

12 files changed

Lines changed: 398 additions & 98 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Changelog
22
=========
33

4+
## 3.29.0 (2022-10-19)
5+
6+
### Enhancements
7+
8+
* The maximum number of breadcrumbs can now be configured between 0-100 (inclusive)
9+
[#652](https://github.com/bugsnag/bugsnag-php/pull/652)
10+
11+
* Raised the default maximum number of breadcrumbs to 50
12+
[#652](https://github.com/bugsnag/bugsnag-php/pull/652)
13+
14+
* Add a `Report::getFeatureFlags` method to allow accessing feature flags in callbacks
15+
[#653](https://github.com/bugsnag/bugsnag-php/pull/653)
16+
417
## 3.28.0 (2022-05-18)
518

619
### Enhancements

src/Breadcrumbs/Recorder.php

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,88 @@ class Recorder implements Countable, Iterator
1515
*
1616
* @var int
1717
*/
18-
const MAX_ITEMS = 25;
18+
private $maxBreadcrumbs = 50;
1919

2020
/**
2121
* The recorded breadcrumbs.
2222
*
2323
* @var \Bugsnag\Breadcrumbs\Breadcrumb[]
2424
*/
25-
protected $breadcrumbs = [];
25+
private $breadcrumbs = [];
2626

2727
/**
28-
* The head position.
28+
* The iteration position.
2929
*
3030
* @var int
3131
*/
32-
protected $head = 0;
32+
private $position = 0;
3333

3434
/**
35-
* The pointer position.
35+
* Record a breadcrumb.
3636
*
37-
* @var int
37+
* @param \Bugsnag\Breadcrumbs\Breadcrumb $breadcrumb
38+
*
39+
* @return void
3840
*/
39-
protected $pointer = 0;
41+
public function record(Breadcrumb $breadcrumb)
42+
{
43+
$this->breadcrumbs[] = $breadcrumb;
44+
45+
// drop the oldest breadcrumb if we're over the max
46+
if ($this->count() > $this->maxBreadcrumbs) {
47+
array_shift($this->breadcrumbs);
48+
}
49+
}
4050

4151
/**
42-
* The iteration position.
52+
* Clear all recorded breadcrumbs.
4353
*
44-
* @var int
54+
* @return void
4555
*/
46-
protected $position = 0;
56+
public function clear()
57+
{
58+
$this->position = 0;
59+
$this->breadcrumbs = [];
60+
}
4761

4862
/**
49-
* Record a breadcrumb.
63+
* Set the maximum number of breadcrumbs that are allowed to be stored.
5064
*
51-
* We're recording a maximum of 25 breadcrumbs. Once we've recorded 25, we
52-
* start wrapping back around and replacing the earlier ones. In order to
53-
* indicate the start of the list, we advance a head pointer.
65+
* This must be an integer between 0 and 100 (inclusive).
5466
*
55-
* @param \Bugsnag\Breadcrumbs\Breadcrumb $breadcrumb
67+
* @param int $maxBreadcrumbs
5668
*
5769
* @return void
5870
*/
59-
public function record(Breadcrumb $breadcrumb)
71+
public function setMaxBreadcrumbs($maxBreadcrumbs)
6072
{
61-
// advance the head by one if we've caught up
62-
if ($this->breadcrumbs && $this->pointer === $this->head) {
63-
$this->head = ($this->head + 1) % static::MAX_ITEMS;
73+
if (!is_int($maxBreadcrumbs) || $maxBreadcrumbs < 0 || $maxBreadcrumbs > 100) {
74+
error_log(
75+
'Bugsnag Warning: maxBreadcrumbs should be an integer between 0 and 100 (inclusive)'
76+
);
77+
78+
return;
6479
}
6580

66-
// record the new breadcrumb
67-
$this->breadcrumbs[$this->pointer] = $breadcrumb;
81+
$this->maxBreadcrumbs = $maxBreadcrumbs;
6882

69-
// advance the pointer so we set the next breadcrumb in the next slot
70-
$this->pointer = ($this->pointer + 1) % static::MAX_ITEMS;
83+
// drop the oldest breadcrumbs if we're over the max
84+
if ($this->count() > $this->maxBreadcrumbs) {
85+
$this->breadcrumbs = array_slice(
86+
$this->breadcrumbs,
87+
$this->count() - $this->maxBreadcrumbs
88+
);
89+
}
7190
}
7291

7392
/**
74-
* Clear all recorded breadcrumbs.
93+
* Get the maximum number of breadcrumbs that are allowed to be stored.
7594
*
76-
* @return void
95+
* @return int
7796
*/
78-
public function clear()
97+
public function getMaxBreadcrumbs()
7998
{
80-
$this->head = 0;
81-
$this->pointer = 0;
82-
$this->position = 0;
83-
$this->breadcrumbs = [];
99+
return $this->maxBreadcrumbs;
84100
}
85101

86102
/**
@@ -102,7 +118,7 @@ public function count()
102118
#[\ReturnTypeWillChange]
103119
public function current()
104120
{
105-
return $this->breadcrumbs[($this->head + $this->position) % static::MAX_ITEMS];
121+
return $this->breadcrumbs[$this->position];
106122
}
107123

108124
/**

src/Client.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,4 +1066,24 @@ public function getRedactedKeys()
10661066
{
10671067
return $this->config->getRedactedKeys();
10681068
}
1069+
1070+
/**
1071+
* @param int $maxBreadcrumbs
1072+
*
1073+
* @return $this
1074+
*/
1075+
public function setMaxBreadcrumbs($maxBreadcrumbs)
1076+
{
1077+
$this->recorder->setMaxBreadcrumbs($maxBreadcrumbs);
1078+
1079+
return $this;
1080+
}
1081+
1082+
/**
1083+
* @return int
1084+
*/
1085+
public function getMaxBreadcrumbs()
1086+
{
1087+
return $this->recorder->getMaxBreadcrumbs();
1088+
}
10691089
}

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Configuration implements FeatureDataStore
8585
*/
8686
protected $notifier = [
8787
'name' => 'Bugsnag PHP (Official)',
88-
'version' => '3.28.0',
88+
'version' => '3.29.0',
8989
'url' => 'https://bugsnag.com',
9090
];
9191

src/Internal/FeatureFlagDelegate.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,12 @@ public function clear()
7474
}
7575

7676
/**
77-
* Convert the list of stored feature flags into the format used by the
78-
* Bugsnag Event API.
77+
* Get the list of stored feature flags as an array.
7978
*
80-
* For example: [{ "featureFlag": "name", "variant": "variant" }, ...]
81-
*
82-
* @return array[]
83-
* @phpstan-return list<array{featureFlag: string, variant?: string}>
79+
* @return \Bugsnag\FeatureFlag[]
8480
*/
8581
public function toArray()
8682
{
87-
return array_map(
88-
function (FeatureFlag $flag) {
89-
return $flag->toArray();
90-
},
91-
$this->storage
92-
);
83+
return $this->storage;
9384
}
9485
}

src/Report.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,16 @@ public function clearFeatureFlags()
632632
$this->featureFlags->clear();
633633
}
634634

635+
/**
636+
* Get the list of feature flags for this report.
637+
*
638+
* @return \Bugsnag\FeatureFlag[]
639+
*/
640+
public function getFeatureFlags()
641+
{
642+
return $this->featureFlags->toArray();
643+
}
644+
635645
/**
636646
* Set the current user.
637647
*
@@ -763,7 +773,12 @@ public function toArray()
763773
'metaData' => $this->cleanupObj($this->getMetaData(), true),
764774
'unhandled' => $this->getUnhandled(),
765775
'severityReason' => $this->getSeverityReason(),
766-
'featureFlags' => $this->featureFlags->toArray(),
776+
'featureFlags' => array_map(
777+
function (FeatureFlag $flag) {
778+
return $flag->toArray();
779+
},
780+
$this->featureFlags->toArray()
781+
),
767782
];
768783

769784
if ($hash = $this->getGroupingHash()) {

0 commit comments

Comments
 (0)