-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timing metric and beforeMetric callback (part 3) (#1954)
* added SentryOptions.beforeMetricCallback * added beforeMetricCallback logic in metrics_aggregator.dart * added timing metric api with span auto start * timing api uses span duration as value for the emitted metric if possible * Feat/metrics span summary p4 (#1958) * added local_metrics_aggregator.dart to spans * metrics_aggregator.dart now adds to current span's localMetricsAggregator * added metric_summary.dart * added metricSummary to spans and transaction JSONs
- Loading branch information
1 parent
78c7087
commit d93ace2
Showing
22 changed files
with
713 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'dart:core'; | ||
import 'package:meta/meta.dart'; | ||
import '../protocol/metric_summary.dart'; | ||
import 'metric.dart'; | ||
|
||
@internal | ||
class LocalMetricsAggregator { | ||
// format: <export key, <metric key, gauge>> | ||
final Map<String, Map<String, GaugeMetric>> _buckets = {}; | ||
|
||
void add(final Metric metric, final num value) { | ||
final bucket = | ||
_buckets.putIfAbsent(metric.getSpanAggregationKey(), () => {}); | ||
|
||
bucket.update(metric.getCompositeKey(), (m) => m..add(value), | ||
ifAbsent: () => Metric.fromType( | ||
type: MetricType.gauge, | ||
key: metric.key, | ||
value: value, | ||
unit: metric.unit, | ||
tags: metric.tags) as GaugeMetric); | ||
} | ||
|
||
Map<String, List<MetricSummary>> getSummaries() { | ||
final Map<String, List<MetricSummary>> summaries = {}; | ||
for (final entry in _buckets.entries) { | ||
final String exportKey = entry.key; | ||
|
||
final metricSummaries = entry.value.values | ||
.map((gauge) => MetricSummary.fromGauge(gauge)) | ||
.toList(); | ||
|
||
summaries[exportKey] = metricSummaries; | ||
} | ||
return summaries; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import '../metrics/metric.dart'; | ||
|
||
class MetricSummary { | ||
final num min; | ||
final num max; | ||
final num sum; | ||
final int count; | ||
final Map<String, String>? tags; | ||
|
||
MetricSummary.fromGauge(GaugeMetric gauge) | ||
: min = gauge.minimum, | ||
max = gauge.maximum, | ||
sum = gauge.sum, | ||
count = gauge.count, | ||
tags = gauge.tags; | ||
|
||
const MetricSummary( | ||
{required this.min, | ||
required this.max, | ||
required this.sum, | ||
required this.count, | ||
required this.tags}); | ||
|
||
/// Deserializes a [MetricSummary] from JSON [Map]. | ||
factory MetricSummary.fromJson(Map<String, dynamic> data) => MetricSummary( | ||
min: data['min'], | ||
max: data['max'], | ||
count: data['count'], | ||
sum: data['sum'], | ||
tags: data['tags']?.cast<String, String>(), | ||
); | ||
|
||
/// Produces a [Map] that can be serialized to JSON. | ||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'min': min, | ||
'max': max, | ||
'count': count, | ||
'sum': sum, | ||
if (tags?.isNotEmpty ?? false) 'tags': tags, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.