LCOV - code coverage report
Current view: top level - lib/src/metrics/storage - metric_storage.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 3 3
Test Date: 2026-08-27 23:42:02 Functions: - 0 0

            Line data    Source code
       1              : // Copyright The OpenTelemetry Authors
       2              : // SPDX-License-Identifier: Apache-2.0
       3              : 
       4              : import 'package:dartastic_opentelemetry_api/dartastic_opentelemetry_api.dart';
       5              : 
       6              : import '../data/metric_point.dart';
       7              : import '../exemplar_filter.dart';
       8              : import '../exemplar_reservoir.dart';
       9              : 
      10              : /// Base storage interface for all metric types.
      11              : /// This replaces the old PointStorage with proper input/output type separation.
      12              : abstract class MetricStorage {
      13              :   /// Resets the storage (for delta temporality).
      14              :   void reset();
      15              : }
      16              : 
      17              : /// Storage for metrics that have simple numeric input and output (sum, gauge).
      18              : abstract class NumericStorage<T extends num> extends MetricStorage {
      19              :   /// Records a measurement with the given attributes and context.
      20              :   void record(T value,
      21              :       [Attributes? attributes, Context? context, DateTime? timestamp]);
      22              : 
      23              :   /// Gets the current value for the given attributes.
      24              :   /// If no attributes are provided, returns a summary value depending on the instrument type.
      25              :   T getValue([Attributes? attributes]);
      26              : 
      27              :   /// Collects the current set of metric points.
      28              :   List<MetricPoint<T>> collectPoints();
      29              : }
      30              : 
      31              : /// Storage for histogram metrics that have numeric input but HistogramValue output.
      32              : abstract class HistogramStorageBase<T extends num> extends MetricStorage {
      33              :   /// Records a measurement with the given attributes and context.
      34              :   void record(T value,
      35              :       [Attributes? attributes, Context? context, DateTime? timestamp]);
      36              : 
      37              :   /// Gets the current histogram value for the given attributes.
      38              :   /// If no attributes are provided, returns a combined HistogramValue across all attribute sets.
      39              :   HistogramValue getValue([Attributes? attributes]);
      40              : 
      41              :   /// Collects the current set of metric points containing HistogramValue objects.
      42              :   List<MetricPoint<HistogramValue>> collectPoints();
      43              : }
      44              : 
      45              : /// Mixin for managing exemplar sampling policy across storage implementations.
      46              : mixin ExemplarSampling<T extends num> {
      47              :   ExemplarFilter get exemplarFilter;
      48              : 
      49           41 :   void maybeOffer(ExemplarReservoir reservoir, T value, Attributes attributes,
      50              :       Context context, DateTime timestamp,
      51              :       [int? bucketIndex]) {
      52           82 :     if (exemplarFilter.shouldSample(value, attributes, context)) {
      53            2 :       reservoir.offerMeasurement(
      54              :           value, attributes, context, timestamp, bucketIndex);
      55              :     }
      56              :   }
      57              : }
        

Generated by: LCOV version 2.0-1