SentryEnvelopeItem.fromMetrics constructor

SentryEnvelopeItem.fromMetrics(
  1. Map<int, Iterable<Metric>> buckets
)

Creates a SentryEnvelopeItem which holds several Metric data.

Implementation

factory SentryEnvelopeItem.fromMetrics(Map<int, Iterable<Metric>> buckets) {
  final cachedItem = _CachedItem(() async {
    final statsd = StringBuffer();
    // Encode all metrics of a bucket in statsd format, using the bucket key,
    //  which is the timestamp of the bucket.
    for (final bucket in buckets.entries) {
      final encodedMetrics =
          bucket.value.map((metric) => metric.encodeToStatsd(bucket.key));
      statsd.write(encodedMetrics.join('\n'));
    }
    return utf8.encode(statsd.toString());
  });

  final header = SentryEnvelopeItemHeader(
    SentryItemType.statsd,
    cachedItem.getDataLength,
    contentType: 'application/octet-stream',
  );
  return SentryEnvelopeItem(header, cachedItem.getData,
      originalObject: buckets);
}