diff --git a/CHANGELOG.md b/CHANGELOG.md index 62b0a89dba..e44fb822c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dart/lib/src/sentry_measurement_unit.dart b/dart/lib/src/sentry_measurement_unit.dart index e53432b827..257dd1b6bc 100644 --- a/dart/lib/src/sentry_measurement_unit.dart +++ b/dart/lib/src/sentry_measurement_unit.dart @@ -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. enum SentryMeasurementUnit { + /// Duration units + /// Nanosecond (`"nanosecond"`), 10^-9 seconds. nanoSecond, @@ -23,6 +31,58 @@ 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, } @@ -30,6 +90,7 @@ enum SentryMeasurementUnit { extension SentryMeasurementUnitExtension on SentryMeasurementUnit { String toStringValue() { switch (this) { + // Duration units case SentryMeasurementUnit.nanoSecond: return 'nanosecond'; case SentryMeasurementUnit.microSecond: @@ -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'; } diff --git a/dart/test/sentry_measurement_unit_test.dart b/dart/test/sentry_measurement_unit_test.dart new file mode 100644 index 0000000000..2af0a27aff --- /dev/null +++ b/dart/test/sentry_measurement_unit_test.dart @@ -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'); + }); + }); + }); +}