Skip to content

Commit 2501258

Browse files
author
Gassan Gousseinov
committed
Adds ignore_exceptions and ignore_transactions options to Configurator
fixes: #710
1 parent 52befb4 commit 2501258

File tree

13 files changed

+94
-0
lines changed

13 files changed

+94
-0
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public function getConfigTreeBuilder(): TreeBuilder
6262
->fixXmlConfig('trace_propagation_target')
6363
->fixXmlConfig('tag')
6464
->fixXmlConfig('class_serializer')
65+
->fixXmlConfig('ignore_exception')
66+
->fixXmlConfig('ignore_transaction')
6567
->fixXmlConfig('prefix', 'prefixes')
6668
->children()
6769
->arrayNode('integrations')
@@ -157,6 +159,14 @@ public function getConfigTreeBuilder(): TreeBuilder
157159
->normalizeKeys(false)
158160
->scalarPrototype()->end()
159161
->end()
162+
->arrayNode('ignore_exceptions')
163+
->scalarPrototype()->end()
164+
->beforeNormalization()->castToArray()->end()
165+
->end()
166+
->arrayNode('ignore_transactions')
167+
->scalarPrototype()->end()
168+
->beforeNormalization()->castToArray()->end()
169+
->end()
160170
->end()
161171
->end()
162172
->end();

src/Resources/config/schema/sentry-1.0.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<xsd:element name="in-app-exclude" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
3131
<xsd:element name="in-app-include" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
3232
<xsd:element name="class-serializer" type="class-serializer" minOccurs="0" maxOccurs="unbounded" />
33+
<xsd:element name="ignore-exception" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
34+
<xsd:element name="ignore-transaction" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
3335
</xsd:sequence>
3436

3537
<xsd:attribute name="default-integrations" type="xsd:boolean" />

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
3939
],
4040
'in_app_include' => [],
4141
'class_serializers' => [],
42+
'ignore_exceptions' => [],
43+
'ignore_transactions' => [],
4244
],
4345
'messenger' => [
4446
'enabled' => interface_exists(MessageBusInterface::class),

tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
'capture_silenced_errors' => true,
4545
'max_request_body_size' => 'none',
4646
'class_serializers' => ['App\\FooClass' => 'App\\Sentry\\Serializer\\FooClassSerializer'],
47+
'ignore_exceptions' => ['Symfony\Component\HttpKernel\Exception\BadRequestHttpException'],
48+
'ignore_transactions' => ['GET tracing_ignored_transaction'],
4749
],
4850
'messenger' => [
4951
'enabled' => true,

tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<sentry:in-app-exclude>%kernel.cache_dir%</sentry:in-app-exclude>
4545
<sentry:in-app-include>%kernel.project_dir%</sentry:in-app-include>
4646
<sentry:class-serializer class="App\FooClass">App\Sentry\Serializer\FooClassSerializer</sentry:class-serializer>
47+
<sentry:ignore-exception>Symfony\Component\HttpKernel\Exception\BadRequestHttpException</sentry:ignore-exception>
48+
<sentry:ignore-transaction>GET tracing_ignored_transaction</sentry:ignore-transaction>
4749
</sentry:options>
4850
<sentry:messenger enabled="true" capture-soft-fails="false" />
4951
<sentry:tracing>

tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ sentry:
4242
max_request_body_size: 'none'
4343
class_serializers:
4444
App\FooClass: App\Sentry\Serializer\FooClassSerializer
45+
ignore_exceptions:
46+
- Symfony\Component\HttpKernel\Exception\BadRequestHttpException
47+
ignore_transactions:
48+
- GET tracing_ignored_transaction
4549
messenger:
4650
enabled: true
4751
capture_soft_fails: false

tests/DependencyInjection/SentryExtensionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public function testClientIsCreatedFromOptions(): void
233233
'App\\FooClass' => new Reference('App\\Sentry\\Serializer\\FooClassSerializer'),
234234
],
235235
'dsn' => 'https://[email protected]/0',
236+
'ignore_exceptions' => [
237+
'Symfony\Component\HttpKernel\Exception\BadRequestHttpException',
238+
],
239+
'ignore_transactions' => [
240+
'GET tracing_ignored_transaction',
241+
],
236242
];
237243

238244
$this->assertSame(Options::class, $optionsDefinition->getClass());

