Skip to content

Commit

Permalink
add flag management on subscriber (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-mercier authored and ecourtial committed Jan 23, 2020
1 parent 450e4c9 commit 3f14891
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/ApmBundle.php

This file was deleted.

9 changes: 9 additions & 0 deletions src/ElasticApmAbstractSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ public function __destruct()

public function onKernelTerminate()
{
if ($this->isDisabled()) {
return $this;
}

if ($this->transaction instanceof Transaction) {
$this->agentService->stopTransaction();
$this->transaction = null;
}
}

public function isDisabled(): bool
{
return false === $this->agentService->getApmEnabled();
}

abstract public static function getSubscribedEvents();
}
8 changes: 8 additions & 0 deletions src/ElasticApmSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static function getSubscribedEvents()
*/
public function onKernelRequest(GetResponseEvent $kernelEvent)
{
if ($this->isDisabled()) {
return $this;
}

if (true === $kernelEvent->isMasterRequest() && null === $this->transaction) {
$this->transaction = $this->agentService
->startTransaction(
Expand All @@ -47,6 +51,10 @@ public function onKernelRequest(GetResponseEvent $kernelEvent)

public function onKernelException(GetResponseForExceptionEvent $kernelEvent)
{
if ($this->isDisabled()) {
return $this;
}

$this->agentService->error($kernelEvent->getException());
}
}

0 comments on commit 3f14891

Please sign in to comment.