Skip to content

Commit

Permalink
allow empty keys
Browse files Browse the repository at this point in the history
since open-telemetry/opentelemetry-specification#4269 empty keys are allows, and NULL is no longer equivalent to unset
  • Loading branch information
brettmc committed Dec 11, 2024
1 parent 2619859 commit ef569b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
3 changes: 0 additions & 3 deletions src/Config/SDK/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OpenTelemetry\Config\SDK\Configuration\Internal\EnvSubstitutionNormalization;
use OpenTelemetry\Config\SDK\Configuration\Internal\ResourceCollection;
use OpenTelemetry\Config\SDK\Configuration\Internal\TrackingEnvReader;
use OpenTelemetry\Config\SDK\Configuration\Internal\TreatNullAsUnsetNormalization;
use OpenTelemetry\Config\SDK\Configuration\Loader\YamlExtensionFileLoader;
use OpenTelemetry\Config\SDK\Configuration\Loader\YamlSymfonyFileLoader;
use function serialize;
Expand Down Expand Up @@ -134,8 +133,6 @@ private function compileFactory(): CompiledConfigurationFactory
$envReader = new TrackingEnvReader($this->envReader);
// Parse MUST perform environment variable substitution.
(new EnvSubstitutionNormalization($envReader))->apply($root);
// Parse MUST interpret null as equivalent to unset.
(new TreatNullAsUnsetNormalization())->apply($root);

$node = $root->getNode(forceRootNode: true);

Expand Down
32 changes: 16 additions & 16 deletions tests/Integration/Config/configurations/kitchen-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ logger_provider:
# Configure exporter.
exporter:
# Configure exporter to be console.
console: {}
console:
# Configure log record limits. See also attribute_limits.
limits:
# Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit.
Expand All @@ -98,7 +98,7 @@ meter_provider:
pull:
# Configure exporter.
exporter:
console: {}
console:
# Configure metric producers.
producers:
- # Configure metric producer to be opencensus.
Expand Down Expand Up @@ -162,7 +162,7 @@ meter_provider:
# Configure exporter.
exporter:
# Configure exporter to be console.
console: {}
console:
# Configure views. Each view has a selector which determines the instrument(s) it applies to, and a configuration for the resulting stream(s).
views:
- # Configure view selector. Selection criteria is additive as described in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#instrument-selection-criteria.
Expand Down Expand Up @@ -312,7 +312,7 @@ tracer_provider:
# Configure exporter.
exporter:
# Configure exporter to be console.
console: {}
console:
# Configure span limits. See also attribute_limits.
limits:
# Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit.
Expand Down Expand Up @@ -348,24 +348,24 @@ tracer_provider:
ratio: 0.0001
# Configure remote_parent_sampled sampler.
# If omitted or null, always_on is used.
# remote_parent_sampled:
# # Configure sampler to be always_on.
# always_on:
remote_parent_sampled:
# Configure sampler to be always_on.
always_on:
# Configure remote_parent_not_sampled sampler.
# If omitted or null, always_off is used.
# remote_parent_not_sampled:
# # Configure sampler to be always_off.
# always_off:
remote_parent_not_sampled:
# Configure sampler to be always_off.
always_off:
# Configure local_parent_sampled sampler.
# If omitted or null, always_on is used.
# local_parent_sampled:
# # Configure sampler to be always_on.
# always_on:
local_parent_sampled:
# Configure sampler to be always_on.
always_on:
# Configure local_parent_not_sampled sampler.
# If omitted or null, always_off is used.
# local_parent_not_sampled:
# # Configure sampler to be always_off.
# always_off:
local_parent_not_sampled:
# Configure sampler to be always_off.
always_off:
# Configure resource for all signals.
# If omitted, the default resource is used.
resource:
Expand Down
16 changes: 1 addition & 15 deletions tests/Unit/Config/SDK/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
float_key: 1.1 # Interpreted as type float, tag URI tag:yaml.org,2002:float
combo_string_key: foo value 1.1 # Interpreted as type string, tag URI tag:yaml.org,2002:str
string_key_with_default: fallback # Interpreted as type string, tag URI tag:yaml.org,2002:str
# undefined_key removed as null is treated as unset
# undefined_key: # Interpreted as type null, tag URI tag:yaml.org,2002:null
undefined_key: # Interpreted as type null, tag URI tag:yaml.org,2002:null
${STRING_VALUE}: value # Interpreted as type string, tag URI tag:yaml.org,2002:str
YAML),
self::getPropertiesFromPlugin($parsed),
Expand Down Expand Up @@ -167,19 +166,6 @@ public function test_env_substitution_non_string(): void
$this->assertSame(2048, self::getPropertiesFromPlugin($parsed)['attribute_limits']['attribute_value_length_limit']);
}

public function test_treat_null_as_unset(): void
{
$parsed = self::factory()->process([[
'file_format' => '0.1',
'attribute_limits' => [
'attribute_count_limit' => null,
],
]]);

$this->assertInstanceOf(ComponentPlugin::class, $parsed);
$this->assertSame(128, self::getPropertiesFromPlugin($parsed)['attribute_limits']['attribute_count_limit']);
}

/**
* @psalm-suppress UndefinedThisPropertyFetch,PossiblyNullFunctionCall
*/
Expand Down

0 comments on commit ef569b7

Please sign in to comment.