Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

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

### Features

Expand Down
99 changes: 99 additions & 0 deletions dart/lib/src/sentry_measurement_unit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/// The unit of measurement of a metric value.
/// Units augment metric values by giving them a magnitude and semantics.
/// Units and their precisions are uniquely represented by a string identifier.
///
/// This is a singe enum because Enhanced Enums in Dart is only available
/// in newer versions.
Comment on lines +5 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limitation before Dart 2.17 and we cannot do breaking changes just yet.
It's either this or an open String, but this has better UX, so users don't need to find out the units by themselves via docs.

enum SentryMeasurementUnit {
/// Duration units

/// Nanosecond (`"nanosecond"`), 10^-9 seconds.
nanoSecond,

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

/// Information units

/// Bit (`"bit"`), corresponding to 1/8 of a byte.
bit,

/// Byte (`"byte"`).
byte,

/// Kilobyte (`"kilobyte"`), 10^3 bytes.
kiloByte,

/// Kibibyte (`"kibibyte"`), 2^10 bytes.
kibiByte,

/// Megabyte (`"megabyte"`), 10^6 bytes.
megaByte,

/// Mebibyte (`"mebibyte"`), 2^20 bytes.
mebiByte,

/// Gigabyte (`"gigabyte"`), 10^9 bytes.
gigaByte,

/// Gibibyte (`"gibibyte"`), 2^30 bytes.
gibiByte,

/// Terabyte (`"terabyte"`), 10^12 bytes.
teraByte,

/// Tebibyte (`"tebibyte"`), 2^40 bytes.
tebiByte,

/// Petabyte (`"petabyte"`), 10^15 bytes.
petaByte,

/// Pebibyte (`"pebibyte"`), 2^50 bytes.
pebiByte,

/// Exabyte (`"exabyte"`), 10^18 bytes.
exaByte,

/// Exbibyte (`"exbibyte"`), 2^60 bytes.
exbiByte,

/// Fraction units

/// Floating point fraction of `1`.
ratio,

/// Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`.
percent,

/// Untyped value without a unit.
none,
}

extension SentryMeasurementUnitExtension on SentryMeasurementUnit {
String toStringValue() {
switch (this) {
// Duration units
case SentryMeasurementUnit.nanoSecond:
return 'nanosecond';
case SentryMeasurementUnit.microSecond:
Expand All @@ -46,6 +107,44 @@ extension SentryMeasurementUnitExtension on SentryMeasurementUnit {
return 'day';
case SentryMeasurementUnit.week:
return 'week';

// Information units
case SentryMeasurementUnit.bit:
return 'bit';
case SentryMeasurementUnit.byte:
return 'byte';
case SentryMeasurementUnit.kiloByte:
return 'kilobyte';
case SentryMeasurementUnit.kibiByte:
return 'kibibyte';
case SentryMeasurementUnit.megaByte:
return 'megabyte';
case SentryMeasurementUnit.mebiByte:
return 'mebibyte';
case SentryMeasurementUnit.gigaByte:
return 'gigabyte';
case SentryMeasurementUnit.gibiByte:
return 'gibibyte';
case SentryMeasurementUnit.teraByte:
return 'terabyte';
case SentryMeasurementUnit.tebiByte:
return 'tebibyte';
case SentryMeasurementUnit.petaByte:
return 'petabyte';
case SentryMeasurementUnit.pebiByte:
return 'pebibyte';
case SentryMeasurementUnit.exaByte:
return 'exabyte';
case SentryMeasurementUnit.exbiByte:
return 'exbibyte';

// Fraction units
case SentryMeasurementUnit.ratio:
return 'ratio';
case SentryMeasurementUnit.percent:
return 'percent';

// Untyped value
case SentryMeasurementUnit.none:
return 'none';
}
Expand Down
110 changes: 110 additions & 0 deletions dart/test/sentry_measurement_unit_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

void main() {
group('$SentryMeasurementUnit', () {
group('DurationUnit', () {
test('nanosecond', () {
expect(SentryMeasurementUnit.nanoSecond.toStringValue(), 'nanosecond');
});

test('microsecond', () {
expect(
SentryMeasurementUnit.microSecond.toStringValue(), 'microsecond');
});

test('millisecond', () {
expect(
SentryMeasurementUnit.milliSecond.toStringValue(), 'millisecond');
});

test('second', () {
expect(SentryMeasurementUnit.second.toStringValue(), 'second');
});

test('minute', () {
expect(SentryMeasurementUnit.minute.toStringValue(), 'minute');
});

test('hour', () {
expect(SentryMeasurementUnit.hour.toStringValue(), 'hour');
});

test('day', () {
expect(SentryMeasurementUnit.day.toStringValue(), 'day');
});

test('week', () {
expect(SentryMeasurementUnit.week.toStringValue(), 'week');
});
});

group('FractionUnit', () {
test('ratio', () {
expect(SentryMeasurementUnit.ratio.toStringValue(), 'ratio');
});

test('percent', () {
expect(SentryMeasurementUnit.percent.toStringValue(), 'percent');
});
});

group('None', () {
test('none', () {
expect(SentryMeasurementUnit.none.toStringValue(), 'none');
});
});

group('InformationUnit', () {
test('bit', () {
expect(SentryMeasurementUnit.bit.toStringValue(), 'bit');
});

test('byte', () {
expect(SentryMeasurementUnit.byte.toStringValue(), 'byte');
});

test('kilobyte', () {
expect(SentryMeasurementUnit.kiloByte.toStringValue(), 'kilobyte');
});

test('kibibyte', () {
expect(SentryMeasurementUnit.kibiByte.toStringValue(), 'kibibyte');
});

test('megabyte', () {
expect(SentryMeasurementUnit.megaByte.toStringValue(), 'megabyte');
});

test('mebibyte', () {
expect(SentryMeasurementUnit.mebiByte.toStringValue(), 'mebibyte');
});

test('gigabyte', () {
expect(SentryMeasurementUnit.gigaByte.toStringValue(), 'gigabyte');
});

test('gibibyte', () {
expect(SentryMeasurementUnit.gibiByte.toStringValue(), 'gibibyte');
});
test('terabyte', () {
expect(SentryMeasurementUnit.teraByte.toStringValue(), 'terabyte');
});
test('tebibyte', () {
expect(SentryMeasurementUnit.tebiByte.toStringValue(), 'tebibyte');
});
test('petabyte', () {
expect(SentryMeasurementUnit.petaByte.toStringValue(), 'petabyte');
});
test('pebibyte', () {
expect(SentryMeasurementUnit.pebiByte.toStringValue(), 'pebibyte');
});
test('exabyte', () {
expect(SentryMeasurementUnit.exaByte.toStringValue(), 'exabyte');
});
test('exbibyte', () {
expect(SentryMeasurementUnit.exbiByte.toStringValue(), 'exbibyte');
});
});
});
}