diff --git a/composer.json b/composer.json index 8660c1d6a..7adbe8715 100644 --- a/composer.json +++ b/composer.json @@ -169,6 +169,7 @@ "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Composer", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Host", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Process", + "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Service", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\HttpConfigProvider", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider", diff --git a/src/Config/SDK/ComponentProvider/Detector/Service.php b/src/Config/SDK/ComponentProvider/Detector/Service.php new file mode 100644 index 000000000..55e635a8c --- /dev/null +++ b/src/Config/SDK/ComponentProvider/Detector/Service.php @@ -0,0 +1,34 @@ + + */ +final class Service implements ComponentProvider +{ + /** + * @param array{} $properties + */ + #[\Override] + public function createPlugin(array $properties, Context $context): ResourceDetectorInterface + { + return new ServiceDetector(); + } + + #[\Override] + public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition + { + return $builder->arrayNode('service'); + } +} diff --git a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php index 56749a3f4..8cfa3164a 100644 --- a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php +++ b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php @@ -62,7 +62,7 @@ final class OpenTelemetrySdk implements ComponentProvider { /** * @param array{ - * file_format: '0.4', + * file_format: '1.0-rc.2', * disabled: bool, * resource: array{ * attributes: array{ @@ -409,7 +409,7 @@ public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $buil ->isRequired() ->example('0.1') ->validate()->always(Validation::ensureString())->end() - ->validate()->ifNotInArray(['0.4'])->thenInvalid('unsupported version')->end() + ->validate()->ifNotInArray(['1.0-rc.2'])->thenInvalid('unsupported version')->end() ->end() ->booleanNode('disabled')->defaultFalse()->end() ->append($this->getResourceConfig($registry, $builder)) @@ -510,11 +510,11 @@ private function getTracerProviderConfig(ComponentProviderRegistry $registry, No ->arrayNode('tracers') ->arrayPrototype() ->children() - ->scalarNode('name')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('name')->end() ->arrayNode('config') ->addDefaultsIfNotSet() ->children() - ->booleanNode('disabled')->isRequired()->end() + ->booleanNode('disabled')->end() ->end() ->end() ->end() diff --git a/src/Config/SDK/composer.json b/src/Config/SDK/composer.json index 4036901ae..311940c88 100644 --- a/src/Config/SDK/composer.json +++ b/src/Config/SDK/composer.json @@ -80,6 +80,7 @@ "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Composer", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Host", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Process", + "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Detector\\Service", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\HttpConfigProvider", "OpenTelemetry\\Config\\SDK\\ComponentProvider\\Instrumentation\\General\\PeerConfigProvider" diff --git a/src/SDK/Trace/SpanSuppression/SemanticConventionSuppressionStrategy/SemanticConventionSuppressionStrategy.php b/src/SDK/Trace/SpanSuppression/SemanticConventionSuppressionStrategy/SemanticConventionSuppressionStrategy.php index b4e5f5dbf..8be4c345e 100644 --- a/src/SDK/Trace/SpanSuppression/SemanticConventionSuppressionStrategy/SemanticConventionSuppressionStrategy.php +++ b/src/SDK/Trace/SpanSuppression/SemanticConventionSuppressionStrategy/SemanticConventionSuppressionStrategy.php @@ -59,7 +59,7 @@ public function getSuppressor(string $name, ?string $version, ?string $schemaUrl foreach ($semanticConvention->samplingAttributes as $attribute) { $lookup[$semanticConvention->spanKind][$attribute][0] |= 1 << $i; } - foreach ($lookup[$semanticConvention->spanKind] as $attribute => $_) { + foreach (array_keys($lookup[$semanticConvention->spanKind]) as $attribute) { if (!$attributes->matches($attribute)) { $lookup[$semanticConvention->spanKind][$attribute][1] |= 1 << $i; } diff --git a/src/SDK/Trace/TracerProvider.php b/src/SDK/Trace/TracerProvider.php index 9c0e10e28..cc365cbf6 100644 --- a/src/SDK/Trace/TracerProvider.php +++ b/src/SDK/Trace/TracerProvider.php @@ -35,7 +35,7 @@ public function __construct( ?IdGeneratorInterface $idGenerator = null, ?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null, private ?Configurator $configurator = null, - private SpanSuppressionStrategy $spanSuppressionStrategy = new NoopSuppressionStrategy(), + private readonly SpanSuppressionStrategy $spanSuppressionStrategy = new NoopSuppressionStrategy(), ) { $spanProcessors ??= []; $spanProcessors = is_array($spanProcessors) ? $spanProcessors : [$spanProcessors]; diff --git a/tests/Integration/Config/ComponentProvider/Metrics/MetricExporterPrometheus.php b/tests/Integration/Config/ComponentProvider/Metrics/MetricExporterPrometheus.php index f7c2b40b1..04d436a4a 100644 --- a/tests/Integration/Config/ComponentProvider/Metrics/MetricExporterPrometheus.php +++ b/tests/Integration/Config/ComponentProvider/Metrics/MetricExporterPrometheus.php @@ -70,6 +70,7 @@ public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $buil ->end() ->end() ->end() + ->scalarNode('translation_strategy')->defaultValue('UnderscoreEscapingWithSuffixes')->end() ->end() ; diff --git a/tests/Integration/Config/ConfigurationTest.php b/tests/Integration/Config/ConfigurationTest.php index f28057c71..9ffb8e86b 100644 --- a/tests/Integration/Config/ConfigurationTest.php +++ b/tests/Integration/Config/ConfigurationTest.php @@ -221,7 +221,7 @@ public function test_resource_attributes_take_precedence_over_default_attributes ); $sdk = $factory->process([Yaml::parse(/** @lang yaml */<<<'YAML' - file_format: "0.4" + file_format: "1.0-rc.2" resource: attributes: - { name: service.name, value: test-service } @@ -240,7 +240,7 @@ public function test_resource_detectors_take_precedence_over_default_attributes( ); $sdk = $factory->process([Yaml::parse(/** @lang yaml */<<<'YAML' - file_format: "0.4" + file_format: "1.0-rc.2" resource: detection/development: detectors: @@ -262,7 +262,7 @@ public function test_resource_attributes_take_precedence_over_resource_detectors ); $sdk = $factory->process([Yaml::parse(/** @lang yaml */<<<'YAML' - file_format: "0.4" + file_format: "1.0-rc.2" resource: attributes: - { name: service.name, value: test-service } @@ -302,7 +302,7 @@ public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $buil ); $sdk = $factory->process([Yaml::parse(/** @lang yaml */<<<'YAML' - file_format: "0.4" + file_format: "1.0-rc.2" resource: attributes: - { name: service.name, value: test-service } diff --git a/tests/Integration/Config/configurations/anchors.yaml b/tests/Integration/Config/configurations/anchors.yaml index fe580d137..b251b1095 100644 --- a/tests/Integration/Config/configurations/anchors.yaml +++ b/tests/Integration/Config/configurations/anchors.yaml @@ -1,6 +1,6 @@ # anchors.yaml demonstrates anchor substitution to reuse OTLP exporter configuration across signals. -file_format: "0.4" +file_format: "1.0-rc.2" exporters: otlp: &otlp-exporter encoding: protobuf diff --git a/tests/Integration/Config/configurations/configurators.yaml b/tests/Integration/Config/configurations/configurators.yaml index 6c7bd0087..7d1ad7a62 100644 --- a/tests/Integration/Config/configurations/configurators.yaml +++ b/tests/Integration/Config/configurations/configurators.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' propagators: composite: [ tracecontext, baggage ] diff --git a/tests/Integration/Config/configurations/experimental-response-propagators-duplicate.yaml b/tests/Integration/Config/configurations/experimental-response-propagators-duplicate.yaml index a71dcb0ac..c882d54d6 100644 --- a/tests/Integration/Config/configurations/experimental-response-propagators-duplicate.yaml +++ b/tests/Integration/Config/configurations/experimental-response-propagators-duplicate.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' response_propagator/development: composite_list: "servertiming,servertiming" diff --git a/tests/Integration/Config/configurations/kitchen-sink.yaml b/tests/Integration/Config/configurations/kitchen-sink.yaml index 772d22360..7c54abc07 100644 --- a/tests/Integration/Config/configurations/kitchen-sink.yaml +++ b/tests/Integration/Config/configurations/kitchen-sink.yaml @@ -8,7 +8,7 @@ # The file format version. # The yaml format is documented at # https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema -file_format: "0.4" +file_format: "1.0-rc.2" # Configure if the SDK is disabled or not. # If omitted or null, false is used. disabled: false @@ -200,12 +200,6 @@ meter_provider: # Configure port. # If omitted or null, 9464 is used. port: 9464 - # Configure Prometheus Exporter to produce metrics without a unit suffix or UNIT metadata. - # If omitted or null, false is used. - without_units: false - # Configure Prometheus Exporter to produce metrics without a type suffix. - # If omitted or null, false is used. - without_type_suffix: false # Configure Prometheus Exporter to produce metrics without a scope info metric. # If omitted or null, false is used. without_scope_info: false @@ -225,6 +219,15 @@ meter_provider: # If omitted, .included resource attributes are included. excluded: - "service.attr1" + # Configure how Prometheus metrics are exposed. Values include: + # + # * UnderscoreEscapingWithSuffixes, the default. This fully escapes metric names for classic Prometheus metric name compatibility, and includes appending type and unit suffixes. + # * UnderscoreEscapingWithoutSuffixes, metric names will continue to escape special characters to _, but suffixes won't be attached. + # * NoUTF8EscapingWithSuffixes will disable changing special characters to _. Special suffixes like units and _total for counters will be attached. + # * NoTranslation. This strategy bypasses all metric and label name translation, passing them through unaltered. + # + # If omitted or null, UnderscoreEscapingWithSuffixes is used. + translation_strategy: UnderscoreEscapingWithSuffixes # Configure metric producers. producers: - # Configure metric producer to be opencensus. @@ -459,7 +462,7 @@ meter_provider: meter_version: 1.0.0 # Configure meter schema url selection criteria. # If omitted or null, all meter schema URLs match. - meter_schema_url: https://opentelemetry.io/schemas/1.30.0 + meter_schema_url: https://opentelemetry.io/schemas/1.32.0 # Configure view stream. stream: # Configure metric name of the resulting stream(s). @@ -557,18 +560,6 @@ propagator: # Built-in propagator identifiers include: tracecontext, baggage, b3, b3multi, jaeger, ottrace. Known third party identifiers include: xray. # If the resolved list of propagators (from .composite and .composite_list) is empty, a noop propagator is used. composite_list: "tracecontext,baggage,b3,b3multi,jaeger,ottrace,xray" -# Configure response propagators. -# If omitted, a noop response propagator is used. -response_propagator/development: - # Configure the experimental response propagators in the composite experimental response propagator. Entries from .composite_list are appended to the list here with duplicates filtered out. - # Built-in experimental response propagator keys include: N/A. Known third party keys include: servertiming, traceresponse. - # If the resolved list of experimental response propagators (from .composite and .composite_list) is empty, a noop response propagator is used. - composite: - # Configure the experimental response propagators in the composite experimental response propagator. Entries are appended to .composite with duplicates filtered out. - # The value is a comma separated list of experimental response propagator identifiers matching the format of OTEL_EXPERIMENTAL_RESPONSE_PROPAGATORS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details. - # Built-in experimental propagator identifiers include: N/A. Known third party identifiers include: servertiming, traceresponse. - # If the resolved list of experimental propagators (from .composite and .composite_list) is empty, a noop response propagator is used. - composite_list: "servertiming,traceresponse" # Configure tracer provider. # If omitted, a noop tracer provider is used. tracer_provider: @@ -851,18 +842,14 @@ resource: # Resource detector names are dependent on the SDK language ecosystem. Please consult documentation for each respective language. # If omitted or null, no resource detectors are enabled. detectors: - - # Enable the container resource detector. - # Note, the key "container" is an example and detector names may vary by SDK language ecosystem. + - # Enable the container resource detector, which populates container.* attributes. container: - - # Enable the host resource detector. - # Note, the key "host" is an example and detector names may vary by SDK language ecosystem. + - # Enable the host resource detector, which populates host.* and os.* attributes. host: - - # Enable the os resource detector. - # Note, the key "os" is an example and detector names may vary by SDK language ecosystem. - os: - - # Enable the process resource detector. - # Note, the key "process" is an example and detector names may vary by SDK language ecosystem. + - # Enable the process resource detector, which populates process.* attributes. process: + - # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id. + service: # Configure resource schema URL. # If omitted or null, no schema URL is used. schema_url: https://opentelemetry.io/schemas/1.32.0 @@ -960,4 +947,4 @@ instrumentation/development: swift: # Configure the instrumentation corresponding to key "example". example: - property: "value" + property: "value" \ No newline at end of file diff --git a/tests/Integration/Config/configurations/minimal.yaml b/tests/Integration/Config/configurations/minimal.yaml index 457d038dc..935088722 100644 --- a/tests/Integration/Config/configurations/minimal.yaml +++ b/tests/Integration/Config/configurations/minimal.yaml @@ -1,2 +1,2 @@ # this is the minimal acceptable configuration file -file_format: '0.4' +file_format: '1.0-rc.2' diff --git a/tests/Integration/Config/configurations/propagators-duplicate.yaml b/tests/Integration/Config/configurations/propagators-duplicate.yaml index ee2d10c05..f0bae1688 100644 --- a/tests/Integration/Config/configurations/propagators-duplicate.yaml +++ b/tests/Integration/Config/configurations/propagators-duplicate.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' propagator: composite_list: "tracecontext,tracecontext" diff --git a/tests/Integration/Config/configurations/resource-default.yaml b/tests/Integration/Config/configurations/resource-default.yaml index 66c59af5c..00bf2269f 100644 --- a/tests/Integration/Config/configurations/resource-default.yaml +++ b/tests/Integration/Config/configurations/resource-default.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' resource: schema_url: https://opentelemetry.io/schemas/1.32.0 diff --git a/tests/Integration/Config/configurations/resource-include-exclude.yaml b/tests/Integration/Config/configurations/resource-include-exclude.yaml index 1d8cde64c..57f8361d0 100644 --- a/tests/Integration/Config/configurations/resource-include-exclude.yaml +++ b/tests/Integration/Config/configurations/resource-include-exclude.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' resource: schema_url: https://opentelemetry.io/schemas/1.32.0 diff --git a/tests/Integration/Config/configurations/resource.yaml b/tests/Integration/Config/configurations/resource.yaml index 564906ba3..7aa0bcae6 100644 --- a/tests/Integration/Config/configurations/resource.yaml +++ b/tests/Integration/Config/configurations/resource.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' resource: schema_url: https://opentelemetry.io/schemas/1.32.0 diff --git a/tests/Unit/Contrib/Otlp/LogsConverterTest.php b/tests/Unit/Contrib/Otlp/LogsConverterTest.php index 4ed7da8a1..0253b7958 100644 --- a/tests/Unit/Contrib/Otlp/LogsConverterTest.php +++ b/tests/Unit/Contrib/Otlp/LogsConverterTest.php @@ -36,7 +36,7 @@ public function test_convert(): void $this->record->method('getBody')->willReturn('body'); $request = $this->converter->convert([$this->record]); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ $row = $request->getResourceLogs()[0]->getScopeLogs()[0]->getLogRecords()[0]; $this->assertSame('body', $row->getBody()->getStringValue()); } @@ -49,7 +49,7 @@ public function test_convert_with_context(): void $span->method('getContext')->willReturn($spanContext); $this->record->method('getSpanContext')->willReturn($spanContext); $request = $this->converter->convert([$this->record]); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ $row = $request->getResourceLogs()[0]->getScopeLogs()[0]->getLogRecords()[0]; $this->assertSame(self::TRACE_ID_BASE16, bin2hex((string) $row->getTraceId())); $this->assertSame(self::SPAN_ID_BASE16, bin2hex((string) $row->getSpanId())); diff --git a/tests/Unit/Contrib/Otlp/SpanConverterTest.php b/tests/Unit/Contrib/Otlp/SpanConverterTest.php index 3ee0c248f..205d84a39 100644 --- a/tests/Unit/Contrib/Otlp/SpanConverterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanConverterTest.php @@ -33,7 +33,7 @@ class SpanConverterTest extends TestCase { /** - * @psalm-suppress InvalidArgument + * @psalm-suppress InvalidArgument,PossiblyNullReference */ public function test_convert_span_to_payload(): void { @@ -85,12 +85,13 @@ public function test_span_context_is_remote_flags(): void $convertSpanData = static function (SpanData $spanData): ProtoSpan { $converter = new SpanConverter(); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ return $converter->convert([$spanData])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0]; }; + /** @psalm-suppress InvalidNullableReturnType */ $getLink = static function (ProtoSpan $protoSpan, int $linkIndex): ProtoSpanLink { - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,NullableReturnStatement */ return $protoSpan->getLinks()[$linkIndex]; }; @@ -130,6 +131,7 @@ public function test_attribute_are_coerced_correctly($actual, $expected): void $converter = new SpanConverter(); /** @psalm-suppress InvalidArgument */ $converted = $converter->convert([$span])->getResourceSpans()[0]; + /** @psalm-suppress PossiblyNullReference */ $attributes = $converted->getScopeSpans()[0]->getSpans()[0]->getAttributes(); // Check that we can convert all attributes to tags @@ -308,7 +310,7 @@ public function test_resources_from_multiple_spans_are_not_duplicated(): void $resource->method('getAttributes')->willReturn($attributes); $converter = new SpanConverter(); $result = $converter->convert([$span, $span, $span])->getResourceSpans(); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ $this->assertCount(2, $result[0]->getResource()->getAttributes()); } @@ -339,7 +341,7 @@ public function test_otlp_no_spans(): void public function test_span_kind($kind, $expected): void { $span = (new SpanData())->setKind($kind); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ $row = (new SpanConverter())->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0]; $this->assertSame($expected, $row->getKind()); } @@ -359,7 +361,7 @@ public static function spanKindProvider(): array public function test_span_with_error_status(): void { $span = (new SpanData())->setStatus(StatusData::error()); - /** @psalm-suppress InvalidArgument */ + /** @psalm-suppress InvalidArgument,PossiblyNullReference */ $row = (new SpanConverter())->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0]; $this->assertSame(V1\Status\StatusCode::STATUS_CODE_ERROR, $row->getStatus()->getCode()); } diff --git a/tests/Unit/SDK/fixtures/otel-sdk.yaml b/tests/Unit/SDK/fixtures/otel-sdk.yaml index 37024fef0..181c562d0 100644 --- a/tests/Unit/SDK/fixtures/otel-sdk.yaml +++ b/tests/Unit/SDK/fixtures/otel-sdk.yaml @@ -1,4 +1,4 @@ -file_format: '0.4' +file_format: '1.0-rc.2' tracer_provider: processors: