Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ObservableCallbackInterface.php

interface ObservableCallbackInterface

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(); } } ```

Hierarchy

  • interface \OpenTelemetry\API\Metrics\ObservableCallbackInterface

Expanded class hierarchy of ObservableCallbackInterface

All classes that implement ObservableCallbackInterface

See also

ObservableCounterInterface::observe()

ObservableGaugeInterface::observe()

ObservableUpDownCounterInterface::observe()

9 files declare their use of ObservableCallbackInterface
AsynchronousInstruments.php in vendor/open-telemetry/sdk/Metrics/AsynchronousInstruments.php
Meter.php in vendor/open-telemetry/sdk/Metrics/Meter.php
NoopMeter.php in vendor/open-telemetry/api/Metrics/Noop/NoopMeter.php
NoopObservableCallback.php in vendor/open-telemetry/api/Metrics/Noop/NoopObservableCallback.php
NoopObservableCounter.php in vendor/open-telemetry/api/Metrics/Noop/NoopObservableCounter.php

... See full list

File

vendor/open-telemetry/api/Metrics/ObservableCallbackInterface.php, line 49

Namespace

OpenTelemetry\API\Metrics
View source
interface ObservableCallbackInterface {
    
    /**
     * Detaches the associated callback from the instrument.
     */
    public function detach() : void;

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ObservableCallbackInterface::detach public function Detaches the associated callback from the instrument. 2

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal