Skip to content

Commit 64e1732

Browse files
committed
removed useless types
renamed a test
1 parent 2c4e01f commit 64e1732

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

dart/lib/src/metrics/metric.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ abstract class Metric {
4343
/// [bucketKey] is the key of the metric bucket that will be sent to Sentry,
4444
/// and it's appended at the end of the encoded metric.
4545
String encodeToStatsd(int bucketKey) {
46-
final StringBuffer buffer = StringBuffer();
46+
final buffer = StringBuffer();
4747
buffer.write(_normalizeKey(key));
4848
buffer.write("@");
4949

50-
final String sanitizeUnitName = _sanitizeUnit(unit.name);
50+
final sanitizeUnitName = _sanitizeUnit(unit.name);
5151
buffer.write(sanitizeUnitName);
5252

53-
for (Object value in _serializeValue()) {
53+
for (final value in _serializeValue()) {
5454
buffer.write(":");
5555
buffer.write(value.toString());
5656
}
@@ -60,7 +60,7 @@ abstract class Metric {
6060

6161
if (tags.isNotEmpty) {
6262
buffer.write("|#");
63-
String serializedTags = tags.entries
63+
final serializedTags = tags.entries
6464
.map((tag) =>
6565
'${_normalizeKey(tag.key)}:${_normalizeTagValue(tag.value)}')
6666
.join(',');
@@ -102,7 +102,7 @@ abstract class Metric {
102102

103103
@internal
104104

105-
/// Metric [MetricType.counter] that track a value that can only be incremented.
105+
/// Metric [MetricType.counter] that tracks a value that can only be incremented.
106106
class CounterMetric extends Metric {
107107
double value;
108108

dart/lib/src/metrics/metrics_aggregator.dart

+8-9
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ class MetricsAggregator {
5050
return;
5151
}
5252

53-
final int bucketKey = _getBucketKey(_options.clock());
54-
final Map<String, Metric> bucket =
55-
_buckets.putIfAbsent(bucketKey, () => {});
56-
final Metric metric =
53+
final bucketKey = _getBucketKey(_options.clock());
54+
final bucket = _buckets.putIfAbsent(bucketKey, () => {});
55+
final metric =
5756
CounterMetric(value: value, key: key, unit: unit, tags: tags);
5857

5958
// Update the existing metric in the bucket.
@@ -90,7 +89,7 @@ class MetricsAggregator {
9089

9190
/// Flush and sends metrics.
9291
Future<void> _flush() async {
93-
final Iterable<int> flushableBucketKeys = _getFlushableBucketKeys();
92+
final flushableBucketKeys = _getFlushableBucketKeys();
9493
if (flushableBucketKeys.isEmpty) {
9594
_options.logger(SentryLevel.debug, 'Metrics: nothing to flush');
9695
return;
@@ -100,7 +99,7 @@ class MetricsAggregator {
10099
int numMetrics = 0;
101100

102101
for (int flushableBucketKey in flushableBucketKeys) {
103-
final Map<String, Metric>? bucket = _buckets.remove(flushableBucketKey);
102+
final bucket = _buckets.remove(flushableBucketKey);
104103
if (bucket != null) {
105104
numMetrics += bucket.length;
106105
bucketsToFlush[flushableBucketKey] = bucket.values;
@@ -120,11 +119,11 @@ class MetricsAggregator {
120119
List<int> _getFlushableBucketKeys() {
121120
// Flushable buckets are all buckets with timestamp lower than the current
122121
// one (so now - rollupInSeconds), minus a random duration (flushShiftMs).
123-
final DateTime maxTimestampToFlush = _options.clock().subtract(Duration(
122+
final maxTimestampToFlush = _options.clock().subtract(Duration(
124123
seconds: _rollupInSeconds,
125124
milliseconds: _flushShiftMs,
126125
));
127-
final int maxKeyToFlush = _getBucketKey(maxTimestampToFlush);
126+
final maxKeyToFlush = _getBucketKey(maxTimestampToFlush);
128127

129128
// takeWhile works because we use a SplayTreeMap and keys are ordered.
130129
// toList() is needed because takeWhile is lazy and we want to remove items
@@ -134,7 +133,7 @@ class MetricsAggregator {
134133

135134
/// The timestamp of the bucket, rounded down to the nearest RollupInSeconds.
136135
int _getBucketKey(DateTime timestamp) {
137-
final int seconds = timestamp.millisecondsSinceEpoch ~/ 1000;
136+
final seconds = timestamp.millisecondsSinceEpoch ~/ 1000;
138137
return (seconds ~/ _rollupInSeconds) * _rollupInSeconds;
139138
}
140139

dart/lib/src/sentry_envelope_item.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class SentryEnvelopeItem {
8686
/// Creates a [SentryEnvelopeItem] which holds several [Metric] data.
8787
factory SentryEnvelopeItem.fromMetrics(Map<int, Iterable<Metric>> buckets) {
8888
final cachedItem = _CachedItem(() async {
89-
final StringBuffer statsd = StringBuffer();
89+
final statsd = StringBuffer();
9090
// Encode all metrics of a bucket in statsd format, using the bucket key,
9191
// which is the timestamp of the bucket.
92-
for (MapEntry<int, Iterable<Metric>> bucket in buckets.entries) {
93-
final Iterable<String> encodedMetrics =
92+
for (final bucket in buckets.entries) {
93+
final encodedMetrics =
9494
bucket.value.map((metric) => metric.encodeToStatsd(bucket.key));
9595
statsd.write(encodedMetrics.join('\n'));
9696
}

dart/test/hub_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void main() {
718718
'Metrics are disabled and this \'captureMetrics\' call is a no-op.');
719719
});
720720

721-
test('should not capture metrics if enableMetric is false', () async {
721+
test('should not capture metrics if hub is closed', () async {
722722
final hub = fixture.getSut(debug: true);
723723
await hub.close();
724724

0 commit comments

Comments
 (0)