Skip to content

Commit e152ca8

Browse files
authored
Merge pull request #196 from getsentry/add-integrations
Add integrations
2 parents bf78447 + 207bc05 commit e152ca8

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,20 @@ public function getConfigTreeBuilder()
8383
->end()
8484
->scalarNode('http_proxy')
8585
->end()
86-
// TODO -- integrations
86+
->arrayNode('integrations')
87+
->prototype('scalar')
88+
->validate()
89+
->ifTrue(function ($value): bool {
90+
if (! is_string($value)) {
91+
return true;
92+
}
93+
94+
return '@' !== substr($value, 0, 1);
95+
})
96+
->thenInvalid('Expecting service reference, got %s')
97+
->end()
98+
->end()
99+
->end()
87100
->scalarNode('logger')
88101
->end()
89102
->integerNode('max_breadcrumbs')

src/DependencyInjection/SentryExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
9494
if (\array_key_exists('before_breadcrumb', $processedOptions)) {
9595
$this->mapCallableValue($options, 'setBeforeBreadcrumbCallback', $processedOptions['before_breadcrumb']);
9696
}
97+
98+
if (\array_key_exists('integrations', $processedOptions)) {
99+
$integrations = [];
100+
foreach ($processedOptions['integrations'] as $integrationName) {
101+
$integrations[] = new Reference(substr($integrationName, 1));
102+
}
103+
104+
$options->addMethodCall('setIntegrations', [$integrations]);
105+
}
97106
}
98107

99108
/**

test/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class ConfigurationTest extends TestCase
1313
{
14-
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 22;
14+
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;
1515

1616
public function testDataProviderIsMappingTheRightNumberOfOptions(): void
1717
{
@@ -53,6 +53,7 @@ public function testConfigurationDefaults(): void
5353
'%kernel.cache_dir%',
5454
'%kernel.root_dir%/../vendor',
5555
],
56+
'integrations' => $defaultSdkValues->getIntegrations(),
5657
'excluded_exceptions' => $defaultSdkValues->getExcludedExceptions(),
5758
'prefixes' => $defaultSdkValues->getPrefixes(),
5859
'project_root' => '%kernel.root_dir%/..',
@@ -95,6 +96,7 @@ public function optionValuesProvider(): array
9596
['error_types', E_ALL],
9697
['http_proxy', '1.2.3.4:5678'],
9798
['in_app_exclude', ['some/path']],
99+
['integrations', []],
98100
['excluded_exceptions', [\Throwable::class]],
99101
['logger', 'some-logger'],
100102
['max_breadcrumbs', 15],
@@ -144,9 +146,11 @@ public function invalidValuesProvider(): array
144146
['enable_compression', 'string'],
145147
['environment', ''],
146148
['error_types', []],
149+
['excluded_exceptions', 'some-string'],
147150
['http_proxy', []],
148151
['in_app_exclude', 'some/single/path'],
149-
['excluded_exceptions', 'some-string'],
152+
['integrations', [1]],
153+
['integrations', 'a string'],
150154
['logger', []],
151155
['max_breadcrumbs', -1],
152156
['max_breadcrumbs', 'string'],

test/DependencyInjection/SentryExtensionTest.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Sentry\Breadcrumb;
77
use Sentry\Event;
8+
use Sentry\Integration\IntegrationInterface;
89
use Sentry\Options;
910
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
1011
use Sentry\SentryBundle\EventListener\ConsoleListener;
@@ -28,8 +29,9 @@ public function testDataProviderIsMappingTheRightNumberOfOptions(): void
2829
$providerData = $this->optionsValueProvider();
2930
$supportedOptions = \array_unique(\array_column($providerData, 0));
3031

32+
// subtracted one is `integration`, which cannot be tested with the provider
3133
$this->assertCount(
32-
ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT,
34+
ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT - 1,
3335
$supportedOptions,
3436
'Provider for configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
3537
);
@@ -281,6 +283,19 @@ public function testBeforeBreadcrumbWithInvalidServiceReference(): void
281283
$this->getOptionsFrom($container)->getBeforeBreadcrumbCallback();
282284
}
283285

286+
public function testIntegrations(): void
287+
{
288+
$container = $this->getContainer([
289+
'options' => [
290+
'integrations' => ['@integration_mock'],
291+
],
292+
]);
293+
294+
$integrations = $this->getOptionsFrom($container)->getIntegrations();
295+
$this->assertContainsOnlyInstancesOf(IntegrationMock::class, $integrations);
296+
$this->assertCount(1, $integrations);
297+
}
298+
284299
private function getContainer(array $configuration = []): Container
285300
{
286301
$containerBuilder = new ContainerBuilder();
@@ -291,11 +306,9 @@ private function getContainer(array $configuration = []): Container
291306
}
292307
$containerBuilder->setParameter('kernel.environment', 'test');
293308

294-
$mockEventDispatcher = $this
295-
->createMock(EventDispatcherInterface::class);
309+
$mockEventDispatcher = $this->createMock(EventDispatcherInterface::class);
296310

297-
$mockRequestStack = $this
298-
->createMock(RequestStack::class);
311+
$mockRequestStack = $this->createMock(RequestStack::class);
299312

300313
$containerBuilder->set('request_stack', $mockRequestStack);
301314
$containerBuilder->set('event_dispatcher', $mockEventDispatcher);
@@ -307,6 +320,9 @@ private function getContainer(array $configuration = []): Container
307320
$beforeSend->setFactory([CallbackMock::class, 'createCallback']);
308321
$containerBuilder->setDefinition('callable_mock', $beforeSend);
309322

323+
$integration = new Definition(IntegrationMock::class);
324+
$containerBuilder->setDefinition('integration_mock', $integration);
325+
310326
$extension = new SentryExtension();
311327
$extension->load(['sentry' => $configuration], $containerBuilder);
312328

@@ -348,3 +364,10 @@ public static function createCallback(): callable
348364
return [new self(), 'callback'];
349365
}
350366
}
367+
368+
class IntegrationMock implements IntegrationInterface
369+
{
370+
public function setupOnce(): void
371+
{
372+
}
373+
}

0 commit comments

Comments
 (0)