Skip to content
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

declarative config 0.3+ support #1452

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 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
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\HttpConfigProvider",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider",

"OpenTelemetry\\Example\\ExampleConfigProvider"
"OpenTelemetry\\Example\\ExampleConfigProvider",

"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Metrics\\AggregationResolverExplicitBucketHistogram",
"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Metrics\\MetricExporterPrometheus",
"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Metrics\\MetricReaderPull",
"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Propagator\\TextMapPropagatorXray",
"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Propagator\\TextMapPropagatorOtTrace"
],
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\HookManagerInterface": [
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\ExtensionHookManager"
Expand Down
9 changes: 8 additions & 1 deletion examples/instrumentation/otel-sdk.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
file_format: '0.3'

propagator:
composite: []

tracer_provider:
processors:
- simple:
exporter:
console: {}
console:
sampler:
always_on:

instrumentation:
general:
php:
example_instrumentation:
enabled: true
span_name: ${EXAMPLE_INSTRUMENTATION_SPAN_NAME:-example span}
8 changes: 4 additions & 4 deletions examples/load_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ tracer_provider:
sampler:
parent_based:
root:
always_on: {}
always_on:
processors:
- simple:
exporter:
console: {}
console:
- batch:
exporter:
otlp: *otlp-exporter
meter_provider:
readers:
- periodic:
exporter:
console: {}
console:
- periodic:
exporter:
otlp:
Expand All @@ -40,7 +40,7 @@ logger_provider:
processors:
- simple:
exporter:
console: {}
console:
- batch:
exporter:
otlp: *otlp-exporter
9 changes: 5 additions & 4 deletions examples/src/ExampleConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Validation;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<InstrumentationConfiguration>
Expand All @@ -35,16 +36,16 @@ public function createPlugin(array $properties, Context $context): Instrumentati
/**
* @psalm-suppress UndefinedInterfaceMethod,PossiblyNullReference
*/
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$root = new ArrayNodeDefinition('example_instrumentation');
$root
$node = $builder->arrayNode('example_instrumentation');
$node
->children()
->scalarNode('span_name')->isRequired()->validate()->always(Validation::ensureString())->end()->end()
->end()
->canBeDisabled()
;

return $root;
return $node;
}
}
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ parameters:
message: "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface::.*#"
paths:
- src/Config/SDK
- tests/Integration/Config
-
message: "#Cannot call method .* on null#"
paths:
Expand Down
7 changes: 7 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<directory name="src/Config/SDK/ComponentProvider"/>
<directory name="tests/Integration/Config/ComponentProvider"/>
</errorLevel>
</UndefinedInterfaceMethod>
<PossiblyInvalidArgument>
<errorLevel type="suppress">
<directory name="src/Config/SDK/Configuration"/>
</errorLevel>
</PossiblyInvalidArgument>
<PossiblyNullReference>
<errorLevel type="suppress">
<directory name="src/Config/SDK/ComponentProvider"/>
Expand All @@ -50,6 +56,7 @@
<MoreSpecificImplementedParamType>
<errorLevel type="suppress">
<directory name="src/Config/SDK/ComponentProvider"/>
<directory name="tests/Integration/Config/ComponentProvider"/>
</errorLevel>
</MoreSpecificImplementedParamType>
<InvalidDocblock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<GeneralInstrumentationConfiguration>
Expand All @@ -22,22 +23,22 @@ public function createPlugin(array $properties, Context $context): GeneralInstru
return new HttpConfig($properties);
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('http');
$node = $builder->arrayNode('http');
$node
->children()
->append($this->capturedHeaders('client'))
->append($this->capturedHeaders('server'))
->append($this->capturedHeaders('client', $builder))
->append($this->capturedHeaders('server', $builder))
->end()
;

return $node;
}

