-
Notifications
You must be signed in to change notification settings - Fork 192
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
support refactored otlp export config #1477
Merged
brettmc
merged 6 commits into
open-telemetry:main
from
brettmc:config-sdk-otlp-refactor
Jan 20, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1366eca
support refactored otlp export config
brettmc 8479bae
use const, remove insecure from otlp_http config
brettmc 39dc1e1
Apply suggestions from code review
brettmc b4aeff9
set default endpoints, fix review feedback
brettmc 3e2bde9
move endpoint out of yaml anchor
brettmc df1737b
convert timeouts from millis to seconds
brettmc 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 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
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
85 changes: 85 additions & 0 deletions
85
src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlpHttp.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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Logs; | ||
|
||
use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
use OpenTelemetry\API\Common\Time\ClockInterface; | ||
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\Common\Configuration\Parser\MapParser; | ||
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 LogRecordExporterOtlpHttp implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* endpoint: string, | ||
* certificate: ?string, | ||
* client_key: ?string, | ||
* client_certificate: ?string, | ||
* headers: list<array{name: string, value: string}>, | ||
* headers_list: ?string, | ||
* compression: 'gzip'|null, | ||
* timeout: int<0, max>, | ||
* encoding: 'protobuf'|'json', | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): LogRecordExporterInterface | ||
{ | ||
$headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']); | ||
|
||
return new LogsExporter(Registry::transportFactory('http')->create( | ||
endpoint: $properties['endpoint'], | ||
contentType: match ($properties['encoding']) { | ||
'protobuf' => ContentTypes::PROTOBUF, | ||
'json' => ContentTypes::JSON, | ||
}, | ||
headers: $headers, | ||
compression: $properties['compression'], | ||
timeout: $properties['timeout'] / ClockInterface::MILLIS_PER_SECOND, | ||
cacert: $properties['certificate'], | ||
cert: $properties['client_certificate'], | ||
key: $properties['client_certificate'], | ||
)); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
{ | ||
$node = $builder->arrayNode('otlp_http'); | ||
$node | ||
->children() | ||
->enumNode('encoding')->defaultValue('protobuf')->values(['protobuf', 'json'])->end() | ||
->scalarNode('endpoint')->defaultValue('http://localhost:4318/v1/logs')->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('client_key')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('client_certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->arrayNode('headers') | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('name')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('value')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->end() | ||
->end() | ||
->end() | ||
->scalarNode('headers_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->enumNode('compression')->values(['gzip'])->defaultNull()->end() | ||
->integerNode('timeout')->min(0)->defaultValue(10000)->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
102 changes: 102 additions & 0 deletions
102
src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlpHttp.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,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics; | ||
|
||
use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
use OpenTelemetry\API\Common\Time\ClockInterface; | ||
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\Common\Configuration\Parser\MapParser; | ||
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 MetricExporterOtlpHttp implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* encoding: 'protobuf'|'json', | ||
* endpoint: string, | ||
* certificate: ?string, | ||
* client_key: ?string, | ||
* client_certificate: ?string, | ||
* headers: list<array{name: string, value: string}>, | ||
* headers_list: ?string, | ||
* compression: 'gzip'|null, | ||
* timeout: int<0, max>, | ||
* temporality_preference: 'cumulative'|'delta'|'lowmemory', | ||
* default_histogram_aggregation: 'explicit_bucket_histogram|base2_exponential_bucket_histogram', | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): MetricExporterInterface | ||
{ | ||
$headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']); | ||
|
||
$temporality = match ($properties['temporality_preference']) { | ||
'cumulative' => Temporality::CUMULATIVE, | ||
'delta' => Temporality::DELTA, | ||
'lowmemory' => null, | ||
}; | ||
|
||
return new MetricExporter(Registry::transportFactory('http')->create( | ||
endpoint: $properties['endpoint'], | ||
contentType: match ($properties['encoding']) { | ||
'protobuf' => ContentTypes::PROTOBUF, | ||
'json' => ContentTypes::JSON, | ||
}, | ||
headers: $headers, | ||
compression: $properties['compression'], | ||
timeout: $properties['timeout'] / ClockInterface::MILLIS_PER_SECOND, | ||
cacert: $properties['certificate'], | ||
cert: $properties['client_certificate'], | ||
key: $properties['client_certificate'], | ||
), $temporality); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition | ||
{ | ||
$node = $builder->arrayNode('otlp_http'); | ||
$node | ||
->children() | ||
->enumNode('encoding')->defaultValue('protobuf')->values(['protobuf', 'json'])->end() | ||
->scalarNode('endpoint')->defaultValue('http://localhost:4318/v1/metrics')->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('client_key')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->scalarNode('client_certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->arrayNode('headers') | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('name')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('value')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() | ||
->end() | ||
->end() | ||
->end() | ||
->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(10000)->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; | ||
} | ||
} |
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.
unrelated but noticed when adding transport-grpc