Skip to content

Fix the conditions to automatically enable the tracing of the cache adapters #487

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 2 commits into from
Apr 21, 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: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-${{ matrix.dependencies }}-

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

- name: Install highest dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

## Unreleased

- Fix the conditions to automatically enable the cache instrumentation when possible (#487)

## 4.1.0 (2021-04-19)

- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472)
- Add support for distributed tracing of Symfony request events (#423)
- Add support for distributed tracing of Twig template rendering (#430)
- Add support for distributed tracing of SQL queries while using Doctrine DBAL (#426)
- Add support for distributed tracing when running a console command (#455)
- Add support for distributed tracing of cache pools (#)
- Add support for distributed tracing of cache pools (#477)
- Add `Full command` to extras for CLI commands, which includes command with all arguments
- Deprecate the `Sentry\SentryBundle\EventListener\ConsoleCommandListener` class in favor of its parent class `Sentry\SentryBundle\EventListener\ConsoleListener` (#429)
- 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)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"phpunit/phpunit": "^8.5||^9.0",
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11",
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11",
"symfony/cache-contracts": "^2.4",
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11",
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11",
"symfony/messenger": "^4.4.20||^5.0.11",
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use Sentry\Options;
use Sentry\SentryBundle\ErrorTypesParser;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Cache\CacheInterface;

final class Configuration implements ConfigurationInterface
{
Expand Down Expand Up @@ -165,7 +165,7 @@ private function addDistributedTracingSection(ArrayNodeDefinition $rootNode): vo
->{class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->arrayNode('cache')
->{interface_exists(CacheInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->{interface_exists(CacheItem::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->end()
->end()
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
use Sentry\Serializer\Serializer;
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ErrorHandler\Error\FatalError;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Symfony\Contracts\Cache\CacheInterface;

final class SentryExtension extends ConfigurableExtension
{
Expand Down Expand Up @@ -224,7 +224,7 @@ private function registerCacheTracingConfiguration(ContainerBuilder $container,
$isConfigEnabled = $this->isConfigEnabled($container, $config)
&& $this->isConfigEnabled($container, $config['cache']);

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

Expand Down
5 changes: 2 additions & 3 deletions tests/DependencyInjection/Compiler/CacheTracingPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Contracts\Cache\CacheInterface;

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

$container->register('app.cache.baz', CacheInterface::class)
$container->register('app.cache.baz')
->setPublic(true)
->setAbstract(true)
->addTag('cache.pool');
Expand All @@ -57,7 +56,7 @@ public function testProcess(): void
public function testProcessDoesNothingIfConditionsForEnablingTracingAreMissing(): void
{
$container = $this->createContainerBuilder(false);
$container->register('app.cache', CacheInterface::class);
$container->register('app.cache', AdapterInterface::class);
$container->compile();

$this->assertFalse($container->hasDefinition('app.cache.traceable.inner'));
Expand Down
4 changes: 2 additions & 2 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\DependencyInjection\Configuration;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Cache\CacheInterface;

final class ConfigurationTest extends TestCase
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
'enabled' => class_exists(TwigBundle::class),
],
'cache' => [
'enabled' => interface_exists(CacheInterface::class),
'enabled' => interface_exists(CacheItem::class),
],
],
];
Expand Down