-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b8e36b
commit 5458916
Showing
16 changed files
with
356 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PHILKRA_APP_NAME=Wizaplace | ||
PHILKRA_APP_VERSION=1.0 | ||
PHILKRA_ENVIRONMENT=Dev | ||
PHILKRA_SERVER_URL=http=//172.17.0.1:8200 | ||
PHILKRA_SERVER_URL=http://172.17.0.1:8200 | ||
PHILKRA_SECRET_TOKEN=blabla | ||
|
||
ELASTIC_APM_ENABLED=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/vendor | ||
.idea/* | ||
.env | ||
composer.lock | ||
composer.lock | ||
.php_cs.cache | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
$finder = PhpCsFixer\Finder::create() | ||
->exclude('vendor') | ||
->in(__DIR__) | ||
->exclude('tests') | ||
->in(__DIR__) | ||
; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@Symfony' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'concat_space' => ['spacing' => 'one'], | ||
'increment_style' => ['style' => 'post'], | ||
'declare_strict_types' => true, | ||
'phpdoc_summary' => false | ||
]) | ||
->setFinder($finder) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
phpcs: | ||
vendor/bin/phpcs | ||
|
||
phpstan: | ||
vendor/bin/phpstan analyse | ||
|
||
phpcsfixer: | ||
vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes | ||
|
||
test: | ||
vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
# elastic-apm-symfony | ||
# Elastic APM Symfony Bundle | ||
Uses [wizaplace/wizaplace/elastic-apm-wrapper](https://github.com/wizaplace/elastic-apm-wrapper). | ||
|
||
|
||
## Installation | ||
|
||
1) Add the repositories to your _composer.json_ file: | ||
|
||
{ | ||
"type": "git", | ||
"url": "https://github.com/wizaplace/elastic-apm-symfony" | ||
}, | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/wizaplace/elastic-apm-wrapper" | ||
} | ||
2) Add the requirements in your _require_ section of the _composer.json_ file: | ||
` "philkra/elastic-apm-php-agent": "dev-master"` | ||
|
||
3) Require the bundle _composer require wizaplace/elastic-apm-symfony_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Wizacha\\ElasticApmBundle\\": "" | ||
"Wizacha\\ElasticApmBundle\\": "src/" | ||
}, | ||
"exclude-from-classmap": [ | ||
"/Tests/" | ||
|
@@ -28,5 +28,22 @@ | |
"psr-4": { | ||
"Wizacha\\ElasticApmBundle\\Tests\\": "/Tests/" | ||
} | ||
}, | ||
"require": { | ||
"philkra/elastic-apm-php-agent": "dev-master", | ||
"wizaplace/elastic-apm-wrapper": "^0.2.2", | ||
"symfony/symfony": ">=3.0 <4.3" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "git", | ||
"url": "[email protected]:wizaplace/elastic-apm-wrapper.git" | ||
} | ||
], | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.16", | ||
"phpstan/phpstan": "^0.12.5", | ||
"phpunit/phpunit": "^8.5", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd"> | ||
<arg name="basepath" value="."/> | ||
<arg name="colors"/> | ||
<arg name="report" value="diff"/> | ||
<rule ref="PSR12"/> | ||
<file>src</file> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" | ||
colors="true" | ||
bootstrap="./vendor/autoload.php" | ||
verbose="true" | ||
> | ||
<testsuite name="Elastic Apm Bundle Unit Tests"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
<php> | ||
<ini name="date.timezone" value="Europe/Paris"/> | ||
<ini name="xdebug.max_nesting_level" value="200"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wizacha\ElasticApmBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class ElasticApmExtension extends Extension | ||
{ | ||
public function load(array $config, ContainerBuilder $container) | ||
{ | ||
$loader = new YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../../config') | ||
); | ||
|
||
$loader->load(__DIR__ . '/../../config/services.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wizacha\ElasticApmBundle; | ||
|
||
use PhilKra\Events\Transaction; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Wizacha\ElasticApm\Service\AgentService; | ||
|
||
abstract class ElasticApmAbstractSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var AgentService */ | ||
protected $agentService; | ||
|
||
/** @var Transaction|null */ | ||
protected $transaction; | ||
|
||
public function __construct(AgentService $agentService) | ||
{ | ||
$this->agentService = $agentService; | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
if ($this->transaction instanceof Transaction) { | ||
$this->agentService->stopTransaction(); | ||
$this->transaction = null; | ||
} | ||
} | ||
|
||
public function onKernelTerminate() | ||
{ | ||
if ($this->transaction instanceof Transaction) { | ||
$this->agentService->stopTransaction(); | ||
$this->transaction = null; | ||
} | ||
} | ||
|
||
abstract public static function getSubscribedEvents(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wizacha\ElasticApmBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class ElasticApmBundle extends Bundle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wizacha\ElasticApmBundle; | ||
|
||
use PhilKra\Exception\Transaction\DuplicateTransactionNameException; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
class ElasticApmSubscriber extends ElasticApmAbstractSubscriber | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
KernelEvents::REQUEST => 'onKernelRequest', | ||
KernelEvents::EXCEPTION => ['onKernelException', 100], | ||
KernelEvents::TERMINATE => 'onKernelTerminate', | ||
]; | ||
} | ||
|
||
/** | ||
* @throws DuplicateTransactionNameException | ||
*/ | ||
public function onKernelRequest(GetResponseEvent $kernelEvent) | ||
{ | ||
if (true === $kernelEvent->isMasterRequest() && null === $this->transaction) { | ||
$this->transaction = $this->agentService | ||
->startTransaction( | ||
sprintf( | ||
'%s %s (%s)', | ||
$kernelEvent->getRequest()->getMethod(), | ||
$kernelEvent->getRequest()->get('_controller'), | ||
$kernelEvent->getRequest()->get('_route') | ||
) | ||
) | ||
->getTransaction(); | ||
} | ||
} | ||
|
||
public function onKernelException(GetResponseForExceptionEvent $kernelEvent) | ||
{ | ||
$this->agentService->error($kernelEvent->getException()); | ||
} | ||
} |
Oops, something went wrong.