diff --git a/src/API/Instrumentation/SpanAttribute.php b/src/API/Instrumentation/SpanAttribute.php index b2dcd1ef8..1a9fa1d13 100644 --- a/src/API/Instrumentation/SpanAttribute.php +++ b/src/API/Instrumentation/SpanAttribute.php @@ -11,7 +11,7 @@ * attribute, adding this attribute to an argument will * add the argument as a span attribute. */ -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)] final class SpanAttribute { /** diff --git a/tests/Unit/API/Instrumentation/SpanAttributeTest.php b/tests/Unit/API/Instrumentation/SpanAttributeTest.php index d6437aa82..cc905ecde 100644 --- a/tests/Unit/API/Instrumentation/SpanAttributeTest.php +++ b/tests/Unit/API/Instrumentation/SpanAttributeTest.php @@ -5,7 +5,9 @@ namespace OpenTelemetry\Tests\Unit\API\Instrumentation; use OpenTelemetry\API\Instrumentation\SpanAttribute; +use OpenTelemetry\API\Instrumentation\WithSpan; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; #[CoversClass(SpanAttribute::class)] @@ -16,4 +18,17 @@ public function test_with_span(): void $attr = new SpanAttribute('foo'); $this->assertSame('foo', $attr->name); } + + #[DoesNotPerformAssertions] + public function test_attribute_targets_parameter(): void + { + new class() { + #[WithSpan] + public function foo( + #[SpanAttribute] string $a, + #[SpanAttribute('a_better_attribute_name')] string $b, + ): void { + } + }; + } }