Skip to content

Commit

Permalink
Release v2.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines authored May 20, 2022
2 parents b800261 + 7276a35 commit 512c183
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## 2.24.0 (2022-05-20)

### Enhancements

* New APIs to support feature flag and experiment functionality. For more information, please see https://docs.bugsnag.com/product/features-experiments.
[#153](https://github.com/bugsnag/bugsnag-laravel/pull/487)

## 2.23.0 (2022-02-09)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.5",
"bugsnag/bugsnag": "^3.27.0",
"bugsnag/bugsnag": "^3.28.0",
"bugsnag/bugsnag-psr-logger": "^1.4|^2.0",
"illuminate/contracts": "^5.0|^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "^5.0|^6.0|^7.0|^8.0|^9.0",
Expand Down
19 changes: 19 additions & 0 deletions config/bugsnag.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,23 @@
*/

'redacted_keys' => empty(env('BUGSNAG_REDACTED_KEYS')) ? null : explode(',', env('BUGSNAG_REDACTED_KEYS')),

/*
|--------------------------------------------------------------------------
| Feature flags
|--------------------------------------------------------------------------
|
| An array of feature flags to add to all reports.
|
| Each element in the array must have a "name" key and can optionally have a
| "variant" key, for example:
|
| [
| ['name' => 'example without a variant'],
| ['name' => 'example with a variant', 'variant' => 'example of a variant'],
| ]
|
*/

'feature_flags' => [],
];
21 changes: 20 additions & 1 deletion src/BugsnagServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Bugsnag\Callbacks\CustomUser;
use Bugsnag\Client;
use Bugsnag\Configuration;
use Bugsnag\FeatureFlag;
use Bugsnag\PsrLogger\BugsnagLogger;
use Bugsnag\PsrLogger\MultiLogger as BaseMultiLogger;
use Bugsnag\Report;
Expand Down Expand Up @@ -36,7 +37,7 @@ class BugsnagServiceProvider extends ServiceProvider
*
* @var string
*/
const VERSION = '2.23.0';
const VERSION = '2.24.0';

/**
* Boot the service provider.
Expand Down Expand Up @@ -245,6 +246,24 @@ public function register()
$client->setRedactedKeys($config['redacted_keys']);
}

if (isset($config['feature_flags']) && is_array($config['feature_flags']) && $config['feature_flags'] !== []) {
$featureFlags = [];

foreach ($config['feature_flags'] as $flag) {
if (!is_array($flag) || !array_key_exists('name', $flag)) {
continue;
}

if (array_key_exists('variant', $flag)) {
$featureFlags[] = new FeatureFlag($flag['name'], $flag['variant']);
} else {
$featureFlags[] = new FeatureFlag($flag['name']);
}
}

$client->addFeatureFlags($featureFlags);
}

return $client;
});

Expand Down
49 changes: 49 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,53 @@ public function memoryLimitIncreaseProvider()
[1024 * 1024 * 20],
];
}

public function testFeatureFlagsCanBeSetFromConfig()
{
/** @var \Illuminate\Config\Repository $laravelConfig */
$laravelConfig = $this->app->config;
$bugsnagConfig = $laravelConfig->get('bugsnag');
$bugsnagConfig['feature_flags'] = [
['name' => 'flag1'],
['name' => 'flag2', 'variant' => 'yes'],
['not name' => 'flag3'],
['name' => 'flag4', 'not variant' => 'xyz'],
];

$laravelConfig->set('bugsnag', $bugsnagConfig);

/** @var Client $client */
$client = $this->app->make(Client::class);

$this->assertInstanceOf(Client::class, $client);

$expected = [
['featureFlag' => 'flag1'],
['featureFlag' => 'flag2', 'variant' => 'yes'],
['featureFlag' => 'flag4'],
];

$actual = $client->getConfig()->getFeatureFlagsCopy()->toArray();

$this->assertSame($expected, $actual);
}

public function testFeatureFlagsAreNotSetWhenNotAnArray()
{
/** @var \Illuminate\Config\Repository $laravelConfig */
$laravelConfig = $this->app->config;
$bugsnagConfig = $laravelConfig->get('bugsnag');
$bugsnagConfig['feature_flags'] = new \stdClass();

$laravelConfig->set('bugsnag', $bugsnagConfig);

/** @var Client $client */
$client = $this->app->make(Client::class);

$this->assertInstanceOf(Client::class, $client);

$actual = $client->getConfig()->getFeatureFlagsCopy()->toArray();

$this->assertSame([], $actual);
}
}

0 comments on commit 512c183

Please sign in to comment.