tbachert / otel-sdk-configuration
OpenTelemetry SDK configuration
v0.1.1
2024-03-24 17:43 UTC
Requires
- php: ^8.1
- open-telemetry/api: ^1.0
- open-telemetry/context: ^1.0
- symfony/config: ^5.4 || ^6.4 || ^7.0
Requires (Dev)
- ext-yaml: ^2.2.2
- phpunit/phpunit: ^10.5
- symfony/var-exporter: ^5.4 || ^6.4 || ^7.0
- symfony/yaml: ^5.4 || ^6.4 || ^7.0
Suggests
- ext-yaml: Allows loading config from yaml files
- symfony/yaml: Allows loading config from yaml files
- tbachert/spi: Allows defining and loading component providers from composer.json extra.spi
This package is auto-updated.
Last update: 2024-10-07 20:30:49 UTC
README
Allows creation of an extensible configuration model according to the OTel file configuration specification.
Installation
composer require tbachert/otel-sdk-configuration
Additionally, you will need either ext-yaml
or symfony/yaml
to load configuration from yaml config files.
Usage
Parsing config
$factory = new ConfigurationFactory( [ // all available providers ... ], new OpenTelemetryConfiguration(), new EnvSourceReader([ new ArrayEnvSource($_SERVER), new PhpIniEnvSource(), ]), ); $configuration = $factory->parseFile(__DIR__ . '/config.yaml'); $openTelemetry = $configuration->create(new Context());
Defining component providers
See examples for component provider examples.
Example: BatchSpanProcessor
final class SpanProcessorBatch implements ComponentProvider { /** * @param array{ * schedule_delay: int<0, max>, * export_timeout: int<0, max>, * max_queue_size: int<0, max>, * max_export_batch_size: int<0, max>, * exporter: ComponentPlugin<SpanExporter>, * } $properties */ public function createPlugin(array $properties, Context $context): SpanProcessor { // ... } public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition { $node = new ArrayNodeDefinition('batch'); $node ->children() ->integerNode('schedule_delay')->min(0)->defaultValue(5000)->end() ->integerNode('export_timeout')->min(0)->defaultValue(30000)->end() ->integerNode('max_queue_size')->min(0)->defaultValue(2048)->end() ->integerNode('max_export_batch_size')->min(0)->defaultValue(512)->end() ->append($registry->component('exporter', SpanExporter::class)->isRequired()) ->end() ; return $node; } }