diff --git a/src/Monolog/Handler/RavenHandler.php b/src/Monolog/Handler/RavenHandler.php index cba15f74..90758274 100644 --- a/src/Monolog/Handler/RavenHandler.php +++ b/src/Monolog/Handler/RavenHandler.php @@ -38,6 +38,12 @@ class RavenHandler extends AbstractProcessingHandler Logger::EMERGENCY => Raven_Client::FATAL, ); + /** + * @var string should represent the current version of the calling + * software. Can be any string (git commit, version number) + */ + private $release; + /** * @var Raven_Client the client object that sends the message to the server */ @@ -169,6 +175,10 @@ class RavenHandler extends AbstractProcessingHandler $options['extra']['extra'] = $record['extra']; } + if (!empty($this->release) && !isset($options['release'])) { + $options['release'] = $this->release; + } + if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) { $options['extra']['message'] = $record['formatted']; $this->ravenClient->captureException($record['context']['exception'], $options); @@ -208,4 +218,14 @@ class RavenHandler extends AbstractProcessingHandler { return array('checksum', 'release'); } + + /** + * @param string $value + */ + public function setRelease($value) + { + $this->release = $value; + + return $this; + } } diff --git a/tests/Monolog/Handler/RavenHandlerTest.php b/tests/Monolog/Handler/RavenHandlerTest.php index 9f55af64..a7c4845f 100644 --- a/tests/Monolog/Handler/RavenHandlerTest.php +++ b/tests/Monolog/Handler/RavenHandlerTest.php @@ -204,6 +204,22 @@ class RavenHandlerTest extends TestCase $this->assertSame($formatter, $handler->getBatchFormatter()); } + public function testRelease() + { + $ravenClient = $this->getRavenClient(); + $handler = $this->getHandler($ravenClient); + $release = 'v42.42.42'; + $handler->setRelease($release); + $record = $this->getRecord(Logger::INFO, 'test'); + $handler->handle($record); + $this->assertEquals($release, $ravenClient->lastData['release']); + + $localRelease = 'v41.41.41'; + $record = $this->getRecord(Logger::INFO, 'test', array('release' => $localRelease)); + $handler->handle($record); + $this->assertEquals($localRelease, $ravenClient->lastData['release']); + } + private function methodThatThrowsAnException() { throw new \Exception('This is an exception');