Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanExporterZipkin",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanProcessorBatch",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanProcessorSimple",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanSuppressionStrategySemConv",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanSuppressionStrategySpanKind",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\AggregationResolverDefault",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterConsole",
Expand All @@ -172,6 +174,8 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\HttpConfigProvider",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Distribution\\DistributionConfigurationSdk",

"OpenTelemetry\\Example\\ExampleConfigProvider",

"OpenTelemetry\\Tests\\Integration\\Config\\ComponentProvider\\Detector\\Container",
Expand All @@ -188,6 +192,11 @@
"OpenTelemetry\\API\\Instrumentation\\Configuration\\General\\ConfigEnv\\EnvComponentLoaderHttpConfig",
"OpenTelemetry\\API\\Instrumentation\\Configuration\\General\\ConfigEnv\\EnvComponentLoaderPeerConfig",

"OpenTelemetry\\SDK\\ConfigEnv\\Trace\\SpanSuppressionStrategySemConv",
"OpenTelemetry\\SDK\\ConfigEnv\\Trace\\SpanSuppressionStrategySpanKind",

"OpenTelemetry\\SDK\\ConfigEnv\\Distribution\\DistributionConfigurationSdk",

"OpenTelemetry\\Example\\ExampleConfigLoader"
],
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\HookManagerInterface": [
Expand Down
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');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$node = $builder->arrayNode('opentelemetry_php');
$node = $builder->arrayNode('opentelemetry_php/development');

$node
->children()
->append($registry->component('span_suppression_strategy/development', SpanSuppressionStrategy::class))
->end()
;

return $node;
}
}
13 changes: 13 additions & 0 deletions src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use OpenTelemetry\Context\Propagation\ResponsePropagatorInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Distribution\DistributionConfiguration;
use OpenTelemetry\SDK\Common\Distribution\DistributionRegistry;
use OpenTelemetry\SDK\Common\Distribution\SdkDistribution;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Common\InstrumentationScope\Configurator;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
Expand Down Expand Up @@ -169,6 +172,7 @@ final class OpenTelemetrySdk implements ComponentProvider
* }>
* },
* },
* distribution: list<ComponentPlugin<DistributionConfiguration>>,
* } $properties
*/
#[\Override]
Expand All @@ -194,6 +198,13 @@ public function createPlugin(array $properties, Context $context): SdkBuilder
return $sdkBuilder;
}

$distributionProperties = new DistributionRegistry();
foreach ($properties['distribution'] as $distributionConfiguration) {
$distributionProperties->add($distributionConfiguration->create($context));
}

$distributionConfiguration = $distributionProperties->getDistributionConfiguration(SdkDistribution::class) ?? new SdkDistribution();

//priorities: 1. attributes 2. attributes_list, 3. detected (after applying include/exclude)
$schemaUrl = $properties['resource']['schema_url'];
/** @var ResourceDetectorInterface[] $detectors */
Expand Down Expand Up @@ -277,6 +288,7 @@ public function createPlugin(array $properties, Context $context): SdkBuilder
linkCountLimit: $properties['tracer_provider']['limits']['link_count_limit'],
),
configurator: $configurator,
spanSuppressionStrategy: $distributionConfiguration->spanSuppressionStrategy,
);

// </editor-fold>
Expand Down Expand Up @@ -419,6 +431,7 @@ public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $buil
->append($this->getMeterProviderConfig($registry, $builder))
->append($this->getLoggerProviderConfig($registry, $builder))
->append($this->getExperimentalResponsePropagatorConfig($registry, $builder))
->append($registry->componentMap('distribution', DistributionConfiguration::class)->defaultValue([]))
->end();

return $node;
Expand Down
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');
}
}
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');
}
}
8 changes: 6 additions & 2 deletions src/Config/SDK/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": "^8.1",
"open-telemetry/api": "^1.8",
"open-telemetry/context": "^1.4",
"open-telemetry/sdk": "^1.8",
"open-telemetry/sdk": "^1.14",
"symfony/config": "^5.4 || ^6.4 || ^7.0 || ^8.0",
"tbachert/spi": "^1.0.5"
},
Expand Down Expand Up @@ -59,6 +59,8 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanExporterZipkin",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanProcessorBatch",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanProcessorSimple",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanSuppressionStrategySemConv",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Trace\\SpanSuppressionStrategySpanKind",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\AggregationResolverDefault",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterConsole",
Expand All @@ -82,7 +84,9 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Service",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\HttpConfigProvider",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider"
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Distribution\\DistributionConfigurationSdk"
],
"OpenTelemetry\\Config\\SDK\\Configuration\\Environment\\EnvSourceProvider": [
"OpenTelemetry\\Config\\SDK\\Configuration\\Environment\\Adapter\\SymfonyDotenvProvider",
Expand Down
1 change: 1 addition & 0 deletions src/SDK/Common/Configuration/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ interface Variables
public const OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN = 'OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN';
public const OTEL_CONFIG_FILE = 'OTEL_CONFIG_FILE';
public const OTEL_EXPERIMENTAL_RESPONSE_PROPAGATORS = 'OTEL_EXPERIMENTAL_RESPONSE_PROPAGATORS';
public const OTEL_EXPERIMENTAL_SPAN_SUPPRESSION_STRATEGY = 'OTEL_EXPERIMENTAL_SPAN_SUPPRESSION_STRATEGY';
}
9 changes: 9 additions & 0 deletions src/SDK/Common/Distribution/DistributionConfiguration.php
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
{
}
15 changes: 15 additions & 0 deletions src/SDK/Common/Distribution/DistributionProperties.php
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;
}
25 changes: 25 additions & 0 deletions src/SDK/Common/Distribution/DistributionRegistry.php
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;
}
}
16 changes: 16 additions & 0 deletions src/SDK/Common/Distribution/SdkDistribution.php
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 src/SDK/ConfigEnv/Distribution/DistributionConfigurationSdk.php
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 src/SDK/ConfigEnv/Trace/SpanSuppressionStrategySemConv.php
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';
}
}
Loading
Loading