Skip to content

CacheTracingPass breaks container compilation when a cache pool implements NamespacedPoolInterface #11

Description

@SebLours

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions