function serializeMetricBuckets(metricBucketItems) {
  let out = '';
  for (const item of metricBucketItems) {
    const tagEntries = Object.entries(item.tags);
    const maybeTags = tagEntries.length > 0 ? `|#${tagEntries.map(([key, value]) => `${key}:${value}`).join(',')}` : '';
    out += `${item.name}@${item.unit}:${item.metric}|${item.metricType}${maybeTags}|T${item.timestamp}\n`;
  }
  return out;
}
Serialize metrics buckets into a string based on statsd format.

Example of format:
metric.name@second:1:1.2|d|#a:value,b:anothervalue|T12345677
Segments:
name: metric.name
unit: second
value: [1, 1.2]
type of metric: d (distribution)
tags: { a: value, b: anothervalue }
timestamp: 12345677