-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a processor to remove all stacktraces from reported exceptions
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 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
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Raven. | ||
* | ||
* (c) Sentry Team | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* This processor removes the stacktrace from all exceptions captured by an | ||
* event. | ||
* | ||
* @author Stefano Arlandini <[email protected]> | ||
*/ | ||
class Raven_Processor_RemoveStacktraceProcessor extends Raven_Processor | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(&$data) | ||
{ | ||
if (isset($data['exception']) && isset($data['exception']['values'])) { | ||
foreach ($data['exception']['values'] as &$exception) { | ||
if (isset($exception['stacktrace'])) { | ||
unset($exception['stacktrace']); | ||
} | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
test/Raven/Tests/Processor/RemoveStacktraceProcessorTest.php
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,70 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Raven. | ||
* | ||
* (c) Sentry Team | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
class Raven_Tests_RemoveStacktraceProcessorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Raven_Client|PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var Raven_Processor_RemoveStacktraceProcessor | ||
*/ | ||
protected $processor; | ||
|
||
protected function setUp() | ||
{ | ||
$this->client = $this->getMockBuilder('Raven_Client') | ||
->setMethodsExcept(array('captureException', 'capture', 'get_default_data', 'get_http_data', 'get_user_data', 'get_extra_data')) | ||
->getMock(); | ||
|
||
$this->client->store_errors_for_bulk_send = true; | ||
|
||
$this->processor = new Raven_Processor_RemoveStacktraceProcessor($this->client); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
try { | ||
throw new \Exception(); | ||
} catch (\Exception $exception) { | ||
$this->client->captureException($exception); | ||
} | ||
|
||
$this->assertArrayHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][0]); | ||
|
||
$this->processor->process($this->client->_pending_events[0]); | ||
|
||
$this->assertArrayNotHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][0]); | ||
} | ||
|
||
public function testProcessWithPreviousException() | ||
{ | ||
try { | ||
try { | ||
throw new \Exception('foo'); | ||
} catch (\Exception $exception) { | ||
throw new \Exception('bar', 0, $exception); | ||
} | ||
} catch (\Exception $exception) { | ||
$this->client->captureException($exception); | ||
} | ||
|
||
$this->assertArrayHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][0]); | ||
$this->assertArrayHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][1]); | ||
|
||
$this->processor->process($this->client->_pending_events[0]); | ||
|
||
$this->assertArrayNotHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][0]); | ||
$this->assertArrayNotHasKey('stacktrace', $this->client->_pending_events[0]['exception']['values'][1]); | ||
} | ||
} |