Skip to content

Commit

Permalink
Added \Attribute::TARGET_PARAMETER to \OpenTelemetry\API\Instrumentat…
Browse files Browse the repository at this point in the history
…ion\SpanAttribute (#1433)

Fixes #1429.
  • Loading branch information
ChrisLightfootWild authored Nov 16, 2024
1 parent 7b5cbb5 commit 8857b0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/API/Instrumentation/SpanAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/API/Instrumentation/SpanAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
}
};
}
}

0 comments on commit 8857b0c

Please sign in to comment.