Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions src/Config/SDK/ComponentProvider/Detector/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Detector;

use OpenTelemetry\API\Configuration\Config\ComponentProvider;
use OpenTelemetry\API\Configuration\Config\ComponentProviderRegistry;
use OpenTelemetry\API\Configuration\Context;
use OpenTelemetry\SDK\Resource\Detectors\Service as ServiceDetector;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<ResourceDetectorInterface>
*/
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');
}
}
8 changes: 4 additions & 4 deletions src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/Config/SDK/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Trace/TracerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $buil
->end()
->end()
->end()
->scalarNode('translation_strategy')->defaultValue('UnderscoreEscapingWithSuffixes')->end()
->end()
;

Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Config/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
);

$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 }
Expand All @@ -240,7 +240,7 @@
);

$sdk = $factory->process([Yaml::parse(/** @lang yaml */<<<'YAML'
file_format: "0.4"
file_format: "1.0-rc.2"
resource:
detection/development:
detectors:
Expand All @@ -252,7 +252,7 @@
}

#[Depends('test_resource_attributes_take_precedence_over_default_attributes')]
#[Depends('test_resource_detectors_take_precedence_over_default_attributes')]

Check failure on line 255 in tests/Integration/Config/ConfigurationTest.php

View workflow job for this annotation

GitHub Actions / php (8.5, true, --ignore-platform-reqs)

Attribute class PHPUnit\Framework\Attributes\Depends is not repeatable but is already present above the method.
public function test_resource_attributes_take_precedence_over_resource_detectors(): void
{
$factory = new ConfigurationFactory(
Expand All @@ -262,7 +262,7 @@
);

$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 }
Expand Down Expand Up @@ -302,7 +302,7 @@
);

$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 }
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Config/configurations/anchors.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

propagators:
composite: [ tracecontext, baggage ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

response_propagator/development:
composite_list: "servertiming,servertiming"
Expand Down
47 changes: 17 additions & 30 deletions tests/Integration/Config/configurations/kitchen-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -960,4 +947,4 @@ instrumentation/development:
swift:
# Configure the instrumentation corresponding to key "example".
example:
property: "value"
property: "value"
2 changes: 1 addition & 1 deletion tests/Integration/Config/configurations/minimal.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# this is the minimal acceptable configuration file
file_format: '0.4'
file_format: '1.0-rc.2'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

propagator:
composite_list: "tracecontext,tracecontext"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

resource:
schema_url: https://opentelemetry.io/schemas/1.32.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

resource:
schema_url: https://opentelemetry.io/schemas/1.32.0
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Config/configurations/resource.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

resource:
schema_url: https://opentelemetry.io/schemas/1.32.0
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Contrib/Otlp/LogsConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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()));
Expand Down
14 changes: 8 additions & 6 deletions tests/Unit/Contrib/Otlp/SpanConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class SpanConverterTest extends TestCase
{
/**
* @psalm-suppress InvalidArgument
* @psalm-suppress InvalidArgument,PossiblyNullReference
*/
public function test_convert_span_to_payload(): void
{
Expand Down Expand Up @@ -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];
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SDK/fixtures/otel-sdk.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file_format: '0.4'
file_format: '1.0-rc.2'

tracer_provider:
processors:
Expand Down
Loading