recordMetric method

  1. @override
Future<void> recordMetric({
  1. required String name,
  2. required String metricType,
  3. required double value,
  4. String unit = 'count',
  5. Map<String, String> attributes = const {},
})
override

Records a counter metric.

The metricType specifies the metric kind (e.g., "counter"). Returns Future<void> to allow for async repository operations.

Implementation

@override
Future<void> recordMetric({
  required String name,
  required String metricType,
  required double value,
  String unit = 'count',
  Map<String, String> attributes = const {},
}) async {
  if (name.isEmpty) {
    throw ArgumentError('Metric name cannot be empty');
  }
  if (value.isNaN || value.isInfinite) {
    throw ArgumentError('Metric value must be a valid number');
  }
  if (unit.isEmpty) {
    throw ArgumentError('Metric unit cannot be empty');
  }

  await _repository.exportMetric(
    Metric(
      name: name,
      value: value,
      unit: unit,
      timestamp: DateTime.now().toUtc(),
      attributes: attributes,
    ),
  );
}