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

Release v3.29.0 #654

Merged
merged 7 commits into from
Oct 19, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

## 3.29.0 (2022-10-19)

### Enhancements

* The maximum number of breadcrumbs can now be configured between 0-100 (inclusive)
[#652](https://github.com/bugsnag/bugsnag-php/pull/652)

* Raised the default maximum number of breadcrumbs to 50
[#652](https://github.com/bugsnag/bugsnag-php/pull/652)

* Add a `Report::getFeatureFlags` method to allow accessing feature flags in callbacks
[#653](https://github.com/bugsnag/bugsnag-php/pull/653)

## 3.28.0 (2022-05-18)

### Enhancements
Expand Down
78 changes: 47 additions & 31 deletions src/Breadcrumbs/Recorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,88 @@ class Recorder implements Countable, Iterator
*
* @var int
*/
const MAX_ITEMS = 25;
private $maxBreadcrumbs = 50;

/**
* The recorded breadcrumbs.
*
* @var \Bugsnag\Breadcrumbs\Breadcrumb[]
*/
protected $breadcrumbs = [];
private $breadcrumbs = [];

/**
* The head position.
* The iteration position.
*
* @var int
*/
protected $head = 0;
private $position = 0;

/**
* The pointer position.
* Record a breadcrumb.
*
* @var int
* @param \Bugsnag\Breadcrumbs\Breadcrumb $breadcrumb
*
* @return void
*/
protected $pointer = 0;
public function record(Breadcrumb $breadcrumb)
{
$this->breadcrumbs[] = $breadcrumb;

// drop the oldest breadcrumb if we're over the max
if ($this->count() > $this->maxBreadcrumbs) {
array_shift($this->breadcrumbs);
}
}

/**
* The iteration position.
* Clear all recorded breadcrumbs.
*
* @var int
* @return void
*/
protected $position = 0;
public function clear()
{
$this->position = 0;
$this->breadcrumbs = [];
}

/**
* Record a breadcrumb.
* Set the maximum number of breadcrumbs that are allowed to be stored.
*
* We're recording a maximum of 25 breadcrumbs. Once we've recorded 25, we
* start wrapping back around and replacing the earlier ones. In order to
* indicate the start of the list, we advance a head pointer.
* This must be an integer between 0 and 100 (inclusive).
*
* @param \Bugsnag\Breadcrumbs\Breadcrumb $breadcrumb
* @param int $maxBreadcrumbs
*
* @return void
*/
public function record(Breadcrumb $breadcrumb)
public function setMaxBreadcrumbs($maxBreadcrumbs)
{
// advance the head by one if we've caught up
if ($this->breadcrumbs && $this->pointer === $this->head) {
$this->head = ($this->head + 1) % static::MAX_ITEMS;
if (!is_int($maxBreadcrumbs) || $maxBreadcrumbs < 0 || $maxBreadcrumbs > 100) {
error_log(
'Bugsnag Warning: maxBreadcrumbs should be an integer between 0 and 100 (inclusive)'
);

return;
}

// record the new breadcrumb
$this->breadcrumbs[$this->pointer] = $breadcrumb;
$this->maxBreadcrumbs = $maxBreadcrumbs;

// advance the pointer so we set the next breadcrumb in the next slot
$this->pointer = ($this->pointer + 1) % static::MAX_ITEMS;
// drop the oldest breadcrumbs if we're over the max
if ($this->count() > $this->maxBreadcrumbs) {
$this->breadcrumbs = array_slice(
$this->breadcrumbs,
$this->count() - $this->maxBreadcrumbs
);
}
}

/**
* Clear all recorded breadcrumbs.
* Get the maximum number of breadcrumbs that are allowed to be stored.
*
* @return void
* @return int
*/
public function clear()
public function getMaxBreadcrumbs()
{
$this->head = 0;
$this->pointer = 0;
$this->position = 0;
$this->breadcrumbs = [];
return $this->maxBreadcrumbs;
}

/**
Expand All @@ -102,7 +118,7 @@ public function count()
#[\ReturnTypeWillChange]
public function current()
{
return $this->breadcrumbs[($this->head + $this->position) % static::MAX_ITEMS];
return $this->breadcrumbs[$this->position];
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,24 @@ public function getRedactedKeys()
{
return $this->config->getRedactedKeys();
}

/**
* @param int $maxBreadcrumbs
*
* @return $this
*/
public function setMaxBreadcrumbs($maxBreadcrumbs)
{
$this->recorder->setMaxBreadcrumbs($maxBreadcrumbs);

return $this;
}

/**
* @return int
*/
public function getMaxBreadcrumbs()
{
return $this->recorder->getMaxBreadcrumbs();
}
}
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Configuration implements FeatureDataStore
*/
protected $notifier = [
'name' => 'Bugsnag PHP (Official)',
'version' => '3.28.0',
'version' => '3.29.0',
'url' => 'https://bugsnag.com',
];

Expand Down
15 changes: 3 additions & 12 deletions src/Internal/FeatureFlagDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,12 @@ public function clear()
}

/**
* Convert the list of stored feature flags into the format used by the
* Bugsnag Event API.
* Get the list of stored feature flags as an array.
*
* For example: [{ "featureFlag": "name", "variant": "variant" }, ...]
*
* @return array[]
* @phpstan-return list<array{featureFlag: string, variant?: string}>
* @return \Bugsnag\FeatureFlag[]
*/
public function toArray()
{
return array_map(
function (FeatureFlag $flag) {
return $flag->toArray();
},
$this->storage
);
return $this->storage;
}
}
17 changes: 16 additions & 1 deletion src/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,16 @@ public function clearFeatureFlags()
$this->featureFlags->clear();
}

/**
* Get the list of feature flags for this report.
*
* @return \Bugsnag\FeatureFlag[]
*/
public function getFeatureFlags()
{
return $this->featureFlags->toArray();
}

/**
* Set the current user.
*
Expand Down Expand Up @@ -763,7 +773,12 @@ public function toArray()
'metaData' => $this->cleanupObj($this->getMetaData(), true),
'unhandled' => $this->getUnhandled(),
'severityReason' => $this->getSeverityReason(),
'featureFlags' => $this->featureFlags->toArray(),
'featureFlags' => array_map(
function (FeatureFlag $flag) {
return $flag->toArray();
},
$this->featureFlags->toArray()
),
];

if ($hash = $this->getGroupingHash()) {
Expand Down
Loading