Skip to content

Adds ignore_exceptions and ignore_transactions options to Configurator #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->fixXmlConfig('trace_propagation_target')
->fixXmlConfig('tag')
->fixXmlConfig('class_serializer')
->fixXmlConfig('ignore_exception')
->fixXmlConfig('ignore_transaction')
->fixXmlConfig('prefix', 'prefixes')
->children()
->arrayNode('integrations')
Expand Down Expand Up @@ -157,6 +159,14 @@ public function getConfigTreeBuilder(): TreeBuilder
->normalizeKeys(false)
->scalarPrototype()->end()
->end()
->arrayNode('ignore_exceptions')
->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->end()
->arrayNode('ignore_transactions')
->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->end()
->end()
->end()
->end();
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/schema/sentry-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<xsd:element name="in-app-exclude" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="in-app-include" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="class-serializer" type="class-serializer" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="ignore-exception" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="ignore-transaction" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>

<xsd:attribute name="default-integrations" type="xsd:boolean" />
Expand Down
2 changes: 2 additions & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
],
'in_app_include' => [],
'class_serializers' => [],
'ignore_exceptions' => [],
'ignore_transactions' => [],
],
'messenger' => [
'enabled' => interface_exists(MessageBusInterface::class),
Expand Down
2 changes: 2 additions & 0 deletions tests/DependencyInjection/Fixtures/php/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
'capture_silenced_errors' => true,
'max_request_body_size' => 'none',
'class_serializers' => ['App\\FooClass' => 'App\\Sentry\\Serializer\\FooClassSerializer'],
'ignore_exceptions' => ['Symfony\Component\HttpKernel\Exception\BadRequestHttpException'],
'ignore_transactions' => ['GET tracing_ignored_transaction'],
],
'messenger' => [
'enabled' => true,
Expand Down
2 changes: 2 additions & 0 deletions tests/DependencyInjection/Fixtures/xml/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<sentry:in-app-exclude>%kernel.cache_dir%</sentry:in-app-exclude>
<sentry:in-app-include>%kernel.project_dir%</sentry:in-app-include>
<sentry:class-serializer class="App\FooClass">App\Sentry\Serializer\FooClassSerializer</sentry:class-serializer>
<sentry:ignore-exception>Symfony\Component\HttpKernel\Exception\BadRequestHttpException</sentry:ignore-exception>
<sentry:ignore-transaction>GET tracing_ignored_transaction</sentry:ignore-transaction>
</sentry:options>
<sentry:messenger enabled="true" capture-soft-fails="false" />
<sentry:tracing>
Expand Down
4 changes: 4 additions & 0 deletions tests/DependencyInjection/Fixtures/yml/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ sentry:
max_request_body_size: 'none'
class_serializers:
App\FooClass: App\Sentry\Serializer\FooClassSerializer
ignore_exceptions:
- Symfony\Component\HttpKernel\Exception\BadRequestHttpException
ignore_transactions:
- GET tracing_ignored_transaction
messenger:
enabled: true
capture_soft_fails: false
Expand Down
6 changes: 6 additions & 0 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ public function testClientIsCreatedFromOptions(): void
'App\\FooClass' => new Reference('App\\Sentry\\Serializer\\FooClassSerializer'),
],
'dsn' => 'https://[email protected]/0',
'ignore_exceptions' => [
'Symfony\Component\HttpKernel\Exception\BadRequestHttpException',
],
'ignore_transactions' => [
'GET tracing_ignored_transaction',
],
];

$this->assertSame(Options::class, $optionsDefinition->getClass());
Expand Down
6 changes: 6 additions & 0 deletions tests/End2End/App/Controller/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class MainController
Expand Down Expand Up @@ -46,6 +47,11 @@ public function fatal(): Response
return new Response('This response should not happen: ' . json_encode($foo));
}

public function badRequest(): Response
{
throw new BadRequestHttpException('Parameter "foo" not allowed');
}

public function index(): Response
{
$this->sentry->captureMessage('Hello there');
Expand Down
10 changes: 10 additions & 0 deletions tests/End2End/App/Controller/TracingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public function pingDatabase(): Response
return new Response('Success');
}

public function ignoredTransaction(): Response
{
$this->hub->setSpan(
$this->hub->getSpan()
->startChild($this->createSpan())
);

return new Response('Success');
}

private function createSpan(): SpanContext
{
$spanContext = new SpanContext();
Expand Down
2 changes: 2 additions & 0 deletions tests/End2End/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sentry:
capture_silenced_errors: false
error_types: E_ALL & ~E_USER_DEPRECATED
traces_sample_rate: 0
ignore_exceptions: 'Symfony\Component\HttpKernel\Exception\BadRequestHttpException'
ignore_transactions: 'GET tracing_ignored_transaction'

framework:
router: { resource: "%routing_config_dir%/routing.yml" }
Expand Down
8 changes: 8 additions & 0 deletions tests/End2End/App/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ fatal:
path: /fatal
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::fatal' }

invalid_csrf:
path: /bad-request
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::badRequest' }

success:
path: /200
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::index' }
Expand Down Expand Up @@ -33,3 +37,7 @@ dispatch_unrecoverable:
tracing_ping_database:
path: /tracing/ping-database
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\TracingController::pingDatabase' }

tracing_ignored_transaction:
path: /tracing/ignored-transaction
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\TracingController::ignoredTransaction' }
14 changes: 14 additions & 0 deletions tests/End2End/End2EndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ public function testGet404(): void
$this->assertEventCount(1);
}

public function testGetBadRequest(): void
{
$client = static::createClient(['debug' => false]);

$client->request('GET', '/bad-request');

$response = $client->getResponse();

$this->assertInstanceOf(Response::class, $response);
$this->assertSame(400, $response->getStatusCode());

$this->assertLastEventIdIsNull($client);
}

public function testGet500(): void
{
$client = static::createClient();
Expand Down
26 changes: 26 additions & 0 deletions tests/End2End/TracingEnd2EndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public function testTracingWithDoctrineConnectionPing(): void
$this->assertTracingEventCount(1);
}

public function testTracingWithIgnoredTransaction(): void
{
$client = static::createClient(['debug' => false]);

$client->request('GET', '/tracing/ignored-transaction');

$response = $client->getResponse();

$this->assertInstanceOf(Response::class, $response);
$this->assertSame(200, $response->getStatusCode());

$this->assertLastEventIdIsNull($client);
$this->assertTracingEventCount(1);
}

private function assertLastEventIdIsNotNull(KernelBrowser $client): void
{
$container = $client->getContainer();
Expand All @@ -57,6 +72,17 @@ private function assertLastEventIdIsNotNull(KernelBrowser $client): void
$this->assertNotNull($hub->getLastEventId(), 'Last error not captured');
}

private function assertLastEventIdIsNull(KernelBrowser $client): void
{
$container = $client->getContainer();
$this->assertNotNull($container);

$hub = $container->get('test.hub');
$this->assertInstanceOf(HubInterface::class, $hub);

$this->assertNull($hub->getLastEventId(), 'Some error was captured');
}

private function assertTracingEventCount(int $expectedCount): void
{
$events = file_get_contents(self::SENT_EVENTS_LOG);
Expand Down