Skip to content

Commit e67b49b

Browse files
authored
adding auto-instrumentation attribute to API (#1371)
adding WithSpan and SpanAttribute attributes to the API. These attributes are used by an upcoming feature in auto-instrumentation which allows users to add attributes to their code to enable auto-instrumentation.
1 parent 0588257 commit e67b49b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Instrumentation/SpanAttribute.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\API\Instrumentation;
6+
7+
use Attribute;
8+
9+
/**
10+
* For function and methods that have the {@link WithSpan}
11+
* attribute, adding this attribute to an argument will
12+
* add the argument as a span attribute.
13+
*/
14+
#[Attribute(Attribute::TARGET_PROPERTY)]
15+
final class SpanAttribute
16+
{
17+
/**
18+
* @param string|null $name Optional name to use for the attribute. Default: argument name.
19+
*/
20+
public function __construct(
21+
public readonly ?string $name = null,
22+
) {
23+
}
24+
}

Instrumentation/WithSpan.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\API\Instrumentation;
6+
7+
use Attribute;
8+
use OpenTelemetry\API\Trace\SpanKind; //@phan-suppress-current-line PhanUnreferencedUseNormal
9+
10+
/**
11+
* Functions and methods with this attribute will be auto-instrumented
12+
* by the OpenTelemetry extension.
13+
*/
14+
#[Attribute(Attribute::TARGET_FUNCTION|Attribute::TARGET_METHOD)]
15+
final class WithSpan
16+
{
17+
/**
18+
* @param string|null $span_name Optional span name. Default: function name or class::method
19+
* @param int|null $span_kind Optional {@link SpanKind}. Default: {@link SpanKind::KIND_INTERNAL}
20+
* @param array $attributes Optional attributes to be added to the span.
21+
*/
22+
public function __construct(
23+
public readonly ?string $span_name = null,
24+
public readonly ?int $span_kind = null,
25+
public readonly array $attributes = [],
26+
) {
27+
}
28+
}

0 commit comments

Comments
 (0)