Skip to content

Commit 78bf761

Browse files
authored
Add instrument advisory parameter (#1186)
* Add instrument advisory parameter * Undo bucket boundaries change to preserve BC "SDKs SHOULD use the default value when boundaries are not explicitly provided, unless they have good reasons to use something different (e.g. for backward compatibility reasons in a stable SDK release)." * Add note that passing callback instead of advisory is deprecated
1 parent 08ff4d6 commit 78bf761

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Metrics/MeterInterface.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ interface MeterInterface
1313
* @param string $name name of the instrument
1414
* @param string|null $unit unit of measure
1515
* @param string|null $description description of the instrument
16+
* @param array $advisory an optional set of recommendations
1617
* @return CounterInterface created instrument
1718
*
1819
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#counter-creation
1920
*/
2021
public function createCounter(
2122
string $name,
2223
?string $unit = null,
23-
?string $description = null
24+
?string $description = null,
25+
array $advisory = []
2426
): CounterInterface;
2527

2628
/**
@@ -29,6 +31,8 @@ public function createCounter(
2931
* @param string $name name of the instrument
3032
* @param string|null $unit unit of measure
3133
* @param string|null $description description of the instrument
34+
* @param array|callable $advisory an optional set of recommendations, or
35+
* deprecated: the first callback to report measurements
3236
* @param callable ...$callbacks responsible for reporting measurements
3337
* @return ObservableCounterInterface created instrument
3438
*
@@ -38,6 +42,7 @@ public function createObservableCounter(
3842
string $name,
3943
?string $unit = null,
4044
?string $description = null,
45+
$advisory = [],
4146
callable ...$callbacks
4247
): ObservableCounterInterface;
4348

@@ -47,14 +52,17 @@ public function createObservableCounter(
4752
* @param string $name name of the instrument
4853
* @param string|null $unit unit of measure
4954
* @param string|null $description description of the instrument
55+
* @param array $advisory an optional set of recommendations, e.g.
56+
* <code>['ExplicitBucketBoundaries' => [0.25, 0.5, 1, 5]]</code>
5057
* @return HistogramInterface created instrument
5158
*
5259
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#histogram-creation
5360
*/
5461
public function createHistogram(
5562
string $name,
5663
?string $unit = null,
57-
?string $description = null
64+
?string $description = null,
65+
array $advisory = []
5866
): HistogramInterface;
5967

6068
/**
@@ -63,6 +71,8 @@ public function createHistogram(
6371
* @param string $name name of the instrument
6472
* @param string|null $unit unit of measure
6573
* @param string|null $description description of the instrument
74+
* @param array|callable $advisory an optional set of recommendations, or
75+
* deprecated: the first callback to report measurements
6676
* @param callable ...$callbacks responsible for reporting measurements
6777
* @return ObservableGaugeInterface created instrument
6878
*
@@ -72,6 +82,7 @@ public function createObservableGauge(
7282
string $name,
7383
?string $unit = null,
7484
?string $description = null,
85+
$advisory = [],
7586
callable ...$callbacks
7687
): ObservableGaugeInterface;
7788

@@ -81,14 +92,16 @@ public function createObservableGauge(
8192
* @param string $name name of the instrument
8293
* @param string|null $unit unit of measure
8394
* @param string|null $description description of the instrument
95+
* @param array $advisory an optional set of recommendations
8496
* @return UpDownCounterInterface created instrument
8597
*
8698
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#updowncounter-creation
8799
*/
88100
public function createUpDownCounter(
89101
string $name,
90102
?string $unit = null,
91-
?string $description = null
103+
?string $description = null,
104+
array $advisory = []
92105
): UpDownCounterInterface;
93106

94107
/**
@@ -97,6 +110,8 @@ public function createUpDownCounter(
97110
* @param string $name name of the instrument
98111
* @param string|null $unit unit of measure
99112
* @param string|null $description description of the instrument
113+
* @param array|callable $advisory an optional set of recommendations, or
114+
* deprecated: the first callback to report measurements
100115
* @param callable ...$callbacks responsible for reporting measurements
101116
* @return ObservableUpDownCounterInterface created instrument
102117
*
@@ -106,6 +121,7 @@ public function createObservableUpDownCounter(
106121
string $name,
107122
?string $unit = null,
108123
?string $description = null,
124+
$advisory = [],
109125
callable ...$callbacks
110126
): ObservableUpDownCounterInterface;
111127
}

Metrics/Noop/NoopMeter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@
1414

1515
final class NoopMeter implements MeterInterface
1616
{
17-
public function createCounter(string $name, ?string $unit = null, ?string $description = null): CounterInterface
17+
public function createCounter(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): CounterInterface
1818
{
1919
return new NoopCounter();
2020
}
2121

22-
public function createObservableCounter(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableCounterInterface
22+
public function createObservableCounter(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableCounterInterface
2323
{
2424
return new NoopObservableCounter();
2525
}
2626

27-
public function createHistogram(string $name, ?string $unit = null, ?string $description = null): HistogramInterface
27+
public function createHistogram(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): HistogramInterface
2828
{
2929
return new NoopHistogram();
3030
}
3131

32-
public function createObservableGauge(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableGaugeInterface
32+
public function createObservableGauge(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableGaugeInterface
3333
{
3434
return new NoopObservableGauge();
3535
}
3636

37-
public function createUpDownCounter(string $name, ?string $unit = null, ?string $description = null): UpDownCounterInterface
37+
public function createUpDownCounter(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): UpDownCounterInterface
3838
{
3939
return new NoopUpDownCounter();
4040
}
4141

42-
public function createObservableUpDownCounter(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableUpDownCounterInterface
42+
public function createObservableUpDownCounter(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableUpDownCounterInterface
4343
{
4444
return new NoopObservableUpDownCounter();
4545
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"symfony/polyfill-php81": "^1.26",
2525
"symfony/polyfill-php82": "^1.26"
2626
},
27+
"conflict": {
28+
"open-telemetry/sdk": "<=1.0.1"
29+
},
2730
"autoload": {
2831
"psr-4": {
2932
"OpenTelemetry\\API\\": "."

0 commit comments

Comments
 (0)