Skip to content

Commit

Permalink
improove monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jjsaunier committed Feb 26, 2016
1 parent 8ad0607 commit 5ca9f59
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/KernelStack/NewrelicMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ class NewrelicMiddleware implements HttpKernelInterface, TerminableInterface
*/
protected $newRelic;

/** @var array */
protected $extras;

/**
* NewrelicMiddleware constructor.
*
* @param HttpKernelInterface $app
* @param string $applicationName
* @param $applicationName
* @param array $extras
*/
public function __construct(HttpKernelInterface $app, $applicationName)
public function __construct(HttpKernelInterface $app, $applicationName, array $extras = array())
{
$this->app = $app;
$this->applicationName = $applicationName;
$this->extras = $extras;

$this->newRelic = new \Intouch\Newrelic\Newrelic(false);
$this->newRelic->setAppName($applicationName);
Expand All @@ -57,6 +62,10 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
return $this->app->handle($request, $type, $catch);
}

foreach($this->extras as $name => $value){
$this->newRelic->addCustomParameter($name, $value);
}

$this->newRelic->addCustomParameter('url', $request->getPathInfo());
$this->newRelic->addCustomParameter('content_type', $request->getContentType());

Expand Down
13 changes: 13 additions & 0 deletions src/Logger/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ final class LoggerFactory
*/
private $bufferHandler;

/** @var array */
private $tags;

/**
* LoggerFactory constructor.
*
Expand All @@ -58,6 +61,7 @@ public function __construct($debug, $logDir)
$this->debug = $debug;
$this->logDir = $logDir;
$this->loggers = array();
$this->tags = array();

$webProcessor = new WebProcessor();
$this->tagProcessor = new TagProcessor();
Expand Down Expand Up @@ -91,9 +95,18 @@ public function flushBuffer()
*/
public function addTag($name, $value)
{
$this->tags[$name] = $value;
$this->tagProcessor->addTags(array($name => $value));
}

/**
* @return array
*/
public function getTags()
{
return $this->tags;
}

/**
* @param HandlerInterface $handler
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Utils/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pyrite\Utils;

use Monolog\Formatter\LineFormatter;
use Monolog\Handler\NewRelicHandler;
use Monolog\Handler\RavenHandler;
use Monolog\Handler\SlackHandler;
use Pyrite\Logger\LoggerFactory;
Expand Down Expand Up @@ -44,4 +45,20 @@ public static function attachSlack(LoggerFactory $factory, $token, $channel, $us
$factory->addHandler($slackHandler);
$factory->getLogger('app')->pushHandler($slackHandler);
}

/**
* @param LoggerFactory $factory
* @param string $appName
* @param bool $debug
*/
public static function attachNewRelic(LoggerFactory $factory, $appName, $debug)
{
if(true === $debug){
return;
}

$newRelicHandler = new NewRelicHandler(\Monolog\Logger::ERROR, true, $appName, true);
$factory->addHandler($newRelicHandler);
$factory->getLogger('app')->pushHandler($newRelicHandler);
}
}

0 comments on commit 5ca9f59

Please sign in to comment.