-
Notifications
You must be signed in to change notification settings - Fork 223
Allow span suppression strategy configuration using file-based and env-based config #1920
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
Open
Nevay
wants to merge
1
commit into
open-telemetry:main
Choose a base branch
from
Nevay:feature/span-suppression-configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Config/SDK/ComponentProvider/Distribution/DistributionConfigurationSdk.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\ComponentProvider\Distribution; | ||
|
|
||
| use OpenTelemetry\API\Configuration\Config\ComponentPlugin; | ||
| use OpenTelemetry\API\Configuration\Config\ComponentProvider; | ||
| use OpenTelemetry\API\Configuration\Config\ComponentProviderRegistry; | ||
| use OpenTelemetry\API\Configuration\Context; | ||
| use OpenTelemetry\SDK\Common\Distribution\DistributionConfiguration; | ||
| use OpenTelemetry\SDK\Common\Distribution\SdkDistribution; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\NoopSuppressionStrategy\NoopSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
| use Override; | ||
| use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
|
||
| /** | ||
| * @implements ComponentProvider<DistributionConfiguration> | ||
| */ | ||
| final class DistributionConfigurationSdk implements ComponentProvider | ||
| { | ||
| /** | ||
| * @param array{ | ||
| * "span_suppression_strategy/development": ?ComponentPlugin<SpanSuppressionStrategy>, | ||
| * } $properties | ||
| * @param Context $context | ||
| * @return DistributionConfiguration | ||
| */ | ||
| #[Override] | ||
| public function createPlugin(array $properties, Context $context): DistributionConfiguration | ||
| { | ||
| return new SdkDistribution( | ||
| spanSuppressionStrategy: $properties['span_suppression_strategy/development']?->create($context) ?? new NoopSuppressionStrategy(), | ||
| ); | ||
| } | ||
|
|
||
| #[Override] | ||
| public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
| { | ||
| $node = $builder->arrayNode('opentelemetry_php'); | ||
| $node | ||
| ->children() | ||
| ->append($registry->component('span_suppression_strategy/development', SpanSuppressionStrategy::class)) | ||
| ->end() | ||
| ; | ||
|
|
||
| return $node; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Config/SDK/ComponentProvider/Trace/SpanSuppressionStrategySemConv.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\ComponentProvider\Trace; | ||
|
|
||
| use Nevay\SPI\ServiceLoader; | ||
| use OpenTelemetry\API\Configuration\Config\ComponentProvider; | ||
| use OpenTelemetry\API\Configuration\Config\ComponentProviderRegistry; | ||
| use OpenTelemetry\API\Configuration\Context; | ||
| use OpenTelemetry\API\Trace\SpanSuppression\SemanticConventionResolver; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SemanticConventionSuppressionStrategy\SemanticConventionSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
| use Override; | ||
| use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
|
||
| /** | ||
| * @implements ComponentProvider<SpanSuppressionStrategy> | ||
| */ | ||
| final class SpanSuppressionStrategySemConv implements ComponentProvider | ||
| { | ||
| /** | ||
| * @param array{} $properties | ||
| */ | ||
| #[Override] | ||
| public function createPlugin(array $properties, Context $context): SpanSuppressionStrategy | ||
| { | ||
| return new SemanticConventionSuppressionStrategy(ServiceLoader::load(SemanticConventionResolver::class)); | ||
| } | ||
|
|
||
| #[Override] | ||
| public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
| { | ||
| return $builder->arrayNode('semconv'); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/Config/SDK/ComponentProvider/Trace/SpanSuppressionStrategySpanKind.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\ComponentProvider\Trace; | ||
|
|
||
| use OpenTelemetry\API\Configuration\Config\ComponentProvider; | ||
| use OpenTelemetry\API\Configuration\Config\ComponentProviderRegistry; | ||
| use OpenTelemetry\API\Configuration\Context; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanKindSuppressionStrategy\SpanKindSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
| use Override; | ||
| use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
|
||
| /** | ||
| * @implements ComponentProvider<SpanSuppressionStrategy> | ||
| */ | ||
| final class SpanSuppressionStrategySpanKind implements ComponentProvider | ||
| { | ||
| /** | ||
| * @param array{} $properties | ||
| */ | ||
| #[Override] | ||
| public function createPlugin(array $properties, Context $context): SpanSuppressionStrategy | ||
| { | ||
| return new SpanKindSuppressionStrategy(); | ||
| } | ||
|
|
||
| #[Override] | ||
| public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
| { | ||
| return $builder->arrayNode('spankind'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\Common\Distribution; | ||
|
|
||
| interface DistributionConfiguration | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\Common\Distribution; | ||
|
|
||
| interface DistributionProperties | ||
| { | ||
| /** | ||
| * @template C of DistributionConfiguration | ||
| * @param class-string<C> $distribution | ||
| * @return C|null | ||
| */ | ||
| public function getDistributionConfiguration(string $distribution): ?DistributionConfiguration; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\Common\Distribution; | ||
|
|
||
| use Override; | ||
|
|
||
| final class DistributionRegistry implements DistributionProperties | ||
| { | ||
| private array $distributionConfigurations = []; | ||
|
|
||
| public function add(DistributionConfiguration $distributionConfiguration): self | ||
| { | ||
| $this->distributionConfigurations[$distributionConfiguration::class] = $distributionConfiguration; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| #[Override] | ||
| public function getDistributionConfiguration(string $distribution): ?DistributionConfiguration | ||
| { | ||
| return $this->distributionConfigurations[$distribution] ?? null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\Common\Distribution; | ||
|
|
||
| use OpenTelemetry\SDK\Trace\SpanSuppression\NoopSuppressionStrategy\NoopSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
|
|
||
| final class SdkDistribution implements DistributionConfiguration | ||
| { | ||
| public function __construct( | ||
| public readonly SpanSuppressionStrategy $spanSuppressionStrategy = new NoopSuppressionStrategy(), | ||
| ) { | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/SDK/ConfigEnv/Distribution/DistributionConfigurationSdk.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\ConfigEnv\Distribution; | ||
|
|
||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvComponentLoader; | ||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvComponentLoaderRegistry; | ||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvResolver; | ||
| use OpenTelemetry\API\Configuration\Context; | ||
| use OpenTelemetry\SDK\Common\Configuration\Variables; | ||
| use OpenTelemetry\SDK\Common\Distribution\DistributionConfiguration; | ||
| use OpenTelemetry\SDK\Common\Distribution\SdkDistribution; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\NoopSuppressionStrategy\NoopSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
| use Override; | ||
|
|
||
| /** | ||
| * @implements EnvComponentLoader<DistributionConfiguration> | ||
| */ | ||
| final class DistributionConfigurationSdk implements EnvComponentLoader | ||
| { | ||
| #[Override] | ||
| public function load(EnvResolver $env, EnvComponentLoaderRegistry $registry, Context $context): DistributionConfiguration | ||
| { | ||
| $spanSuppressionStrategyName = $env->string(Variables::OTEL_EXPERIMENTAL_SPAN_SUPPRESSION_STRATEGY) ?? 'none'; | ||
|
|
||
| return new SdkDistribution( | ||
| spanSuppressionStrategy: match ($spanSuppressionStrategyName) { | ||
| 'none' => new NoopSuppressionStrategy(), | ||
| default => $registry->load(SpanSuppressionStrategy::class, $spanSuppressionStrategyName, $env, $context), | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| #[Override] | ||
| public function name(): string | ||
| { | ||
| return self::class; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/SDK/ConfigEnv/Trace/SpanSuppressionStrategySemConv.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\SDK\ConfigEnv\Trace; | ||
|
|
||
| use Nevay\SPI\ServiceLoader; | ||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvComponentLoader; | ||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvComponentLoaderRegistry; | ||
| use OpenTelemetry\API\Configuration\ConfigEnv\EnvResolver; | ||
| use OpenTelemetry\API\Configuration\Context; | ||
| use OpenTelemetry\API\Trace\SpanSuppression\SemanticConventionResolver; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SemanticConventionSuppressionStrategy\SemanticConventionSuppressionStrategy; | ||
| use OpenTelemetry\SDK\Trace\SpanSuppression\SpanSuppressionStrategy; | ||
| use Override; | ||
|
|
||
| /** | ||
| * @implements EnvComponentLoader<SpanSuppressionStrategy> | ||
| */ | ||
| final class SpanSuppressionStrategySemConv implements EnvComponentLoader | ||
| { | ||
| #[Override] | ||
| public function load(EnvResolver $env, EnvComponentLoaderRegistry $registry, Context $context): SpanSuppressionStrategy | ||
| { | ||
| return new SemanticConventionSuppressionStrategy(ServiceLoader::load(SemanticConventionResolver::class)); | ||
| } | ||
|
|
||
| #[Override] | ||
| public function name(): string | ||
| { | ||
| return 'semconv'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.