Skip to content

Allow to disable auto register subscriber on bundle boot #1

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
Feb 18, 2020
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
5 changes: 4 additions & 1 deletion src/JaegerMongoDbBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class JaegerMongoDbBundle extends Bundle
public function boot()
{
parent::boot();
\MongoDB\Driver\Monitoring\addSubscriber($this->container->get('jaeger.mongodb.query.time.collector'));

if ($this->container->getParameter('jaeger.mongodb.auto_subscribe')) {
\MongoDB\Driver\Monitoring\addSubscriber($this->container->get('jaeger.mongodb.query.time.collector'));
}
}


Expand Down
32 changes: 32 additions & 0 deletions src/Resources/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

namespace Jaeger\MongoDb\Symfony\Resources\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('jaeger_mongodb');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root('jaeger_mongodb');
}

// @formatter:off
$rootNode
->children()
->booleanNode('auto_subscribe')
->info('Register collector on bundle boot')
->defaultTrue()
->end()
->end();
// @formatter:on

return $treeBuilder;
}
}
10 changes: 10 additions & 0 deletions src/Resources/DependencyInjection/JaegerMongoDbExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ public function load(array $configs, ContainerBuilder $container)
new FileLocator(__DIR__ . '/../config')
);
$loader->load('services.yml');

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('jaeger.mongodb.auto_subscribe', $config['auto_subscribe']);
}

public function getAlias(): string
{
return 'jaeger_mongodb';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symfony provides jaeger_mongo_db alias, which is inconsistent with used DI prefix in configs

}
}