Skip to content

Commit 97a76ac

Browse files
authored
Add missing measurements units (#1033)
1 parent 812d379 commit 97a76ac

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Tracer does not allow setting measurement if finished ([#1026](https://github.com/getsentry/sentry-dart/pull/1026))
8+
- Add missing measurements units ([#1033](https://github.com/getsentry/sentry-dart/pull/1033))
89

910
### Features
1011

dart/lib/src/sentry_measurement_unit.dart

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
/// The unit of measurement of a metric value.
2+
/// Units augment metric values by giving them a magnitude and semantics.
3+
/// Units and their precisions are uniquely represented by a string identifier.
4+
///
5+
/// This is a singe enum because Enhanced Enums in Dart is only available
6+
/// in newer versions.
17
enum SentryMeasurementUnit {
8+
/// Duration units
9+
210
/// Nanosecond (`"nanosecond"`), 10^-9 seconds.
311
nanoSecond,
412

@@ -23,13 +31,66 @@ enum SentryMeasurementUnit {
2331
/// Week (`"week"`), 604,800 seconds.
2432
week,
2533

34+
/// Information units
35+
36+
/// Bit (`"bit"`), corresponding to 1/8 of a byte.
37+
bit,
38+
39+
/// Byte (`"byte"`).
40+
byte,
41+
42+
/// Kilobyte (`"kilobyte"`), 10^3 bytes.
43+
kiloByte,
44+
45+
/// Kibibyte (`"kibibyte"`), 2^10 bytes.
46+
kibiByte,
47+
48+
/// Megabyte (`"megabyte"`), 10^6 bytes.
49+
megaByte,
50+
51+
/// Mebibyte (`"mebibyte"`), 2^20 bytes.
52+
mebiByte,
53+
54+
/// Gigabyte (`"gigabyte"`), 10^9 bytes.
55+
gigaByte,
56+
57+
/// Gibibyte (`"gibibyte"`), 2^30 bytes.
58+
gibiByte,
59+
60+
/// Terabyte (`"terabyte"`), 10^12 bytes.
61+
teraByte,
62+
63+
/// Tebibyte (`"tebibyte"`), 2^40 bytes.
64+
tebiByte,
65+
66+
/// Petabyte (`"petabyte"`), 10^15 bytes.
67+
petaByte,
68+
69+
/// Pebibyte (`"pebibyte"`), 2^50 bytes.
70+
pebiByte,
71+
72+
/// Exabyte (`"exabyte"`), 10^18 bytes.
73+
exaByte,
74+
75+
/// Exbibyte (`"exbibyte"`), 2^60 bytes.
76+
exbiByte,
77+
78+
/// Fraction units
79+
80+
/// Floating point fraction of `1`.
81+
ratio,
82+
83+
/// Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`.
84+
percent,
85+
2686
/// Untyped value without a unit.
2787
none,
2888
}
2989

3090
extension SentryMeasurementUnitExtension on SentryMeasurementUnit {
3191
String toStringValue() {
3292
switch (this) {
93+
// Duration units
3394
case SentryMeasurementUnit.nanoSecond:
3495
return 'nanosecond';
3596
case SentryMeasurementUnit.microSecond:
@@ -46,6 +107,44 @@ extension SentryMeasurementUnitExtension on SentryMeasurementUnit {
46107
return 'day';
47108
case SentryMeasurementUnit.week:
48109
return 'week';
110+
111+
// Information units
112+
case SentryMeasurementUnit.bit:
113+
return 'bit';
114+
case SentryMeasurementUnit.byte:
115+
return 'byte';
116+
case SentryMeasurementUnit.kiloByte:
117+
return 'kilobyte';
118+
case SentryMeasurementUnit.kibiByte:
119+
return 'kibibyte';
120+
case SentryMeasurementUnit.megaByte:
121+
return 'megabyte';
122+
case SentryMeasurementUnit.mebiByte:
123+
return 'mebibyte';
124+
case SentryMeasurementUnit.gigaByte:
125+
return 'gigabyte';
126+
case SentryMeasurementUnit.gibiByte:
127+
return 'gibibyte';
128+
case SentryMeasurementUnit.teraByte:
129+
return 'terabyte';
130+
case SentryMeasurementUnit.tebiByte:
131+
return 'tebibyte';
132+
case SentryMeasurementUnit.petaByte:
133+
return 'petabyte';
134+
case SentryMeasurementUnit.pebiByte:
135+
return 'pebibyte';
136+
case SentryMeasurementUnit.exaByte:
137+
return 'exabyte';
138+
case SentryMeasurementUnit.exbiByte:
139+
return 'exbibyte';
140+
141+
// Fraction units
142+
case SentryMeasurementUnit.ratio:
143+
return 'ratio';
144+
case SentryMeasurementUnit.percent:
145+
return 'percent';
146+
147+
// Untyped value
49148
case SentryMeasurementUnit.none:
50149
return 'none';
51150
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import 'package:sentry/sentry.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('$SentryMeasurementUnit', () {
6+
group('DurationUnit', () {
7+
test('nanosecond', () {
8+
expect(SentryMeasurementUnit.nanoSecond.toStringValue(), 'nanosecond');
9+
});
10+
11+
test('microsecond', () {
12+
expect(
13+
SentryMeasurementUnit.microSecond.toStringValue(), 'microsecond');
14+
});
15+
16+
test('millisecond', () {
17+
expect(
18+
SentryMeasurementUnit.milliSecond.toStringValue(), 'millisecond');
19+
});
20+
21+
test('second', () {
22+
expect(SentryMeasurementUnit.second.toStringValue(), 'second');
23+
});
24+
25+
test('minute', () {
26+
expect(SentryMeasurementUnit.minute.toStringValue(), 'minute');
27+
});
28+
29+
test('hour', () {
30+
expect(SentryMeasurementUnit.hour.toStringValue(), 'hour');
31+
});
32+
33+
test('day', () {
34+
expect(SentryMeasurementUnit.day.toStringValue(), 'day');
35+
});
36+
37+
test('week', () {
38+
expect(SentryMeasurementUnit.week.toStringValue(), 'week');
39+
});
40+
});
41+
42+
group('FractionUnit', () {
43+
test('ratio', () {
44+
expect(SentryMeasurementUnit.ratio.toStringValue(), 'ratio');
45+
});
46+
47+
test('percent', () {
48+
expect(SentryMeasurementUnit.percent.toStringValue(), 'percent');
49+
});
50+
});
51+
52+
group('None', () {
53+
test('none', () {
54+
expect(SentryMeasurementUnit.none.toStringValue(), 'none');
55+
});
56+
});
57+
58+
group('InformationUnit', () {
59+
test('bit', () {
60+
expect(SentryMeasurementUnit.bit.toStringValue(), 'bit');
61+
});
62+
63+
test('byte', () {
64+
expect(SentryMeasurementUnit.byte.toStringValue(), 'byte');
65+
});
66+
67+
test('kilobyte', () {
68+
expect(SentryMeasurementUnit.kiloByte.toStringValue(), 'kilobyte');
69+
});
70+
71+
test('kibibyte', () {
72+
expect(SentryMeasurementUnit.kibiByte.toStringValue(), 'kibibyte');
73+
});
74+
75+
test('megabyte', () {
76+
expect(SentryMeasurementUnit.megaByte.toStringValue(), 'megabyte');
77+
});
78+
79+
test('mebibyte', () {
80+
expect(SentryMeasurementUnit.mebiByte.toStringValue(), 'mebibyte');
81+
});
82+
83+
test('gigabyte', () {
84+
expect(SentryMeasurementUnit.gigaByte.toStringValue(), 'gigabyte');
85+
});
86+
87+
test('gibibyte', () {
88+
expect(SentryMeasurementUnit.gibiByte.toStringValue(), 'gibibyte');
89+
});
90+
test('terabyte', () {
91+
expect(SentryMeasurementUnit.teraByte.toStringValue(), 'terabyte');
92+
});
93+
test('tebibyte', () {
94+
expect(SentryMeasurementUnit.tebiByte.toStringValue(), 'tebibyte');
95+
});
96+
test('petabyte', () {
97+
expect(SentryMeasurementUnit.petaByte.toStringValue(), 'petabyte');
98+
});
99+
test('pebibyte', () {
100+
expect(SentryMeasurementUnit.pebiByte.toStringValue(), 'pebibyte');
101+
});
102+
test('exabyte', () {
103+
expect(SentryMeasurementUnit.exaByte.toStringValue(), 'exabyte');
104+
});
105+
test('exbibyte', () {
106+
expect(SentryMeasurementUnit.exbiByte.toStringValue(), 'exbibyte');
107+
});
108+
});
109+
});
110+
}

0 commit comments

Comments
 (0)