tests/End2End/App/Controller/MainController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\HttpFoundation\Request;
99
use Symfony\Component\HttpFoundation\RequestStack;
1010
use Symfony\Component\HttpFoundation\Response;
11+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1112
use Symfony\Component\HttpKernel\HttpKernelInterface;
1213

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

50+
public function badRequest(): Response
51+
{
52+
throw new BadRequestHttpException('Parameter "foo" not allowed');
53+
}
54+
4955
public function index(): Response
5056
{
5157
$this->sentry->captureMessage('Hello there');

tests/End2End/App/Controller/TracingController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public function pingDatabase(): Response
4141
return new Response('Success');
4242
}
4343

44+
public function ignoredTransaction(): Response
45+
{
46+
$this->hub->setSpan(
47+
$this->hub->getSpan()
48+
->startChild($this->createSpan())
49+
);
50+
51+
return new Response('Success');
52+
}
53+
4454
private function createSpan(): SpanContext
4555
{
4656
$spanContext = new SpanContext();

tests/End2End/App/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ sentry:
66
capture_silenced_errors: false
77
error_types: E_ALL & ~E_USER_DEPRECATED
88
traces_sample_rate: 0
9+
ignore_exceptions: 'Symfony\Component\HttpKernel\Exception\BadRequestHttpException'
10+
ignore_transactions: 'GET tracing_ignored_transaction'
911

1012
framework:
1113
router: { resource: "%routing_config_dir%/routing.yml" }

tests/End2End/App/routing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ fatal:
66
path: /fatal
77
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::fatal' }
88

9+
invalid_csrf:
10+
path: /bad-request
11+
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::badRequest' }
12+
913
success:
1014
path: /200
1115
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MainController::index' }
@@ -33,3 +37,7 @@ dispatch_unrecoverable:
3337
tracing_ping_database:
3438
path: /tracing/ping-database
3539
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\TracingController::pingDatabase' }
40+
41+
tracing_ignored_transaction:
42+
path: /tracing/ignored-transaction
43+
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\TracingController::ignoredTransaction' }

tests/End2End/End2EndTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ public function testGet404(): void
109109
$this->assertEventCount(1);
110110
}
111111

112+
public function testGetBadRequest(): void
113+
{
114+
$client = static::createClient(['debug' => false]);
115+
116+
$client->request('GET', '/bad-request');
117+
118+
$response = $client->getResponse();
119+
120+
$this->assertInstanceOf(Response::class, $response);
121+
$this->assertSame(400, $response->getStatusCode());
122+
123+
$this->assertLastEventIdIsNull($client);
124+
}
125+
112126
public function testGet500(): void
113127
{
114128
$client = static::createClient();

tests/End2End/TracingEnd2EndTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ public function testTracingWithDoctrineConnectionPing(): void
4646
$this->assertTracingEventCount(1);
4747
}
4848

49+
public function testTracingWithIgnoredTransaction(): void
50+
{
51+
$client = static::createClient(['debug' => false]);
52+
53+
$client->request('GET', '/tracing/ignored-transaction');
54+
55+
$response = $client->getResponse();
56+
57+
$this->assertInstanceOf(Response::class, $response);
58+
$this->assertSame(200, $response->getStatusCode());
59+
60+
$this->assertLastEventIdIsNull($client);
61+
$this->assertTracingEventCount(1);
62+
}
63+
4964
private function assertLastEventIdIsNotNull(KernelBrowser $client): void
5065
{
5166
$container = $client->getContainer();
@@ -57,6 +72,17 @@ private function assertLastEventIdIsNotNull(KernelBrowser $client): void
5772
$this->assertNotNull($hub->getLastEventId(), 'Last error not captured');
5873
}
5974

75+
private function assertLastEventIdIsNull(KernelBrowser $client): void
76+
{
77+
$container = $client->getContainer();
78+
$this->assertNotNull($container);
79+
80+
$hub = $container->get('test.hub');
81+
$this->assertInstanceOf(HubInterface::class, $hub);
82+
83+
$this->assertNull($hub->getLastEventId(), 'Some error was captured');
84+
}
85+
6086
private function assertTracingEventCount(int $expectedCount): void
6187
{
6288
$events = file_get_contents(self::SENT_EVENTS_LOG);

0 commit comments

Comments
 (0)