Skip to content

Commit 8cd97db

Browse files
authored
Make the transport factory configurable in the bundle's config (#504)
1 parent 55b79b3 commit 8cd97db

File tree

9 files changed

+18
-6
lines changed

9 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Make the transport factory configurable in the bundle's config (#504)
6+
57
## 4.1.0 (2021-04-19)
68

79
- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472)

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Jean85\PrettyVersions;
99
use Sentry\Options;
1010
use Sentry\SentryBundle\ErrorTypesParser;
11+
use Sentry\Transport\TransportFactoryInterface;
1112
use Symfony\Bundle\TwigBundle\TwigBundle;
1213
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1314
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -35,6 +36,10 @@ public function getConfigTreeBuilder(): TreeBuilder
3536
->info('If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.')
3637
->end()
3738
->booleanNode('register_error_listener')->defaultTrue()->end()
39+
->scalarNode('transport_factory')
40+
->info('The service ID of the transport factory used by the default SDK client.')
41+
->defaultValue(TransportFactoryInterface::class)
42+
->end()
3843
->arrayNode('options')
3944
->addDefaultsIfNotSet()
4045
->fixXmlConfig('integration')

src/DependencyInjection/SentryExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension;
2727
use Sentry\Serializer\RepresentationSerializer;
2828
use Sentry\Serializer\Serializer;
29-
use Sentry\Transport\TransportFactoryInterface;
3029
use Symfony\Bundle\TwigBundle\TwigBundle;
3130
use Symfony\Component\Config\FileLocator;
3231
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -128,7 +127,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
128127
->setArgument(0, new Reference('sentry.client.options'))
129128
->addMethodCall('setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER])
130129
->addMethodCall('setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()])
131-
->addMethodCall('setTransportFactory', [new Reference(TransportFactoryInterface::class)])
130+
->addMethodCall('setTransportFactory', [new Reference($config['transport_factory'])])
132131
->addMethodCall('setSerializer', [$serializer])
133132
->addMethodCall('setRepresentationSerializer', [$representationSerializerDefinition]);
134133

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</xsd:choice>
1616

1717
<xsd:attribute name="register-error-listener" type="xsd:boolean" />
18+
<xsd:attribute name="transport-factory" type="xsd:string" />
1819
<xsd:attribute name="dsn" type="xsd:string" />
1920
</xsd:complexType>
2021

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
2020
{
2121
$expectedBundleDefaultConfig = [
2222
'register_error_listener' => true,
23+
'transport_factory' => 'Sentry\\Transport\\TransportFactoryInterface',
2324
'options' => [
2425
'integrations' => [],
2526
'prefixes' => array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))),

tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/** @var ContainerBuilder $container */
88
$container->loadFromExtension('sentry', [
99
'dsn' => 'https://[email protected]/0',
10+
'transport_factory' => 'App\\Sentry\\Transport\\TransportFactory',
1011
'options' => [
1112
'integrations' => ['App\\Sentry\\Integration\\FooIntegration'],
1213
'default_integrations' => false,
@@ -28,7 +29,7 @@
2829
],
2930
'error_types' => \E_ALL,
3031
'max_breadcrumbs' => 1,
31-
'before_breadcrumb' => 'App\Sentry\BeforeBreadcrumbCallback',
32+
'before_breadcrumb' => 'App\\Sentry\\BeforeBreadcrumbCallback',
3233
'in_app_exclude' => ['%kernel.cache_dir%'],
3334
'in_app_include' => ['%kernel.project_dir%'],
3435
'send_default_pii' => true,

tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
77
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">
88

9-
<sentry:config dsn="https://[email protected]/0">
9+
<sentry:config
10+
dsn="https://[email protected]/0"
11+
transport-factory="App\Sentry\Transport\TransportFactory"
12+
>
1013
<sentry:options default-integrations="false"
1114
send-attempts="1"
1215
sample-rate="1"

tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sentry:
22
dsn: https://[email protected]/0
3+
transport_factory: App\Sentry\Transport\TransportFactory
34
options:
45
integrations:
56
- App\Sentry\Integration\FooIntegration

tests/DependencyInjection/SentryExtensionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension;
2626
use Sentry\Serializer\RepresentationSerializer;
2727
use Sentry\Serializer\Serializer;
28-
use Sentry\Transport\TransportFactoryInterface;
2928
use Symfony\Bundle\TwigBundle\TwigBundle;
3029
use Symfony\Component\Console\ConsoleEvents;
3130
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -231,7 +230,7 @@ public function testClentIsCreatedFromOptions(): void
231230

232231
$this->assertDefinitionMethodCallAt($methodCalls[0], 'setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER]);
233232
$this->assertDefinitionMethodCallAt($methodCalls[1], 'setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()]);
234-
$this->assertDefinitionMethodCallAt($methodCalls[2], 'setTransportFactory', [new Reference(TransportFactoryInterface::class)]);
233+
$this->assertDefinitionMethodCallAt($methodCalls[2], 'setTransportFactory', [new Reference('App\\Sentry\\Transport\\TransportFactory')]);
235234

236235
$this->assertSame('setSerializer', $methodCalls[3][0]);
237236
$this->assertInstanceOf(Definition::class, $methodCalls[3][1][0]);

0 commit comments

Comments
 (0)