SentryEnvelopeItem.fromMetrics constructor
Creates a SentryEnvelopeItem which holds several Metric
data.
Implementation
factory SentryEnvelopeItem.fromMetrics(Map<int, Iterable<Metric>> buckets) {
final dataFactory = () {
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,
contentType: 'application/octet-stream',
);
return SentryEnvelopeItem(
header,
dataFactory,
originalObject: buckets,
);
}