toJson method

  1. @override
Map<String, dynamic> toJson()
override

Serializes this event to JSON.

Implementation

@override
Map<String, dynamic> toJson() {
  final json = super.toJson();

  if (spans.isNotEmpty) {
    json['spans'] = spans.map((e) => e.toJson()).toList(growable: false);
  }
  json['start_timestamp'] =
      formatDateAsIso8601WithMillisPrecision(startTimestamp);

  if (measurements.isNotEmpty) {
    final map = <String, dynamic>{};
    for (final item in measurements.entries) {
      map[item.key] = item.value.toJson();
    }
    json['measurements'] = map;
  }

  final transactionInfo = this.transactionInfo;
  if (transactionInfo != null) {
    json['transaction_info'] = transactionInfo.toJson();
  }

  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;
}