Skip to content

Commit

Permalink
use MapParser to process headers_list
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Nov 12, 2024
1 parent 9ff4923 commit d08b170
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenTelemetry\Contrib\Otlp\LogsExporter;
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser;
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
use OpenTelemetry\SDK\Registry;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
Expand Down Expand Up @@ -41,8 +42,7 @@ public function createPlugin(array $properties, Context $context): LogRecordExpo
{
$protocol = $properties['protocol'];

$headers_list = array_column(array_map(fn ($item) => explode('=', $item), explode(',', $properties['headers_list'] ?? '')), 1, 0);
$headers = array_column($properties['headers'], 'value', 'name') + $headers_list;
$headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']);

return new LogsExporter(Registry::transportFactory($protocol)->create(
endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::LOGS, $protocol),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenTelemetry\Contrib\Otlp\MetricExporter;
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser;
use OpenTelemetry\SDK\Metrics\Data\Temporality;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use OpenTelemetry\SDK\Registry;
Expand Down Expand Up @@ -44,8 +45,7 @@ public function createPlugin(array $properties, Context $context): MetricExporte
{
$protocol = $properties['protocol'];

$headers_list = array_column(array_map(fn ($item) => explode('=', $item), explode(',', $properties['headers_list'] ?? '')), 1, 0);
$headers = array_column($properties['headers'], 'value', 'name') + $headers_list;
$headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']);

$temporality = match ($properties['temporality_preference']) {
'cumulative' => Temporality::CUMULATIVE,
Expand Down
4 changes: 2 additions & 2 deletions src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser;
use OpenTelemetry\SDK\Registry;
use OpenTelemetry\SDK\Trace\SpanExporterInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
Expand Down Expand Up @@ -41,8 +42,7 @@ public function createPlugin(array $properties, Context $context): SpanExporterI
{
$protocol = $properties['protocol'];

$headers_list = array_column(array_map(fn ($item) => explode('=', $item), explode(',', $properties['headers_list'] ?? '')), 1, 0);
$headers = array_column($properties['headers'], 'value', 'name') + $headers_list;
$headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']);

return new SpanExporter(Registry::transportFactory($protocol)->create(
endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::TRACE, $protocol),
Expand Down

0 comments on commit d08b170

Please sign in to comment.