-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* otlp_file config support * handle otlp_file scheme://path format * update kitchen-sink
- Loading branch information
Showing
9 changed files
with
459 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlpFile.php
This file contains 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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Logs; | ||
|
||
use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
use OpenTelemetry\Config\SDK\ComponentProvider\OutputStreamParser; | ||
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\Contrib\Otlp\ContentTypes; | ||
use OpenTelemetry\Contrib\Otlp\LogsExporter; | ||
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> | ||
*/ | ||
#[PackageDependency('open-telemetry/exporter-otlp', '^1.0.5')] | ||
final class LogRecordExporterOtlpFile implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* output_stream: string, | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): LogRecordExporterInterface | ||
{ | ||
$endpoint = OutputStreamParser::parse($properties['output_stream']); | ||
|
||
return new LogsExporter(Registry::transportFactory('stream')->create( | ||
endpoint: $endpoint, | ||
contentType: ContentTypes::NDJSON, | ||
)); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
{ | ||
$node = $builder->arrayNode('otlp_file'); | ||
$node | ||
->children() | ||
->scalarNode('output_stream')->defaultValue('stdout')->validate()->always(Validation::ensureString())->end()->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlpFile.php
This file contains 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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics; | ||
|
||
use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
use OpenTelemetry\Config\SDK\ComponentProvider\OutputStreamParser; | ||
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\Contrib\Otlp\ContentTypes; | ||
use OpenTelemetry\Contrib\Otlp\MetricExporter; | ||
use OpenTelemetry\SDK\Metrics\Data\Temporality; | ||
use OpenTelemetry\SDK\Metrics\MetricExporterInterface; | ||
use OpenTelemetry\SDK\Registry; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
||
/** | ||
* @implements ComponentProvider<MetricExporterInterface> | ||
*/ | ||
#[PackageDependency('open-telemetry/exporter-otlp', '^1.0.5')] | ||
final class MetricExporterOtlpFile implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* output_stream: string, | ||
* temporality_preference: 'cumulative'|'delta'|'lowmemory', | ||
* default_histogram_aggregation: 'explicit_bucket_histogram|base2_exponential_bucket_histogram', | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): MetricExporterInterface | ||
{ | ||
$endpoint = OutputStreamParser::parse($properties['output_stream']); | ||
|
||
$temporality = match ($properties['temporality_preference']) { | ||
'cumulative' => Temporality::CUMULATIVE, | ||
'delta' => Temporality::DELTA, | ||
'lowmemory' => null, | ||
}; | ||
|
||
return new MetricExporter(Registry::transportFactory('stream')->create( | ||
endpoint: $endpoint, | ||
contentType: ContentTypes::NDJSON, | ||
), $temporality); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
{ | ||
$node = $builder->arrayNode('otlp_file'); | ||
$node | ||
->children() | ||
->scalarNode('output_stream')->defaultValue('stdout')->validate()->always(Validation::ensureString())->end()->end() | ||
->enumNode('temporality_preference') | ||
->values(['cumulative', 'delta', 'lowmemory']) | ||
->defaultValue('cumulative') | ||
->end() | ||
->enumNode('default_histogram_aggregation') | ||
->values(['explicit_bucket_histogram', 'base2_exponential_bucket_histogram']) | ||
->defaultValue('explicit_bucket_histogram') | ||
->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
This file contains 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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class OutputStreamParser | ||
{ | ||
private static ?string $root = null; | ||
|
||
public static function setRoot(string $root): void | ||
{ | ||
self::$root = $root; | ||
} | ||
|
||
public static function reset(): void | ||
{ | ||
self::$root = null; | ||
} | ||
|
||
public static function parse(string $outputStream): string | ||
{ | ||
if ($outputStream === 'stdout') { | ||
return 'php://stdout'; | ||
} | ||
|
||
$pattern = '/^(?P<scheme>[a-zA-Z][a-zA-Z0-9]*):\/\/(?P<path>.+)$/'; | ||
if (preg_match($pattern, $outputStream, $matches) !== 1) { | ||
throw new \InvalidArgumentException('Invalid output_stream format: ' . $outputStream); | ||
} | ||
|
||
return match ($matches['scheme']) { | ||
'file' => self::$root . $matches['path'], | ||
default => throw new \InvalidArgumentException('Invalid endpoint scheme: ' . $matches['scheme']), | ||
}; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlpFile.php
This file contains 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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Trace; | ||
|
||
use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
use OpenTelemetry\Config\SDK\ComponentProvider\OutputStreamParser; | ||
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\Contrib\Otlp\ContentTypes; | ||
use OpenTelemetry\Contrib\Otlp\SpanExporter; | ||
use OpenTelemetry\SDK\Registry; | ||
use OpenTelemetry\SDK\Trace\SpanExporterInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
||
/** | ||
* @implements ComponentProvider<SpanExporterInterface> | ||
*/ | ||
#[PackageDependency('open-telemetry/exporter-otlp', '^1.0.5')] | ||
final class SpanExporterOtlpFile implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* output_stream: string, | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): SpanExporterInterface | ||
{ | ||
$endpoint = OutputStreamParser::parse($properties['output_stream']); | ||
|
||
return new SpanExporter(Registry::transportFactory('stream')->create( | ||
endpoint: $endpoint, | ||
contentType: ContentTypes::NDJSON, | ||
)); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
{ | ||
$node = $builder->arrayNode('otlp_file'); | ||
$node | ||
->children() | ||
->scalarNode('output_stream')->defaultValue('stdout')->validate()->always(Validation::ensureString())->end()->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.