Skip to content

[Bug] TelemetryCompilerPass ignores SYLIUS_TELEMETRY_ENABLED #496

Description

@mneuville

SyliusRefundPlugin version affected: 1.6.1

Description

SyliusRefundPlugin::build() unconditionally registers Sylius\Telemetry\TelemetryCompilerPass (from the sylius/telemetry package, v1.0.1):

public function build(ContainerBuilder $container): void
{
    parent::build($container);
    $container->addCompilerPass(new TelemetryCompilerPass());
}

That compiler pass loads every sylius.telemetry.* service (the kernel.terminate listener,
all data providers, the HTTP sender, etc.) without ever checking the SYLIUS_TELEMETRY_ENABLED
env var

Steps to reproduce

On a Sylius application with sylius/refund-plugin installed:

  1. Run with telemetry explicitly enabled; the services are listed, as expected:
SYLIUS_TELEMETRY_ENABLED=1 APP_ENV=prod php bin/console debug:container sylius.telemetry.listener --env=prod --no-debug
  1. Run again with telemetry explicitly disabled; the same services are still listed,
    which is the bug:
SYLIUS_TELEMETRY_ENABLED=0 APP_ENV=prod php bin/console debug:container sylius.telemetry.listener --env=prod --no-debug
  1. To confirm TelemetryCompilerPass registration is the exact cause, comment out the single
    line in vendor/sylius/refund-plugin/src/SyliusRefundPlugin.php:
   final class SyliusRefundPlugin extends Bundle
   {
       use SyliusPluginTrait;

       public function build(ContainerBuilder $container): void
       {
           parent::build($container);
           // $container->addCompilerPass(new TelemetryCompilerPass());
       }
   }
  1. Re-run the same command as step 2:
SYLIUS_TELEMETRY_ENABLED=0 APP_ENV=prod php bin/console debug:container sylius.telemetry.listener --env=prod --no-debug

The telemetry services are now correctly absent:
No services found that match "sylius.telemetry.listener".

Thank you for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConfirmed bugs or bugfixes.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions