registerInstrument method

void registerInstrument(
  1. String instrumentName,
  2. SDKInstrument instrument
)

Registers an instrument with this provider.

This allows the provider to track all active instruments for metrics collection.

@param instrumentName The name of the instrument @param instrument The instrument to register

Implementation

void registerInstrument(String instrumentName, SDKInstrument instrument) {
  final meterKey = instrument.meter.name;
  if (!_instruments.containsKey(meterKey)) {
    _instruments[meterKey] = {};
  }

  _instruments[meterKey]!.add(instrument);

  if (OTelLog.isLogMetrics()) {
    OTelLog.logMetric(
      'MeterProvider: Registered instrument "${instrument.name}" for meter "${instrument.meter.name}"',
    );
  }
}