public static function extendEventManager(
        ContainerInterface $container,
        ?EventManager $eventManager = null
    ): ?TraceableEventManager {
        if ($eventManager !== null) {
            $options = self::resolveOptions($container->get('config'));

            if ($options['collector']['events']) {
                $eventManager = new TraceableEventManager($eventManager, $container->get(Stopwatch::class));

                if ($container->has(LoggerInterface::class)) {
                    $eventManager->setLogger($container->get(LoggerInterface::class));
                }
            }
        }

        return $eventManager;
    }