diff options
author | Andrew Dolgov <[email protected]> | 2023-10-20 17:12:29 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-10-20 21:13:39 +0300 |
commit | cdd7ad020e165fe680703b6d3319b908b682fb7a (patch) | |
tree | b51eb09b7b4587e8fbc5624ac8d88d28cfcd0b04 /vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php | |
parent | 45a9ff0c88cbd33892ff16ab837e9059937d656e (diff) |
jaeger-client -> opentelemetry
Diffstat (limited to 'vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php')
-rw-r--r-- | vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php b/vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php new file mode 100644 index 000000000..a20e59666 --- /dev/null +++ b/vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\API\Metrics; + +/** + * An observed callback. + * + * Callbacks that are bound to an object are automatically detached when the + * `ObservableCallbackInterface` and the bound object are out of scope. + * This means that the `ObservableCallbackInterface` can be ignored if the + * observed callback should be bound to the lifetime of the object. + * ```php + * class Example { + * function __construct(MeterProviderInterface $meterProvider) { + * $meterProvider->getMeter('example') + * ->createObservableGauge('random') + * ->observe(fn(ObserverInterface $observer) + * => $observer->observe(rand(0, 10))); + * } + * } + * ``` + * Keeping a reference to the `ObservableCallbackInterface` within the bound + * object to gain a more fine-grained control over the life-time of the callback + * does not prevent garbage collection (but might require cycle collection). + * + * Unbound (static) callbacks must be detached manually using + * {@link ObservableCallbackInterface::detach()}. + * ```php + * class Example { + * private ObservableCallbackInterface $gauge; + * function __construct(MeterProviderInterface $meterProvider) { + * $this->gauge = $meterProvider->getMeter('example') + * ->createObservableGauge('random') + * ->observe(static fn(ObserverInterface $observer) + * => $observer->observe(rand(0, 10))); + * } + * function __destruct() { + * $this->gauge->detach(); + * } + * } + * ``` + * + * @see ObservableCounterInterface::observe() + * @see ObservableGaugeInterface::observe() + * @see ObservableUpDownCounterInterface::observe() + */ +interface ObservableCallbackInterface +{ + + /** + * Detaches the associated callback from the instrument. + */ + public function detach(): void; +} |