-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multi-instrument callbacks (#1202)
* Add support for multi-instrument callbacks https://opentelemetry.io/docs/specs/otel/metrics/api/#multiple-instrument-callbacks * Fix undefined offset on detach of batch callback with repeated instrument * Unify BatchObservableCallback and ObservableCallback * Add missing typehint * Do not bump API dependency Not required, SDK will continue to work with lower API versions, only `::batchObserve()` won't be usable.
- Loading branch information
Showing
30 changed files
with
614 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\API\Metrics; | ||
|
||
/** | ||
* Marker interface for asynchronous instruments. | ||
*/ | ||
interface AsynchronousInstrument | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\API\Metrics; | ||
|
||
/** | ||
* Marker interface for synchronous instruments. | ||
*/ | ||
interface SynchronousInstrument | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Metrics; | ||
|
||
use ArrayAccess; | ||
use OpenTelemetry\API\Metrics\ObservableCallbackInterface; | ||
use function OpenTelemetry\SDK\Common\Util\closure; | ||
use function OpenTelemetry\SDK\Common\Util\weaken; | ||
use OpenTelemetry\SDK\Metrics\MetricRegistry\MetricWriterInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AsynchronousInstruments | ||
{ | ||
/** | ||
* @param ArrayAccess<object, ObservableCallbackDestructor> $destructors | ||
* @param non-empty-list<Instrument> $instruments | ||
*/ | ||
public static function observe( | ||
MetricWriterInterface $writer, | ||
ArrayAccess $destructors, | ||
callable $callback, | ||
array $instruments, | ||
ReferenceCounterInterface $referenceCounter | ||
): ObservableCallbackInterface { | ||
$target = null; | ||
$callback = weaken(closure($callback), $target); | ||
|
||
$callbackId = $writer->registerCallback($callback, ...$instruments); | ||
$referenceCounter->acquire(); | ||
|
||
$destructor = null; | ||
if ($target) { | ||
$destructor = $destructors[$target] ??= new ObservableCallbackDestructor($destructors, $writer); | ||
$destructor->callbackIds[$callbackId] = $referenceCounter; | ||
} | ||
|
||
return new ObservableCallback($writer, $referenceCounter, $callbackId, $destructor, $target); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Metrics; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface InstrumentHandle | ||
{ | ||
public function getHandle(): Instrument; | ||
} |
Oops, something went wrong.