Skip to content

Make the transport factory configurable in the bundle's config #504

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 1 commit into from
May 17, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Make the transport factory configurable in the bundle's config (#504)

## 4.1.0 (2021-04-19)

- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472)
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Jean85\PrettyVersions;
use Sentry\Options;
use Sentry\SentryBundle\ErrorTypesParser;
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -35,6 +36,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->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.')
->end()
->booleanNode('register_error_listener')->defaultTrue()->end()
->scalarNode('transport_factory')
->info('The service ID of the transport factory used by the default SDK client.')
->defaultValue(TransportFactoryInterface::class)
->end()
->arrayNode('options')
->addDefaultsIfNotSet()
->fixXmlConfig('integration')
Expand Down
3 changes: 1 addition & 2 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension;
use Sentry\Serializer\RepresentationSerializer;
use Sentry\Serializer\Serializer;
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -128,7 +127,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
->setArgument(0, new Reference('sentry.client.options'))
->addMethodCall('setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER])
->addMethodCall('setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()])
->addMethodCall('setTransportFactory', [new Reference(TransportFactoryInterface::class)])
->addMethodCall('setTransportFactory', [new Reference($config['transport_factory'])])
->addMethodCall('setSerializer', [$serializer])
->addMethodCall('setRepresentationSerializer', [$representationSerializerDefinition]);

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/schema/sentry-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</xsd:choice>

<xsd:attribute name="register-error-listener" type="xsd:boolean" />
<xsd:attribute name="transport-factory" type="xsd:string" />
<xsd:attribute name="dsn" type="xsd:string" />
</xsd:complexType>

Expand Down
1 change: 1 addition & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
{
$expectedBundleDefaultConfig = [
'register_error_listener' => true,
'transport_factory' => 'Sentry\\Transport\\TransportFactoryInterface',
'options' => [
'integrations' => [],
'prefixes' => array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))),
Expand Down
3 changes: 2 additions & 1 deletion tests/DependencyInjection/Fixtures/php/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'dsn' => 'https://[email protected]/0',
'transport_factory' => 'App\\Sentry\\Transport\\TransportFactory',
'options' => [
'integrations' => ['App\\Sentry\\Integration\\FooIntegration'],
'default_integrations' => false,
Expand All @@ -28,7 +29,7 @@
],
'error_types' => \E_ALL,
'max_breadcrumbs' => 1,
'before_breadcrumb' => 'App\Sentry\BeforeBreadcrumbCallback',
'before_breadcrumb' => 'App\\Sentry\\BeforeBreadcrumbCallback',
'in_app_exclude' => ['%kernel.cache_dir%'],
'in_app_include' => ['%kernel.project_dir%'],
'send_default_pii' => true,
Expand Down
5 changes: 4 additions & 1 deletion tests/DependencyInjection/Fixtures/xml/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config dsn="https://[email protected]/0">
<sentry:config
dsn="https://[email protected]/0"
transport-factory="App\Sentry\Transport\TransportFactory"
>
<sentry:options default-integrations="false"
send-attempts="1"
sample-rate="1"
Expand Down
1 change: 1 addition & 0 deletions tests/DependencyInjection/Fixtures/yml/full.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sentry:
dsn: https://[email protected]/0
transport_factory: App\Sentry\Transport\TransportFactory
options:
integrations:
- App\Sentry\Integration\FooIntegration
Expand Down
3 changes: 1 addition & 2 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension;
use Sentry\Serializer\RepresentationSerializer;
use Sentry\Serializer\Serializer;
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -231,7 +230,7 @@ public function testClentIsCreatedFromOptions(): void

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

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