Skip to content

Commit

Permalink
Use "adaptive" interactor as default. (#189)
Browse files Browse the repository at this point in the history
* Use "adaptive" interactor as default.

* Fixed broken tests

* Bugfix

* Added changelog

* improved logic
  • Loading branch information
Nyholm authored Jun 15, 2018
1 parent 8cd72e0 commit 2db2f3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Changelog



## v2.0.0-beta3

### Changed

- Moved "instrument" to the root level
- The `AdaptiveInteractor` is now the default interactor.

### Fixed

Expand Down
14 changes: 10 additions & 4 deletions DependencyInjection/EkinoNewRelicExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Ekino\NewRelicBundle\Listener\CommandListener;
use Ekino\NewRelicBundle\Listener\RequestListener;
use Ekino\NewRelicBundle\Listener\ResponseListener;
use Ekino\NewRelicBundle\NewRelic\AdaptiveInteractor;
use Ekino\NewRelicBundle\NewRelic\BlackholeInteractor;
use Ekino\NewRelicBundle\NewRelic\Config;
use Ekino\NewRelicBundle\NewRelic\LoggingInteractorDecorator;
Expand Down Expand Up @@ -145,12 +146,17 @@ private function getInteractorServiceId(array $config): string
return BlackholeInteractor::class;
}

if (isset($config['interactor'])) {
return $config['interactor'];
if (!isset($config['interactor'])) {
// Fallback on AdaptiveInteractor.
return AdaptiveInteractor::class;
}

// Fallback to see if the extension is loaded or not
return \extension_loaded('newrelic') ? NewRelicInteractor::class : BlackholeInteractor::class;
if ('auto' === $config['interactor']) {
// Check if the extension is loaded or not
return \extension_loaded('newrelic') ? NewRelicInteractor::class : BlackholeInteractor::class;
}

return $config['interactor'];
}

private function getTransactionNamingServiceId(array $config): string
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ The bundle provide a [Capifony](http://capifony.org) recipe to automate the depl
It makes one request per `app_name`, due roll-up names are not supported by Data REST API.
## Interactor services
The config key`ekino_new_relic.interactor` will accept a service ID to a service implementing `NewRelicInteractorInterface`.
This bundle comes with a few services that may be suitable for you.
| Configuration value | Description |
| ------------------- | ----------- |
| `Ekino\NewRelicBundle\NewRelic\AdaptiveInteractor` | This is the default interactor. It will check once per request if the NewRelic PHP extension is installed or not. It is a decorator for the `NewRelicInteractor` |
| `Ekino\NewRelicBundle\NewRelic\NewRelicInteractor` | This interactor communicates with NewRelic. It is the one decorator that actually does some work. |
| `Ekino\NewRelicBundle\NewRelic\BlackholeInteractor` | This interactor does nothing. |
| `auto` | This value will check if the NewRelic PHP extension is installed when you build your container. |
Note that if you set `ekino_new_relic.enabled: false` you will always use the `BlackholeInteractor` no matter what value
used for `ekino_new_relic.interactor`.
## Flow of the Request
1. A request comes in and the first thing we do is to `setApplicationName` so that we use the correct license key and name.
Expand Down
3 changes: 2 additions & 1 deletion Tests/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Ekino\NewRelicBundle\Tests;

use Ekino\NewRelicBundle\EkinoNewRelicBundle;
use Ekino\NewRelicBundle\NewRelic\AdaptiveInteractor;
use Ekino\NewRelicBundle\NewRelic\BlackholeInteractor;
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractor;
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testInitBundle()
$container = $this->getContainer();

$services = [
NewRelicInteractorInterface::class => BlackholeInteractor::class,
NewRelicInteractorInterface::class => AdaptiveInteractor::class,
BlackholeInteractor::class,
NewRelicInteractor::class,
];
Expand Down

0 comments on commit 2db2f3e

Please sign in to comment.