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; }