toJson method

Map<String, dynamic> toJson()

Implementation

Map<String, dynamic> toJson() {
  final json = _context.toJson();
  json['start_timestamp'] =
      formatDateAsIso8601WithMillisPrecision(_startTimestamp);
  if (_endTimestamp != null) {
    json['timestamp'] =
        formatDateAsIso8601WithMillisPrecision(_endTimestamp!);
  }
  if (_data.isNotEmpty) {
    json['data'] = _data;
  }
  if (status != null) {
    json['status'] = status.toString();
  }
  if (_tags.isNotEmpty) {
    json['tags'] = _tags;
  }
  if (_origin != null) {
    json['origin'] = _origin;
  }

  final metricSummariesMap = _metricSummaries?.entries ?? Iterable.empty();
  if (metricSummariesMap.isNotEmpty) {
    final map = <String, dynamic>{};
    for (final entry in metricSummariesMap) {
      final summary = entry.value.map((e) => e.toJson());
      map[entry.key] = summary.toList(growable: false);
    }
    json['_metrics_summary'] = map;
  }
  return json;
}