From 9ff49231f4d44fc8086f8e455ad3c5fa268f266d Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 7 Nov 2024 23:44:41 +1100 Subject: [PATCH 1/6] add sdk-config 0.3 support for key/value headers and attributes - headers and attributes are now arrays with `key` and `value` elements - headers can optionally contain a `headers_list` element which supports a lower-priority CSV of key/value entries - attributes can optionally contain an `attributes_list` element which supports a lower-priority CSV of key/value entries --- examples/load_config.yaml | 4 +- examples/load_config_env.yaml | 3 +- .../Logs/LogRecordExporterOtlp.php | 16 ++++- .../Metrics/MetricExporterOtlp.php | 16 ++++- .../ComponentProvider/OpenTelemetrySdk.php | 19 +++++- .../Trace/SpanExporterOtlp.php | 16 ++++- .../Config/configurations/anchors.yaml | 3 +- .../Config/configurations/kitchen-sink.yaml | 68 +++++++++++++------ 8 files changed, 111 insertions(+), 34 deletions(-) diff --git a/examples/load_config.yaml b/examples/load_config.yaml index d4d8d4de4..0535a6dbb 100644 --- a/examples/load_config.yaml +++ b/examples/load_config.yaml @@ -2,7 +2,9 @@ file_format: '0.3' resource: attributes: - service.name: opentelemetry-demo + - name: service.name + value: opentelemetry-demo + attributes_list: service.name=unused,example.foo=foo_value,example.bar=bar_value propagators: composite: [ tracecontext, baggage ] diff --git a/examples/load_config_env.yaml b/examples/load_config_env.yaml index b593419be..ba760b228 100644 --- a/examples/load_config_env.yaml +++ b/examples/load_config_env.yaml @@ -4,7 +4,8 @@ disabled: ${OTEL_SDK_DISABLED} resource: attributes: - service.name: ${OTEL_SERVICE_NAME} + - name: service.name + value: ${OTEL_SERVICE_NAME} propagators: composite: [ tracecontext, baggage ] diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index 6ee171296..ec31a6788 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -31,7 +31,8 @@ final class LogRecordExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: array, + * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, * } $properties @@ -40,10 +41,13 @@ 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; + return new LogsExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::LOGS, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], @@ -63,8 +67,14 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit ->scalarNode('client_key')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->scalarNode('client_certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->arrayNode('headers') - ->scalarPrototype()->end() + ->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(10)->end() ->end() diff --git a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php index b94015b26..d968a0a38 100644 --- a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php @@ -32,7 +32,8 @@ final class MetricExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: array, + * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, * temporality_preference: 'cumulative'|'delta'|'lowmemory', @@ -43,6 +44,9 @@ 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; + $temporality = match ($properties['temporality_preference']) { 'cumulative' => Temporality::CUMULATIVE, 'delta' => Temporality::DELTA, @@ -52,7 +56,7 @@ public function createPlugin(array $properties, Context $context): MetricExporte return new MetricExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::METRICS, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], @@ -72,8 +76,14 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit ->scalarNode('client_key')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->scalarNode('client_certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->arrayNode('headers') - ->scalarPrototype()->end() + ->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(10)->end() ->enumNode('temporality_preference') diff --git a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php index 3cd1c1b44..a7bcea8c3 100644 --- a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php +++ b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php @@ -56,6 +56,7 @@ final class OpenTelemetrySdk implements ComponentProvider * disabled: bool, * resource: array{ * attributes: array, + * attributes_list: ?string, * schema_url: ?string, * }, * attribute_limits: array{ @@ -113,10 +114,12 @@ public function createPlugin(array $properties, Context $context): SdkBuilder if ($properties['disabled']) { return $sdkBuilder; } - + $attributes_list = array_column(array_map(fn ($item) => explode('=', $item), explode(',', $properties['resource']['attributes_list'] ?? '')), 1, 0); + $attributes = array_column($properties['resource']['attributes'], 'value', 'name') + $attributes_list; + //todo merge with attributes_list $resource = ResourceInfoFactory::defaultResource() ->merge(ResourceInfo::create( - attributes: Attributes::create($properties['resource']['attributes']), + attributes: Attributes::create($attributes), schemaUrl: $properties['resource']['schema_url'], )); @@ -284,8 +287,18 @@ private function getResourceConfig(): ArrayNodeDefinition ->addDefaultsIfNotSet() ->children() ->arrayNode('attributes') - ->variablePrototype()->end() + ->arrayPrototype() + ->children() + ->scalarNode('name')->isRequired()->end() + ->variableNode('value')->isRequired()->end() + // @todo use type to validate and/or cast attributes + ->enumNode('type')->defaultNull() + ->values(['string', 'bool', 'int', 'double', 'string_array', 'bool_array', 'int_array', 'double_array']) + ->end() + ->end() + ->end() ->end() + ->scalarNode('attributes_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->scalarNode('schema_url')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->end(); diff --git a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php index 4823ed898..c1090a6bb 100644 --- a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php @@ -31,7 +31,8 @@ final class SpanExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: array, + * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, * } $properties @@ -40,10 +41,13 @@ 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; + return new SpanExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::TRACE, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], @@ -63,8 +67,14 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit ->scalarNode('client_key')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->scalarNode('client_certificate')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->arrayNode('headers') - ->scalarPrototype()->end() + ->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(10)->end() ->end() diff --git a/tests/Integration/Config/configurations/anchors.yaml b/tests/Integration/Config/configurations/anchors.yaml index 1d821aeac..ea6121ac1 100644 --- a/tests/Integration/Config/configurations/anchors.yaml +++ b/tests/Integration/Config/configurations/anchors.yaml @@ -9,7 +9,8 @@ exporters: client_key: /app/cert.pem client_certificate: /app/cert.pem headers: - api-key: !!str 1234 + - name: api-key + value: "str 1234" compression: gzip timeout: 10000 diff --git a/tests/Integration/Config/configurations/kitchen-sink.yaml b/tests/Integration/Config/configurations/kitchen-sink.yaml index f1528e98e..e0dcaf557 100644 --- a/tests/Integration/Config/configurations/kitchen-sink.yaml +++ b/tests/Integration/Config/configurations/kitchen-sink.yaml @@ -74,11 +74,13 @@ logger_provider: # # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE client_certificate: /app/cert.pem - # Configure headers. - # - # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_LOGS_HEADERS + # Configure headers. Entries have higher priority than entries from .headers_list. headers: - api-key: "1234" + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" # Configure compression. # # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION @@ -138,11 +140,13 @@ meter_provider: # # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE client_certificate: /app/cert.pem - # Configure headers. - # - # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_METRICS_HEADERS + # Configure headers. Entries have higher priority than entries from .headers_list. headers: - api-key: !!str 1234 + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" # Configure compression. # # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION @@ -244,11 +248,13 @@ tracer_provider: # # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE client_certificate: /app/cert.pem - # Configure headers. - # - # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_HEADERS + # Configure headers. Entries have higher priority than entries from .headers_list. headers: - api-key: !!str 1234 + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" # Configure compression. # # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION @@ -340,14 +346,38 @@ tracer_provider: # Configure resource for all signals. resource: - # Configure resource attributes. - # - # Environment variable: OTEL_RESOURCE_ATTRIBUTES + # Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list. + # Entries must contain .name nand .value, and may optionally include .type, which defaults ot "string" if not set. The value must match the type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array. attributes: - # Configure `service.name` resource attribute - # - # Environment variable: OTEL_SERVICE_NAME - service.name: !!str "unknown_service" + - name: service.name + value: unknown_service + - name: string_key + value: value + type: string + - name: bool_key + value: true + type: bool + - name: int_key + value: 1 + type: int + - name: double_key + value: 1.1 + type: double + - name: string_array_key + value: [ "value1", "value2" ] + type: string_array + - name: bool_array_key + value: [ true, false ] + type: bool_array + - name: int_array_key + value: [ 1, 2 ] + type: int_array + - name: double_array_key + value: [ 1.1, 2.2 ] + type: double_array + # Configure resource attributes. Entries have lower priority than entries from .resource.attributes. + # The value is a list of comma separated key-value pairs matching the format of OTEL_RESOURCE_ATTRIBUTES. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details. + attributes_list: "service.namespace=my-namespace,service.version=1.0.0" # Configure the resource schema URL. schema_url: https://opentelemetry.io/schemas/1.27.0 From d08b1703f40d03218ff5fe72e518fb7db54b499a Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 12 Nov 2024 13:22:16 +1100 Subject: [PATCH 2/6] use MapParser to process headers_list --- .../SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php | 4 ++-- .../SDK/ComponentProvider/Metrics/MetricExporterOtlp.php | 4 ++-- src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index ec31a6788..9bc825d28 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -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; @@ -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), diff --git a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php index d968a0a38..053385d69 100644 --- a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php @@ -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; @@ -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, diff --git a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php index c1090a6bb..e18da3d78 100644 --- a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php @@ -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; @@ -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), From def56f1e4173cf184746c2b35dbb568aa6fa3db7 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 14 Nov 2024 10:26:13 +1100 Subject: [PATCH 3/6] Update src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php Co-authored-by: Tobias Bachert --- src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index 9bc825d28..4a829797b 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -32,7 +32,7 @@ final class LogRecordExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, From 9bf126fe50a2b9f5bb22897a4ffbac8973be2a78 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 18 Nov 2024 14:58:53 +1100 Subject: [PATCH 4/6] update phpdoc for headers, improve attribute processing --- .../SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php | 2 +- .../SDK/ComponentProvider/Metrics/MetricExporterOtlp.php | 2 +- src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php | 5 ++--- src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php | 2 +- src/SDK/Metrics/Stream/DeltaStorage.php | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index 4a829797b..67607a690 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -32,7 +32,7 @@ final class LogRecordExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: list, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, diff --git a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php index 053385d69..ecdaaadd4 100644 --- a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php @@ -33,7 +33,7 @@ final class MetricExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, diff --git a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php index a7bcea8c3..cae7ec901 100644 --- a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php +++ b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php @@ -13,6 +13,7 @@ use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory; use OpenTelemetry\SDK\Logs\EventLoggerProvider; use OpenTelemetry\SDK\Logs\LoggerProvider; @@ -114,9 +115,7 @@ public function createPlugin(array $properties, Context $context): SdkBuilder if ($properties['disabled']) { return $sdkBuilder; } - $attributes_list = array_column(array_map(fn ($item) => explode('=', $item), explode(',', $properties['resource']['attributes_list'] ?? '')), 1, 0); - $attributes = array_column($properties['resource']['attributes'], 'value', 'name') + $attributes_list; - //todo merge with attributes_list + $attributes = array_column($properties['resource']['attributes'], 'value', 'name') + MapParser::parse($properties['resource']['attributes_list']); $resource = ResourceInfoFactory::defaultResource() ->merge(ResourceInfo::create( attributes: Attributes::create($attributes), diff --git a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php index e18da3d78..37b290b91 100644 --- a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php @@ -32,7 +32,7 @@ final class SpanExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, diff --git a/src/SDK/Metrics/Stream/DeltaStorage.php b/src/SDK/Metrics/Stream/DeltaStorage.php index 066d2d948..52c987c4b 100644 --- a/src/SDK/Metrics/Stream/DeltaStorage.php +++ b/src/SDK/Metrics/Stream/DeltaStorage.php @@ -14,7 +14,7 @@ */ final class DeltaStorage { - private Delta $head; + private readonly Delta $head; public function __construct(private readonly AggregationInterface $aggregation) { From 83ea91aa28202dc764541763947aa873306cd0e8 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 18 Nov 2024 15:37:14 +1100 Subject: [PATCH 5/6] revert accidental unrelated fix --- src/SDK/Metrics/Stream/DeltaStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDK/Metrics/Stream/DeltaStorage.php b/src/SDK/Metrics/Stream/DeltaStorage.php index 52c987c4b..066d2d948 100644 --- a/src/SDK/Metrics/Stream/DeltaStorage.php +++ b/src/SDK/Metrics/Stream/DeltaStorage.php @@ -14,7 +14,7 @@ */ final class DeltaStorage { - private readonly Delta $head; + private Delta $head; public function __construct(private readonly AggregationInterface $aggregation) { From 35216e78812fd596652f82e085c0087cb581d90d Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 18 Nov 2024 20:25:03 +1100 Subject: [PATCH 6/6] revert headers phpdoc --- src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php | 2 +- src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php | 2 +- src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index 67607a690..4a829797b 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -32,7 +32,7 @@ final class LogRecordExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: list, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, diff --git a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php index ecdaaadd4..6e566304e 100644 --- a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php @@ -33,7 +33,7 @@ final class MetricExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: list, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, diff --git a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php index 37b290b91..32e2c0521 100644 --- a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php @@ -32,7 +32,7 @@ final class SpanExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: list, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>,