Skip to content

Commit 12fcfbe

Browse files
authored
Fix the conditions to automatically enable the tracing of the cache adapters (#487)
1 parent 4b57969 commit 12fcfbe

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-${{ matrix.dependencies }}-
109109

110110
- name: Remove optional packages
111-
run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache --dev --no-update
111+
run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache symfony/cache-contracts --dev --no-update
112112

113113
- name: Install highest dependencies
114114
run: composer update --no-progress --no-interaction --prefer-dist

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
## Unreleased
44

5+
- Fix the conditions to automatically enable the cache instrumentation when possible (#487)
6+
57
## 4.1.0 (2021-04-19)
68

79
- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472)
810
- Add support for distributed tracing of Symfony request events (#423)
911
- Add support for distributed tracing of Twig template rendering (#430)
1012
- Add support for distributed tracing of SQL queries while using Doctrine DBAL (#426)
1113
- Add support for distributed tracing when running a console command (#455)
12-
- Add support for distributed tracing of cache pools (#)
14+
- Add support for distributed tracing of cache pools (#477)
1315
- Add `Full command` to extras for CLI commands, which includes command with all arguments
1416
- Deprecate the `Sentry\SentryBundle\EventListener\ConsoleCommandListener` class in favor of its parent class `Sentry\SentryBundle\EventListener\ConsoleListener` (#429)
1517
- Lower the required version of `symfony/psr-http-message-bridge` to allow installing it on a project that uses Symfony `3.4.x` components only (#480)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"phpunit/phpunit": "^8.5||^9.0",
4747
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11",
4848
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11",
49+
"symfony/cache-contracts": "^2.4",
4950
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11",
5051
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11",
5152
"symfony/messenger": "^4.4.20||^5.0.11",

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
use Sentry\Options;
1010
use Sentry\SentryBundle\ErrorTypesParser;
1111
use Symfony\Bundle\TwigBundle\TwigBundle;
12+
use Symfony\Component\Cache\CacheItem;
1213
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1314
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1415
use Symfony\Component\Config\Definition\ConfigurationInterface;
1516
use Symfony\Component\Messenger\MessageBusInterface;
16-
use Symfony\Contracts\Cache\CacheInterface;
1717

1818
final class Configuration implements ConfigurationInterface
1919
{
@@ -165,7 +165,7 @@ private function addDistributedTracingSection(ArrayNodeDefinition $rootNode): vo
165165
->{class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
166166
->end()
167167
->arrayNode('cache')
168-
->{interface_exists(CacheInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
168+
->{interface_exists(CacheItem::class) ? 'canBeDisabled' : 'canBeEnabled'}()
169169
->end()
170170
->end()
171171
->end()

src/DependencyInjection/SentryExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
use Sentry\Serializer\Serializer;
2929
use Sentry\Transport\TransportFactoryInterface;
3030
use Symfony\Bundle\TwigBundle\TwigBundle;
31+
use Symfony\Component\Cache\CacheItem;
3132
use Symfony\Component\Config\FileLocator;
3233
use Symfony\Component\DependencyInjection\ContainerBuilder;
3334
use Symfony\Component\DependencyInjection\Definition;
3435
use Symfony\Component\DependencyInjection\Loader;
3536
use Symfony\Component\DependencyInjection\Reference;
3637
use Symfony\Component\ErrorHandler\Error\FatalError;
3738
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
38-
use Symfony\Contracts\Cache\CacheInterface;
3939

4040
final class SentryExtension extends ConfigurableExtension
4141
{
@@ -224,7 +224,7 @@ private function registerCacheTracingConfiguration(ContainerBuilder $container,
224224
$isConfigEnabled = $this->isConfigEnabled($container, $config)
225225
&& $this->isConfigEnabled($container, $config['cache']);
226226

227-
if ($isConfigEnabled && !interface_exists(CacheInterface::class)) {
227+
if ($isConfigEnabled && !interface_exists(CacheItem::class)) {
228228
throw new LogicException('Cache tracing support cannot be enabled because the symfony/cache Composer package is not installed.');
229229
}
230230

tests/DependencyInjection/Compiler/CacheTracingPassTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Definition;
1616
use Symfony\Component\DependencyInjection\Reference;
17-
use Symfony\Contracts\Cache\CacheInterface;
1817

1918
final class CacheTracingPassTest extends TestCase
2019
{
@@ -32,7 +31,7 @@ public function testProcess(): void
3231
->setPublic(true)
3332
->addTag('cache.pool');
3433

35-
$container->register('app.cache.baz', CacheInterface::class)
34+
$container->register('app.cache.baz')
3635
->setPublic(true)
3736
->setAbstract(true)
3837
->addTag('cache.pool');
@@ -57,7 +56,7 @@ public function testProcess(): void
5756
public function testProcessDoesNothingIfConditionsForEnablingTracingAreMissing(): void
5857
{
5958
$container = $this->createContainerBuilder(false);
60-
$container->register('app.cache', CacheInterface::class);
59+
$container->register('app.cache', AdapterInterface::class);
6160
$container->compile();
6261

6362
$this->assertFalse($container->hasDefinition('app.cache.traceable.inner'));

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use PHPUnit\Framework\TestCase;
1010
use Sentry\SentryBundle\DependencyInjection\Configuration;
1111
use Symfony\Bundle\TwigBundle\TwigBundle;
12+
use Symfony\Component\Cache\CacheItem;
1213
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1314
use Symfony\Component\Config\Definition\Processor;
1415
use Symfony\Component\Messenger\MessageBusInterface;
15-
use Symfony\Contracts\Cache\CacheInterface;
1616

1717
final class ConfigurationTest extends TestCase
1818
{
@@ -48,7 +48,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
4848
'enabled' => class_exists(TwigBundle::class),
4949
],
5050
'cache' => [
51-
'enabled' => interface_exists(CacheInterface::class),
51+
'enabled' => interface_exists(CacheItem::class),
5252
],
5353
],
5454
];

0 commit comments

Comments
 (0)