Skip to content

Commit

Permalink
Add a processor to remove all stacktraces from reported exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry committed Mar 13, 2017
1 parent c2f44ee commit 41c2704
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
``call_existing`` is true and no exception handler is registered (#421).
- Collect User.ip_address automatically (#419).
- Added a processor to remove web cookies and another to remove HTTP body data for POST, PUT, PATCH and DELETE requests. They will be enabled by default in ``2.0`` (#405).
- Added a processor to remove all stacktraces from reported exceptions (#429)

1.6.2
-----
Expand Down
33 changes: 33 additions & 0 deletions lib/Raven/Processor/RemoveStacktraceProcessor.php
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 test/Raven/Tests/Processor/RemoveStacktraceProcessorTest.php
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]);
}
}

0 comments on commit 41c2704

Please sign in to comment.