Bug: CacheTracingPass breaks container compilation when a cache pool implements NamespacedPoolInterface
Describe the bug
When cache_enabled: true, the container fails to compile with:
Invalid alias definition: alias "Symfony\Contracts\Cache\NamespacedPoolInterface"
is referencing class "Traceway\OpenTelemetryBundle\Cache\TraceableCachePool"
but this class does not implement "Symfony\Contracts\Cache\NamespacedPoolInterface".
Because this alias is an interface, "Traceway\OpenTelemetryBundle\Cache\TraceableCachePool"
must implement "Symfony\Contracts\Cache\NamespacedPoolInterface".
Root cause
CacheTracingPass wraps every tagged cache.pool with TraceableCachePool as a decorator.
Some pools (e.g. Sylius's sylius.cache backed by Redis) implement NamespacedPoolInterface.
Symfony's CheckAliasValidityPass then tries to create an alias
NamespacedPoolInterface → TraceableCachePool, but TraceableCachePool only implements
CacheInterface, AdapterInterface, and ResetInterface — not NamespacedPoolInterface.
// TraceableCachePool.php
class TraceableCachePool implements CacheInterface, AdapterInterface, ResetInterface
// ^^^ missing NamespacedPoolInterface
Suggested fix
TraceableCachePool (and TraceableTagAwareCachePool) should implement NamespacedPoolInterface
and delegate withSubNamespace() to the inner pool:
use Symfony\Contracts\Cache\NamespacedPoolInterface;
class TraceableCachePool implements CacheInterface, AdapterInterface, ResetInterface, NamespacedPoolInterface
{
public function withSubNamespace(string $namespace): static
{
$clone = clone $this;
$clone->pool = $this->pool instanceof NamespacedPoolInterface
? $this->pool->withSubNamespace($namespace)
: $this->pool;
return $clone;
}
}
Alternatively, CacheTracingPass can detect that a pool implements NamespacedPoolInterface
and wrap it with a dedicated subclass that also implements it.
Workaround
# config/packages/open_telemetry.yaml
open_telemetry:
cache_enabled: false
Environment
traceway/opentelemetry-symfony (current main)
- Symfony 7.x
- PHP 8.x
Let me know what solution you prefer?
Bug:
CacheTracingPassbreaks container compilation when a cache pool implementsNamespacedPoolInterfaceDescribe the bug
When
cache_enabled: true, the container fails to compile with:Root cause
CacheTracingPasswraps every taggedcache.poolwithTraceableCachePoolas a decorator.Some pools (e.g. Sylius's
sylius.cachebacked by Redis) implementNamespacedPoolInterface.Symfony's
CheckAliasValidityPassthen tries to create an aliasNamespacedPoolInterface → TraceableCachePool, butTraceableCachePoolonly implementsCacheInterface,AdapterInterface, andResetInterface— notNamespacedPoolInterface.Suggested fix
TraceableCachePool(andTraceableTagAwareCachePool) should implementNamespacedPoolInterfaceand delegate
withSubNamespace()to the inner pool:Alternatively,
CacheTracingPasscan detect that a pool implementsNamespacedPoolInterfaceand wrap it with a dedicated subclass that also implements it.
Workaround
Environment
traceway/opentelemetry-symfony(current main)Let me know what solution you prefer?