Skip to content

Commit

Permalink
Release v3.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines authored Feb 10, 2021
2 parents 5a62ea2 + 78b9b3a commit 36d7a22
Show file tree
Hide file tree
Showing 29 changed files with 1,249 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
guzzle-version: '^7.0'
- php-version: 8.0
guzzle-version: '^7.0'
composer-flags: '--ignore-platform-reqs'

steps:
- uses: actions/checkout@v2
Expand All @@ -28,6 +27,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
extensions: intl, mbstring

- run: composer validate

Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Changelog
=========

## 3.26.0 (2021-02-10)

### Enhancements

* Out of memory errors will now be reported by increasing the memory limit by 5 MiB. Use the new `memoryLimitIncrease` configuration option to change the amount of memory, or set it to `null` to disable the increase entirely.
[#621](https://github.com/bugsnag/bugsnag-php/pull/621)

* Add a "discard classes" configuration option that allows events to be discarded based on the exception class name or PHP error name
[#622](https://github.com/bugsnag/bugsnag-php/pull/622)

* Add a "redacted keys" configuration option. This is similar to `filters` but allows both strings and regexes. String matching is exact but case-insensitive. Regex matching allows for partial and wildcard matching.
[#623](https://github.com/bugsnag/bugsnag-php/pull/623)

### Deprecations

* The `filters` configuration option is now deprecated as `redactedKeys` can express everything that filters could and more.

## 3.25.0 (2020-11-25)

### Enhancements
Expand Down
82 changes: 81 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Bugsnag\Internal\GuzzleCompat;
use Bugsnag\Middleware\BreadcrumbData;
use Bugsnag\Middleware\CallbackBridge;
use Bugsnag\Middleware\DiscardClasses;
use Bugsnag\Middleware\NotificationSkipper;
use Bugsnag\Middleware\SessionData;
use Bugsnag\Request\BasicResolver;
Expand Down Expand Up @@ -137,6 +138,7 @@ public function __construct(
$this->sessionTracker = new SessionTracker($config, $this->http);

$this->registerMiddleware(new NotificationSkipper($config));
$this->registerMiddleware(new DiscardClasses($config));
$this->registerMiddleware(new BreadcrumbData($this->recorder));
$this->registerMiddleware(new SessionData($this));

Expand Down Expand Up @@ -530,6 +532,8 @@ public function shouldNotify()
*
* Eg. ['password', 'credit_card'].
*
* @deprecated Use redactedKeys instead
*
* @param string[] $filters an array of metaData filters
*
* @return $this
Expand All @@ -544,7 +548,9 @@ public function setFilters(array $filters)
/**
* Get the array of metaData filters.
*
* @var string
* @deprecated Use redactedKeys instead
*
* @var string[]
*/
public function getFilters()
{
Expand Down Expand Up @@ -935,4 +941,78 @@ public function getSessionClient()
{
return $this->config->getSessionClient();
}

/**
* Set the amount to increase the memory_limit when an OOM is triggered.
*
* This is an amount of bytes or 'null' to disable increasing the limit.
*
* @param int|null $value
*/
public function setMemoryLimitIncrease($value)
{
return $this->config->setMemoryLimitIncrease($value);
}

/**
* Get the amount to increase the memory_limit when an OOM is triggered.
*
* This will return 'null' if this feature is disabled.
*
* @return int|null
*/
public function getMemoryLimitIncrease()
{
return $this->config->getMemoryLimitIncrease();
}

/**
* Set the array of classes that should not be sent to Bugsnag.
*
* @param array $discardClasses
*
* @return $this
*/
public function setDiscardClasses(array $discardClasses)
{
$this->config->setDiscardClasses($discardClasses);

return $this;
}

/**
* Get the array of classes that should not be sent to Bugsnag.
*
* This can contain both fully qualified class names and regular expressions.
*
* @var array
*/
public function getDiscardClasses()
{
return $this->config->getDiscardClasses();
}

/**
* Set the array of metadata keys that should be redacted.
*
* @param string[] $redactedKeys
*
* @return $this
*/
public function setRedactedKeys(array $redactedKeys)
{
$this->config->setRedactedKeys($redactedKeys);

return $this;
}

/**
* Get the array of metadata keys that should be redacted.
*
* @var string[]
*/
public function getRedactedKeys()
{
return $this->config->getRedactedKeys();
}
}
111 changes: 109 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Configuration
/**
* The strings to filter out from metaData.
*
* @deprecated Use redactedKeys instead
*
* @var string[]
*/
protected $filters = [
Expand Down Expand Up @@ -82,7 +84,7 @@ class Configuration
*/
protected $notifier = [
'name' => 'Bugsnag PHP (Official)',
'version' => '3.25.0',
'version' => '3.26.0',
'url' => 'https://bugsnag.com',
];

Expand Down Expand Up @@ -152,6 +154,31 @@ class Configuration
*/
protected $buildEndpoint = self::BUILD_ENDPOINT;

/**
* The amount to increase the memory_limit to handle an OOM.
*
* The default is 5MiB and can be disabled by setting it to 'null'
*
* @var int|null
*/
protected $memoryLimitIncrease = 5242880;

/**
* An array of classes that should not be sent to Bugsnag.
*
* This can contain both fully qualified class names and regular expressions.
*
* @var array
*/
protected $discardClasses = [];

/**
* An array of metadata keys that should be redacted.
*
* @var string[]
*/
protected $redactedKeys = [];

/**
* Create a new config instance.
*
Expand Down Expand Up @@ -243,6 +270,8 @@ public function shouldNotify()
*
* Eg. ['password', 'credit_card'].
*
* @deprecated Use redactedKeys instead
*
* @param string[] $filters an array of metaData filters
*
* @return $this
Expand All @@ -257,7 +286,9 @@ public function setFilters(array $filters)
/**
* Get the array of metaData filters.
*
* @var string
* @deprecated Use redactedKeys instead
*
* @var string[]
*/
public function getFilters()
{
Expand Down Expand Up @@ -766,4 +797,80 @@ public function getSessionClient()

return $this->sessionClient;
}

/**
* Set the amount to increase the memory_limit when an OOM is triggered.
*
* This is an amount of bytes or 'null' to disable increasing the limit.
*
* @param int|null $value
*/
public function setMemoryLimitIncrease($value)
{
$this->memoryLimitIncrease = $value;

return $this;
}

/**
* Get the amount to increase the memory_limit when an OOM is triggered.
*
* This will return 'null' if this feature is disabled.
*
* @return int|null
*/
public function getMemoryLimitIncrease()
{
return $this->memoryLimitIncrease;
}

/**
* Set the array of classes that should not be sent to Bugsnag.
*
* @param array $discardClasses
*
* @return $this
*/
public function setDiscardClasses(array $discardClasses)
{
$this->discardClasses = $discardClasses;

return $this;
}

/**
* Get the array of classes that should not be sent to Bugsnag.
*
* This can contain both fully qualified class names and regular expressions.
*
* @var array
*/
public function getDiscardClasses()
{
return $this->discardClasses;
}

/**
* Set the array of metadata keys that should be redacted.
*
* @param string[] $redactedKeys
*
* @return $this
*/
public function setRedactedKeys(array $redactedKeys)
{
$this->redactedKeys = $redactedKeys;

return $this;
}

/**
* Get the array of metadata keys that should be redacted.
*
* @var string[]
*/
public function getRedactedKeys()
{
return $this->redactedKeys;
}
}
36 changes: 36 additions & 0 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ class Handler
*/
protected $previousExceptionHandler;

/**
* A bit of reserved memory to ensure we are able to increase the memory
* limit on an OOM.
*
* We can't reserve all of the memory that we need to send OOM reports
* because this would have a big overhead on every request, instead of just
* on shutdown in requests with errors.
*
* @var string|null
*/
private $reservedMemory;

/**
* A regex that matches PHP OOM errors.
*
* @var string
*/
private $oomRegex = '/^Allowed memory size of (\d+) bytes exhausted \(tried to allocate \d+ bytes\)/';

/**
* Whether the shutdown handler will run.
*
Expand Down Expand Up @@ -136,6 +155,9 @@ public function registerExceptionHandler($callPrevious)
*/
public function registerShutdownHandler()
{
// Reserve some memory that we can free in the shutdown handler
$this->reservedMemory = str_repeat(' ', 1024 * 32);

register_shutdown_function([$this, 'shutdownHandler']);
}

Expand Down Expand Up @@ -267,6 +289,9 @@ public function errorHandler($errno, $errstr, $errfile = '', $errline = 0)
*/
public function shutdownHandler()
{
// Free the reserved memory to give ourselves some room to work
$this->reservedMemory = null;

// If we're disabled, do nothing. This avoids reporting twice if the
// exception handler is forcing the native PHP handler to run
if (!self::$enableShutdownHandler) {
Expand All @@ -275,6 +300,17 @@ public function shutdownHandler()

$lastError = error_get_last();

// If this is an OOM and memory increase is enabled, bump the memory
// limit so we can report it
if ($lastError !== null
&& $this->client->getMemoryLimitIncrease() !== null
&& preg_match($this->oomRegex, $lastError['message'], $matches) === 1
) {
$currentMemoryLimit = (int) $matches[1];

ini_set('memory_limit', $currentMemoryLimit + $this->client->getMemoryLimitIncrease());
}

// Check if a fatal error caused this shutdown
if (!is_null($lastError) && ErrorTypes::isFatal($lastError['type']) && !$this->client->getConfig()->shouldIgnoreErrorCode($lastError['type'])) {
$report = Report::fromPHPError(
Expand Down
Loading

0 comments on commit 36d7a22

Please sign in to comment.