registerBatchCallback method

APIBatchCallbackRegistration registerBatchCallback(
  1. BatchObservableCallback callback,
  2. Set<APIObservableInstrument> instruments
)

Registers a batch callback for multiple observable instruments.

Implementation

APIBatchCallbackRegistration registerBatchCallback(
  BatchObservableCallback callback,
  Set<APIObservableInstrument> instruments,
) {
  // metrics/api.md: a multiple-instrument callback MUST be associated
  // with instruments from the same Meter. The type already rules out a
  // synchronous instrument; a foreign meter is reported and the callback
  // is not registered. error-handling.md: never throw at the user.
  for (final instrument in instruments) {
    if (!identical(instrument.meter, this)) {
      OTelErrorHandling.report(ArgumentError(
        'registerBatchCallback: instrument "${instrument.name}" belongs '
        'to a different Meter; the callback was not registered.',
      ));
      return _NoopBatchCallbackRegistration();
    }
  }
  // No-op: return a stateless registration
  return _NoopBatchCallbackRegistration();
}