private function capturedHeaders(string $name): ArrayNodeDefinition
private function capturedHeaders(string $name, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition($name);
$node = $builder->arrayNode($name);
$node
->children()
->arrayNode('request_captured_headers')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<GeneralInstrumentationConfiguration>
Expand All @@ -21,9 +22,9 @@ public function createPlugin(array $properties, Context $context): GeneralInstru
return new PeerConfig($properties);
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('peer');
$node = $builder->arrayNode('peer');
$node
->children()
->arrayNode('service_mapping')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @internal
Expand All @@ -24,7 +25,7 @@ class InstrumentationConfigurationRegistry implements ComponentProvider
* @param array{
* instrumentation: array{
* php: list<ComponentPlugin<InstrumentationConfiguration>>,
* general: list<ComponentPlugin<InstrumentationConfiguration>>
* general: list<ComponentPlugin<GeneralInstrumentationConfiguration>>
* }
* } $properties
*/
Expand All @@ -43,18 +44,16 @@ public function createPlugin(array $properties, Context $context): Configuration
return $configurationRegistry;
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$root = new ArrayNodeDefinition('open_telemetry');
$root = $builder->arrayNode('open_telemetry');
$root
->ignoreExtraKeys()
->children()
->arrayNode('instrumentation')
->ignoreExtraKeys()
->children()
->append($registry->componentList('php', InstrumentationConfiguration::class))
->append($registry->componentList('general', GeneralInstrumentationConfiguration::class))
->end()
->append($registry->componentList('php', InstrumentationConfiguration::class))
->append($registry->componentList('general', GeneralInstrumentationConfiguration::class))
->end()
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
use OpenTelemetry\SDK\Registry;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<LogRecordExporterInterface>
Expand All @@ -29,8 +30,8 @@ public function createPlugin(array $properties, Context $context): LogRecordExpo
));
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
return new ArrayNodeDefinition('console');
return $builder->arrayNode('console');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
use OpenTelemetry\SDK\Registry;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<LogRecordExporterInterface>
Expand All @@ -36,6 +37,7 @@ final class LogRecordExporterOtlp implements ComponentProvider
* headers_list: ?string,
* compression: 'gzip'|null,
* timeout: int<0, max>,
* insecure: ?bool,
* } $properties
*/
public function createPlugin(array $properties, Context $context): LogRecordExporterInterface
Expand All @@ -56,9 +58,9 @@ public function createPlugin(array $properties, Context $context): LogRecordExpo
));
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('otlp');
$node = $builder->arrayNode('otlp');
$node
->children()
->enumNode('protocol')->isRequired()->values(['http/protobuf', 'http/json', 'grpc'])->end()
Expand All @@ -77,6 +79,7 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
->scalarNode('headers_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->enumNode('compression')->values(['gzip'])->defaultNull()->end()
->integerNode('timeout')->min(0)->defaultValue(10)->end()
->booleanNode('insecure')->defaultNull()->end()
->end()
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
use OpenTelemetry\SDK\Logs\Processor\BatchLogRecordProcessor;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<LogRecordProcessorInterface>
Expand Down Expand Up @@ -42,9 +43,9 @@ public function createPlugin(array $properties, Context $context): LogRecordProc
);
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('batch');
$node = $builder->arrayNode('batch');
$node
->children()
->integerNode('schedule_delay')->min(0)->defaultValue(5000)->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface;
use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<LogRecordProcessorInterface>
Expand All @@ -31,9 +32,9 @@ public function createPlugin(array $properties, Context $context): LogRecordProc
);
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('simple');
$node = $builder->arrayNode('simple');
$node
->children()
->append($registry->component('exporter', LogRecordExporterInterface::class)->isRequired())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\SDK\Metrics\DefaultAggregationProviderInterface;
use OpenTelemetry\SDK\Metrics\DefaultAggregationProviderTrait;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<DefaultAggregationProviderInterface>
Expand All @@ -28,8 +29,8 @@ public function createPlugin(array $properties, Context $context): DefaultAggreg
};
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
return new ArrayNodeDefinition('default');
return $builder->arrayNode('default');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenTelemetry\SDK\Metrics\MetricExporter\ConsoleMetricExporter;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<MetricExporterInterface>
Expand All @@ -25,8 +26,8 @@ public function createPlugin(array $properties, Context $context): MetricExporte
return new ConsoleMetricExporter();
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
return new ArrayNodeDefinition('console');
return $builder->arrayNode('console');
}
}
Loading
Loading