recordMetric method
Future<void>
recordMetric({
- required String name,
- required String metricType,
- required double value,
- String unit = 'count',
- 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,
),
);
}