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 9 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: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorBaggage",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorComposite",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorJaeger",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorOtTrace",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorTraceContext",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorXray",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SamplerAlwaysOff",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SamplerAlwaysOn",
Expand All @@ -143,9 +145,12 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanProcessorSimple",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\AggregationResolverDefault",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\AggregationResolverExplicitBucketHistogram",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterOtlp",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterPrometheus",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPeriodic",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPull",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterOtlp",
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Internal\TreatNullAsUnsetNormalization;
use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter;
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
use OpenTelemetry\SDK\Registry;
Expand All @@ -31,6 +32,6 @@ public function createPlugin(array $properties, Context $context): LogRecordExpo

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
return new ArrayNodeDefinition('console');
return (new ArrayNodeDefinition('console'))->attribute(TreatNullAsUnsetNormalization::ALLOW_EMPTY, true);
brettmc marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 Down Expand Up @@ -77,6 +78,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
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics;

use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Validation;
use OpenTelemetry\SDK\Metrics\DefaultAggregationProviderInterface;
use OpenTelemetry\SDK\Metrics\DefaultAggregationProviderTrait;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* @implements ComponentProvider<DefaultAggregationProviderInterface>
*/
final class AggregationResolverExplicitBucketHistogram implements ComponentProvider
{

/**
* @param array{
* boundaries: array<int|float>,
* record_min_max: bool,
* } $properties
*/
public function createPlugin(array $properties, Context $context): DefaultAggregationProviderInterface
{
// TODO Implement proper aggregation providers (default, drop, explicit_bucket_histogram, last_value, sum) to handle advisory
return new class() implements DefaultAggregationProviderInterface {
use DefaultAggregationProviderTrait;
};
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('explicit_bucket_histogram');
$node
->children()
->arrayNode('boundaries')
->prototype('scalar')->validate()->always(Validation::ensureNumber())->end()->end()
->end()
->booleanNode('record_min_max')->defaultValue(false)->end()
brettmc marked this conversation as resolved.
Show resolved Hide resolved
->end();

return $node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Internal\TreatNullAsUnsetNormalization;
use OpenTelemetry\SDK\Metrics\MetricExporter\ConsoleMetricExporter;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
Expand All @@ -27,6 +28,6 @@ public function createPlugin(array $properties, Context $context): MetricExporte

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
return new ArrayNodeDefinition('console');
return (new ArrayNodeDefinition('console'))->attribute(TreatNullAsUnsetNormalization::ALLOW_EMPTY, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ final class MetricExporterOtlp implements ComponentProvider
* headers_list: ?string,
* compression: 'gzip'|null,
* timeout: int<0, max>,
* insecure: ?bool,
* temporality_preference: 'cumulative'|'delta'|'lowmemory',
* default_histogram_aggregation: 'explicit_bucket_histogram',
* default_histogram_aggregation: 'explicit_bucket_histogram|base2_exponential_bucket_histogram',
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricExporterInterface
Expand Down Expand Up @@ -86,12 +87,13 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
->scalarNode('headers_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->enumNode('compression')->values(['gzip'])->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->integerNode('timeout')->min(0)->defaultValue(10)->end()
->booleanNode('insecure')->defaultNull()->end()
->enumNode('temporality_preference')
->values(['cumulative', 'delta', 'lowmemory'])
->defaultValue('cumulative')
->end()
->enumNode('default_histogram_aggregation')
->values(['explicit_bucket_histogram'])
->values(['explicit_bucket_histogram', 'base2_exponential_bucket_histogram'])
->defaultValue('explicit_bucket_histogram')
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics;

use OpenTelemetry\API\Behavior\LogsMessagesTrait;
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Validation;
use OpenTelemetry\SDK\Metrics\MetricExporter\NoopMetricExporter;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* @implements ComponentProvider<MetricExporterInterface>
*/
final class MetricExporterPrometheus implements ComponentProvider
{
use LogsMessagesTrait;

/**
* @param array{
* host: string,
* port: int,
* without_units: bool,
* without_type_suffix: bool,
* without_scope_info: bool,
* with_resource_constant_labels: array{
* included: list<string>,
* excluded: list<string>,
* },
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricExporterInterface
{
self::logWarning('prometheus exporter not implemented');

return new NoopMetricExporter();
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('prometheus');
$node
->children()
->scalarNode('host')->isRequired()->validate()->always(Validation::ensureString())->end()->end()
->scalarNode('port')->isRequired()->validate()->always(Validation::ensureNumber())->end()->end()
->booleanNode('without_units')->defaultFalse()->end()
->booleanNode('without_type_suffix')->defaultFalse()->end()
->booleanNode('without_scope_info')->defaultFalse()->end()
->booleanNode('without_scope_trace')->defaultFalse()->end()
->arrayNode('with_resource_constant_labels')
->children()
->arrayNode('included')
->scalarPrototype()->validate()->always(Validation::ensureString())->end()->end()
->end()
->arrayNode('excluded')
->scalarPrototype()->validate()->always(Validation::ensureString())->end()->end()
->end()
->end()
->end()
;

return $node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class MetricReaderPeriodic implements ComponentProvider
* interval: int<0, max>,
* timeout: int<0, max>,
* exporter: ComponentPlugin<MetricExporterInterface>,
* producers: array,
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricReaderInterface
Expand All @@ -41,6 +42,8 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
->integerNode('interval')->min(0)->defaultValue(5000)->end()
->integerNode('timeout')->min(0)->defaultValue(30000)->end()
->append($registry->component('exporter', MetricExporterInterface::class)->isRequired())
->arrayNode('producers') //@todo
->variablePrototype()->end()
->end()
;

Expand Down
50 changes: 50 additions & 0 deletions src/Config/SDK/ComponentProvider/Metrics/MetricReaderPull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics;

use OpenTelemetry\API\Behavior\LogsMessagesTrait;
use OpenTelemetry\Config\SDK\Configuration\ComponentPlugin;
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use OpenTelemetry\SDK\Metrics\MetricReader\NoopReader;
use OpenTelemetry\SDK\Metrics\MetricReaderInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* @implements ComponentProvider<MetricReaderInterface>
*/
final class MetricReaderPull implements ComponentProvider
{
use LogsMessagesTrait;

/**
* @param array{
* exporter: ComponentPlugin<MetricExporterInterface>,
* producers: array,
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricReaderInterface
{
self::logWarning('pull metric reader not implemented');

return new NoopReader();
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('pull');
$node
->children()
->append($registry->component('exporter', MetricExporterInterface::class)->isRequired())
->arrayNode('producers') //@todo
->variablePrototype()->end()
->end()
;

return $node;
}
}
34 changes: 29 additions & 5 deletions src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ final class OpenTelemetrySdk implements ComponentProvider
* resource: array{
* attributes: array,
* attributes_list: ?string,
* detectors: array,
* schema_url: ?string,
* },
* attribute_limits: array{
Expand All @@ -82,7 +83,10 @@ final class OpenTelemetrySdk implements ComponentProvider
* stream: array{
* name: ?string,
* description: ?string,
* attribute_keys: list<string>,
* attribute_keys: array{
* included: list<string>,
* excluded: list<string>,
* },
* aggregation: ?ComponentPlugin<DefaultAggregationProviderInterface>,
* },
* selector: array{
Expand Down Expand Up @@ -204,8 +208,9 @@ public function createPlugin(array $properties, Context $context): SdkBuilder
if (isset($view['stream']['description'])) {
$viewTemplate = $viewTemplate->withDescription($view['stream']['description']);
}
if ($view['stream']['attribute_keys']) {
$viewTemplate = $viewTemplate->withAttributeKeys($view['stream']['attribute_keys']);
// TODO Add support for excluded keys to view template
if ($view['stream']['attribute_keys']['included']) {
$viewTemplate = $viewTemplate->withAttributeKeys($view['stream']['attribute_keys']['included']);
}
if (isset($view['stream']['aggregation'])) {
// TODO Add support for aggregation providers in views to allow usage of advisory
Expand Down Expand Up @@ -298,6 +303,10 @@ private function getResourceConfig(): ArrayNodeDefinition
->end()
->end()
->scalarNode('attributes_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->arrayNode('detectors')
->variablePrototype()->end()
->end()
->scalarNode('attributes_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->scalarNode('schema_url')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->end();

Expand Down Expand Up @@ -348,6 +357,14 @@ private function getMeterProviderConfig(ComponentProviderRegistry $registry): Ar
$node
->addDefaultsIfNotSet()
->children()
->enumNode('exemplar_filter')
->values([
'trace_based',
'always_on',
'always_off',
])
->defaultValue('trace_based')
->end()
->arrayNode('views')
->arrayPrototype()
->children()
Expand All @@ -357,9 +374,16 @@ private function getMeterProviderConfig(ComponentProviderRegistry $registry): Ar
->scalarNode('name')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->scalarNode('description')->defaultNull()->validate()->always(Validation::ensureString())->end()->end()
->arrayNode('attribute_keys')
->scalarPrototype()->validate()->always(Validation::ensureString())->end()->end()
->children()
->arrayNode('included')
->scalarPrototype()->validate()->always(Validation::ensureString())->end()->end()
->end()
->arrayNode('excluded')
->scalarPrototype()->validate()->always(Validation::ensureString())->end()->end()
->end()
->end()
->end()
->append($registry->component('aggregation', DefaultAggregationProviderInterface::class))
->append($registry->componentList('aggregation', DefaultAggregationProviderInterface::class))
brettmc marked this conversation as resolved.
Show resolved Hide resolved
->end()
->end()
->arrayNode('selector')
Expand Down
Loading
Loading