From febcbbb17753efffead87320a470936ff07ebbd8 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Fri, 7 Oct 2022 11:07:42 +0200 Subject: [PATCH 01/17] feat: Custom measurements API --- .../iOS-Swift/iOS-Swift/ViewController.swift | 7 ++ Sources/Sentry/Public/SentryDefines.h | 81 +++++++++++++ Sources/Sentry/Public/SentrySpanProtocol.h | 22 ++++ Sources/Sentry/SentryNoOpSpan.m | 26 +++++ Sources/Sentry/SentrySpan.m | 26 +++++ Sources/Sentry/SentryTracer.m | 106 ++++++++++++++++++ 6 files changed, 268 insertions(+) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index e0f465e8bda..95718d60a17 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -141,6 +141,13 @@ class ViewController: UIViewController { @IBAction func captureTransaction(_ sender: Any) { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") + + transaction.setMeasurement(name: "custom", value: 44, customUnit: "custom-unit") + transaction.setMeasurement(name: "none", value: 55) + transaction.setMeasurement(name: "duration", value: 1.23, durationUnit: .milliSecond) + transaction.setMeasurement(name: "information", value: 134.3, informationUnit: .gigabyte) + transaction.setMeasurement(name: "fraction", value: 9.3, fractionUnit: .percent) + let span = transaction.startChild(operation: "user", description: "calls out") DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: { diff --git a/Sources/Sentry/Public/SentryDefines.h b/Sources/Sentry/Public/SentryDefines.h index 48a7698048e..2012fa3a160 100644 --- a/Sources/Sentry/Public/SentryDefines.h +++ b/Sources/Sentry/Public/SentryDefines.h @@ -142,3 +142,84 @@ typedef NS_ENUM(NSInteger, SentryTransactionNameSource) { kSentryTransactionNameSourceComponent, kSentryTransactionNameSourceTask }; + +/** + * A time duration. + */ +typedef NS_ENUM(NSInteger, SentryDurationUnit) { + /** Nanosecond (`"nanosecond"`), 10^-9 seconds. */ + kSentryDurationUnitNanoSecond = 0, + /** Microsecond (`"microsecond"`), 10^-6 seconds. */ + kSentryDurationUnitMicroSecond, + /** Millisecond (`"millisecond"`), 10^-3 seconds. */ + kSentryDurationUnitMilliSecond, + /** Full second (`"second"`). */ + kSentryDurationUnitSecond, + /** Minute (`"minute"`), 60 seconds. */ + kSentryDurationUnitMinute, + /** Hour (`"hour"`), 3600 seconds. */ + kSentryDurationUnitHour, + /** Day (`"day"`), 86,400 seconds. */ + kSentryDurationUnitDay, + /** Week (`"week"`), 604,800 seconds. */ + kSentryDurationUnitWeek +} NS_SWIFT_NAME(DurationUnit); + +/** + * Size of information derived from bytes. + */ +typedef NS_ENUM(NSInteger, SentryInformationUnit) { + /** Bit (`"bit"`), corresponding to 1/8 of a byte. */ + kSentryInformationUnitBit, + + /** Byte (`"byte"`). */ + kSentryInformationUnitByte, + + /** Kilobyte (`"kilobyte"`), 10^3 bytes. */ + kSentryInformationUnitKilobyte, + + /** Kibibyte (`"kibibyte"`), 2^10 bytes. */ + kSentryInformationUnitKibibyte, + + /** Megabyte (`"megabyte"`), 10^6 bytes. */ + kSentryInformationUnitMegabyte, + + /** Mebibyte (`"mebibyte"`), 2^20 bytes. */ + kSentryInformationUnitMebibyte, + + /** Gigabyte (`"gigabyte"`), 10^9 bytes. */ + kSentryInformationUnitGigabyte, + + /** Gibibyte (`"gibibyte"`), 2^30 bytes. */ + kSentryInformationUnitGibibyte, + + /** Terabyte (`"terabyte"`), 10^12 bytes. */ + kSentryInformationUnitTerabyte, + + /** Tebibyte (`"tebibyte"`), 2^40 bytes. */ + kSentryInformationUnitTebibyte, + + /** Petabyte (`"petabyte"`), 10^15 bytes. */ + kSentryInformationUnitPetabyte, + + /** Pebibyte (`"pebibyte"`), 2^50 bytes. */ + kSentryInformationUnitPebibyte, + + /** Exabyte (`"exabyte"`), 10^18 bytes. */ + kSentryInformationUnitExabyte, + + /** Exbibyte (`"exbibyte"`), 2^60 bytes. */ + kSentryInformationUnitExbibyte +} NS_SWIFT_NAME(InformationUnit); + +/** + * Fractions such as percentages. + */ +typedef NS_ENUM(NSInteger, SentryFractionUnit) { + + /** Floating point fraction of `1`. */ + kSentryFractionUnitRatio = 0, + + /** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ + kSentryFractionUnitPercent +} NS_SWIFT_NAME(FractionUnit); diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 4fbc1abf50f..99c7fea58a2 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -87,6 +87,28 @@ NS_SWIFT_NAME(Span) */ - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value NS_SWIFT_NAME(setMeasurement(name:value:)); + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + durationUnit:(SentryDurationUnit)durationUnit + NS_SWIFT_NAME(setMeasurement(name:value:durationUnit:)); + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + informationUnit:(SentryInformationUnit)informationUnit + NS_SWIFT_NAME(setMeasurement(name:value:informationUnit:)); + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + fractionUnit:(SentryFractionUnit)fractionUnit + NS_SWIFT_NAME(setMeasurement(name:value:fractionUnit:)); + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + customUnit:(NSString *)customUnit NS_SWIFT_NAME(setMeasurement(name:value:customUnit:)); + /** * Finishes the span by setting the end time. */ diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index 0ad045b7596..77ddd42bc0a 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -64,6 +64,32 @@ - (void)removeTagForKey:(NSString *)key { } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + durationUnit:(SentryDurationUnit)durationUnit +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + informationUnit:(SentryInformationUnit)informationUnit +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + fractionUnit:(SentryFractionUnit)fractionUnit +{ +} + +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit +{ +} + - (NSDictionary *)tags { return @{}; diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 2dab3697943..06104e901be 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -89,6 +89,32 @@ - (void)removeTagForKey:(NSString *)key } } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + durationUnit:(SentryDurationUnit)durationUnit +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + informationUnit:(SentryInformationUnit)informationUnit +{ +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + fractionUnit:(SentryFractionUnit)fractionUnit +{ +} + +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit +{ +} + - (NSDictionary *)tags { @synchronized(_tags) { diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 167363dc263..c212d123c22 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -61,6 +61,7 @@ @implementation SentryTracer { SentryAppStartMeasurement *appStartMeasurement; NSMutableDictionary *_tags; NSMutableDictionary *_data; + NSMutableDictionary *_measurements; dispatch_block_t _idleTimeoutBlock; NSMutableArray> *_children; @@ -160,6 +161,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti _waitForChildren = waitForChildren; _tags = [[NSMutableDictionary alloc] init]; _data = [[NSMutableDictionary alloc] init]; + _measurements = [[NSMutableDictionary alloc] init]; self.finishStatus = kSentrySpanStatusUndefined; self.idleTimeout = idleTimeout; self.dispatchQueueWrapper = dispatchQueueWrapper; @@ -395,6 +397,106 @@ - (void)removeTagForKey:(NSString *)key } } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ + _measurements[name] = @{ @"value" : value, @"unit" : @"none" }; +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + durationUnit:(SentryDurationUnit)durationUnit +{ + _measurements[name] = + @{ @"value" : value, @"unit" : [self stringForDurationUnit:durationUnit] }; +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + informationUnit:(SentryInformationUnit)informationUnit +{ + _measurements[name] = + @{ @"value" : value, @"unit" : [self stringForInformationUnit:informationUnit] }; +} + +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + fractionUnit:(SentryFractionUnit)fractionUnit +{ + _measurements[name] = + @{ @"value" : value, @"unit" : [self stringForFractionUnit:fractionUnit] }; +} + +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit +{ + _measurements[name] = @{ @"value" : value, @"unit" : customUnit }; +} + +- (NSString *)stringForDurationUnit:(SentryDurationUnit)duration +{ + switch (duration) { + case kSentryDurationUnitNanoSecond: + return @"nanosecond"; + case kSentryDurationUnitMicroSecond: + return @"microsecond"; + case kSentryDurationUnitMilliSecond: + return @"millisecond"; + case kSentryDurationUnitSecond: + return @"second"; + case kSentryDurationUnitMinute: + return @"minute"; + case kSentryDurationUnitHour: + return @"hour"; + case kSentryDurationUnitDay: + return @"day"; + case kSentryDurationUnitWeek: + return @"week"; + } +} + +- (NSString *)stringForInformationUnit:(SentryInformationUnit)informationUnit +{ + switch (informationUnit) { + case kSentryInformationUnitBit: + return @"bit"; + case kSentryInformationUnitByte: + return @"byte"; + case kSentryInformationUnitKilobyte: + return @"kilobyte"; + case kSentryInformationUnitKibibyte: + return @"kibibyte"; + case kSentryInformationUnitMegabyte: + return @"megabyte"; + case kSentryInformationUnitMebibyte: + return @"mebibyte"; + case kSentryInformationUnitGigabyte: + return @"gigabyte"; + case kSentryInformationUnitGibibyte: + return @"gibibyte"; + case kSentryInformationUnitTerabyte: + return @"terabyte"; + case kSentryInformationUnitTebibyte: + return @"tebibyte"; + case kSentryInformationUnitPetabyte: + return @"petabyte"; + case kSentryInformationUnitPebibyte: + return @"pebibyte"; + case kSentryInformationUnitExabyte: + return @"exabyte"; + case kSentryInformationUnitExbibyte: + return @"exbibyte"; + } +} + +- (NSString *)stringForFractionUnit:(SentryFractionUnit)fraction +{ + switch (fraction) { + case kSentryFractionUnitRatio: + return @"ratio"; + case kSentryFractionUnitPercent: + return @"percent"; + } +} + - (SentryTraceHeader *)toTraceHeader { return [self.rootSpan toTraceHeader]; @@ -727,6 +829,10 @@ - (void)addMeasurements:(SentryTransaction *)transaction } } #endif + + for (NSString *key in _measurements) { + [transaction setMeasurementValue:_measurements[key] forKey:key]; + } } - (id)buildSpan:(SentrySpanId *)parentId From 4ae6b3fba70002eeaa827e7659bdefc1e9397ee8 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Mon, 10 Oct 2022 11:45:16 +0200 Subject: [PATCH 02/17] Make API similar to NSMEasurement --- .../iOS-Swift/iOS-Swift/ViewController.swift | 7 +- Sentry.xcodeproj/project.pbxproj | 16 +++ Sources/Sentry/Public/Sentry.h | 2 + Sources/Sentry/Public/SentryMeasurement.h | 18 +++ Sources/Sentry/Public/SentryOptions.h | 4 +- Sources/Sentry/Public/SentrySpanProtocol.h | 24 +--- Sources/Sentry/Public/SentryUnit.h | 47 ++++++++ Sources/Sentry/SentryMeasurement.m | 24 ++++ Sources/Sentry/SentryNoOpSpan.m | 24 +--- Sources/Sentry/SentryOptions.m | 4 + Sources/Sentry/SentrySpan.m | 25 +--- Sources/Sentry/SentryTracer.m | 110 ++---------------- Sources/Sentry/SentryUnit.m | 54 +++++++++ 13 files changed, 184 insertions(+), 175 deletions(-) create mode 100644 Sources/Sentry/Public/SentryMeasurement.h create mode 100644 Sources/Sentry/Public/SentryUnit.h create mode 100644 Sources/Sentry/SentryMeasurement.m create mode 100644 Sources/Sentry/SentryUnit.m diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index 95718d60a17..632a9d36a08 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -142,11 +142,8 @@ class ViewController: UIViewController { @IBAction func captureTransaction(_ sender: Any) { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") - transaction.setMeasurement(name: "custom", value: 44, customUnit: "custom-unit") - transaction.setMeasurement(name: "none", value: 55) - transaction.setMeasurement(name: "duration", value: 1.23, durationUnit: .milliSecond) - transaction.setMeasurement(name: "information", value: 134.3, informationUnit: .gigabyte) - transaction.setMeasurement(name: "fraction", value: 9.3, fractionUnit: .percent) + transaction.setMeasurement(SentryMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanoseconds)) + transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(symbol: "custom"))) let span = transaction.startChild(operation: "user", description: "calls out") diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 51b3821838b..2d35832bcd6 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -492,6 +492,10 @@ 7BC8523724588115005A70F0 /* SentryDataCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC8523624588115005A70F0 /* SentryDataCategory.h */; }; 7BC852392458830A005A70F0 /* SentryEnvelopeItemType.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC8523B2458849E005A70F0 /* SentryDataCategoryMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */; }; + 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7BC9A20228F41350001E7C4C /* SentryUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A20128F41350001E7C4C /* SentryUnit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */; }; + 7BC9A20628F41781001E7C4C /* SentryUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20528F41781001E7C4C /* SentryUnit.m */; }; 7BCFA71627D0BB50008C662C /* SentryANRTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BCFA71527D0BB50008C662C /* SentryANRTracker.m */; }; 7BCFBD672681C95000BC27D8 /* SentryScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD662681C95000BC27D8 /* SentryScopeObserver.h */; }; 7BCFBD6D2681D0A900BC27D8 /* SentryCrashScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD6C2681D0A900BC27D8 /* SentryCrashScopeObserver.h */; }; @@ -1224,6 +1228,10 @@ 7BC8523624588115005A70F0 /* SentryDataCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDataCategory.h; path = include/SentryDataCategory.h; sourceTree = ""; }; 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeItemType.h; path = Public/SentryEnvelopeItemType.h; sourceTree = ""; }; 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDataCategoryMapperTests.swift; sourceTree = ""; }; + 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = Public/SentryMeasurement.h; sourceTree = ""; }; + 7BC9A20128F41350001E7C4C /* SentryUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUnit.h; path = Public/SentryUnit.h; sourceTree = ""; }; + 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurement.m; sourceTree = ""; }; + 7BC9A20528F41781001E7C4C /* SentryUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUnit.m; sourceTree = ""; }; 7BC9CD4326A99F660047518E /* SentryUIViewControllerSwizzling+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryUIViewControllerSwizzling+Test.h"; sourceTree = ""; }; 7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTracker.h; path = include/SentryANRTracker.h; sourceTree = ""; }; 7BCFA71527D0BB50008C662C /* SentryANRTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryANRTracker.m; sourceTree = ""; }; @@ -1612,6 +1620,10 @@ 7BD4BD4427EB29F50071F4FF /* SentryClientReport.m */, 7BD4BD4627EB2A3D0071F4FF /* SentryDiscardedEvent.h */, 7BD4BD4827EB2A5D0071F4FF /* SentryDiscardedEvent.m */, + 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */, + 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */, + 7BC9A20128F41350001E7C4C /* SentryUnit.h */, + 7BC9A20528F41781001E7C4C /* SentryUnit.m */, ); name = Protocol; sourceTree = ""; @@ -2895,6 +2907,7 @@ 0A2D8DA8289BC905008720F6 /* SentryViewHierarchy.h in Headers */, 8EAE980C261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h in Headers */, 63FE717D20DA4C1100CDBAE8 /* SentryCrashCachedData.h in Headers */, + 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */, 7BBC826D25DFCFDE005F1ED8 /* SentryInAppLogic.h in Headers */, 03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */, 7B0A54222521C21E00A71716 /* SentryFrameRemover.h in Headers */, @@ -2987,6 +3000,7 @@ 7DC27EC523997EB7006998B5 /* SentryAutoBreadcrumbTrackingIntegration.h in Headers */, 63FE707F20DA4C1000CDBAE8 /* SentryCrashVarArgs.h in Headers */, 03F84D2627DD414C008FE43F /* SentryThreadMetadataCache.hpp in Headers */, + 7BC9A20228F41350001E7C4C /* SentryUnit.h in Headers */, 7BB654FB253DC14A00887E87 /* SentryUserFeedback.h in Headers */, 7B8ECBFA26498907005FE2EF /* SentryAppStateManager.h in Headers */, 639FCFA01EBC804600778193 /* SentryException.h in Headers */, @@ -3414,6 +3428,7 @@ 8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */, D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */, 8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */, + 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */, D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */, 7BD86EC7264A641D005439DB /* SentrySysctl.m in Sources */, D859697327BECDD20036A46E /* SentryCoreDataSwizzling.m in Sources */, @@ -3430,6 +3445,7 @@ 0356A571288B4612008BF593 /* SentryProfilesSampler.m in Sources */, 63FE710B20DA4C1000CDBAE8 /* SentryCrashMach.c in Sources */, 63FE707720DA4C1000CDBAE8 /* Container+SentryDeepSearch.m in Sources */, + 7BC9A20628F41781001E7C4C /* SentryUnit.m in Sources */, 63FE71A020DA4C1100CDBAE8 /* SentryCrashInstallation.m in Sources */, 63FE713520DA4C1100CDBAE8 /* SentryCrashMemory.c in Sources */, 63FE714520DA4C1100CDBAE8 /* SentryCrashObjC.c in Sources */, diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index 8fb98787446..88391a59285 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -25,6 +25,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryHub.h" #import "SentryId.h" #import "SentryIntegrationProtocol.h" +#import "SentryMeasurement.h" #import "SentryMechanism.h" #import "SentryMechanismMeta.h" #import "SentryMessage.h" @@ -46,5 +47,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryThread.h" #import "SentryTraceHeader.h" #import "SentryTransactionContext.h" +#import "SentryUnit.h" #import "SentryUser.h" #import "SentryUserFeedback.h" diff --git a/Sources/Sentry/Public/SentryMeasurement.h b/Sources/Sentry/Public/SentryMeasurement.h new file mode 100644 index 00000000000..56a59b262b6 --- /dev/null +++ b/Sources/Sentry/Public/SentryMeasurement.h @@ -0,0 +1,18 @@ +#import "SentryDefines.h" +#import "SentrySerializable.h" +#import "SentryUnit.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SentryMeasurement : NSObject +SENTRY_NO_INIT + +- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(UnitType)unit; + +@property (nonatomic, copy, readonly) NSString *name; +@property (nonatomic, copy, readonly) NSNumber *value; +@property (readonly, copy) UnitType unit; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/Public/SentryOptions.h b/Sources/Sentry/Public/SentryOptions.h index fec00739085..109478fafa7 100644 --- a/Sources/Sentry/Public/SentryOptions.h +++ b/Sources/Sentry/Public/SentryOptions.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentryDsn, SentrySdkInfo; +@class SentryDsn, SentrySdkInfo, SentryMeasurement; NS_SWIFT_NAME(Options) @interface SentryOptions : NSObject @@ -196,6 +196,8 @@ NS_SWIFT_NAME(Options) */ @property (nonatomic, assign) BOOL enableAutoPerformanceTracking; +- (void)setMeasurement:(SentryMeasurement *)measurement; + #if SENTRY_HAS_UIKIT /** * When enabled, the SDK tracks performance for UIViewController subclasses. The default is diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 99c7fea58a2..67f3c856190 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentrySpanId, SentryId, SentryTraceHeader; +@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurement; NS_SWIFT_NAME(Span) @protocol SentrySpan @@ -87,27 +87,7 @@ NS_SWIFT_NAME(Span) */ - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value NS_SWIFT_NAME(setMeasurement(name:value:)); - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - durationUnit:(SentryDurationUnit)durationUnit - NS_SWIFT_NAME(setMeasurement(name:value:durationUnit:)); - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - informationUnit:(SentryInformationUnit)informationUnit - NS_SWIFT_NAME(setMeasurement(name:value:informationUnit:)); - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - fractionUnit:(SentryFractionUnit)fractionUnit - NS_SWIFT_NAME(setMeasurement(name:value:fractionUnit:)); - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - customUnit:(NSString *)customUnit NS_SWIFT_NAME(setMeasurement(name:value:customUnit:)); +- (void)setMeasurement:(SentryMeasurement *)measurement; /** * Finishes the span by setting the end time. diff --git a/Sources/Sentry/Public/SentryUnit.h b/Sources/Sentry/Public/SentryUnit.h new file mode 100644 index 00000000000..d8ad32fb4fc --- /dev/null +++ b/Sources/Sentry/Public/SentryUnit.h @@ -0,0 +1,47 @@ +#import "SentryDefines.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SentryUnit : NSObject +SENTRY_NO_INIT + +- (instancetype)initWithSymbol:(NSString *)symbol; + +@property (readonly, copy) NSString *symbol; + +@end + +@interface SentryUnitDuration : SentryUnit +SENTRY_NO_INIT + +/** Nanosecond (`"nanosecond"`), 10^-9 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *nanoseconds; + +// ... + +@end + +@interface SentryUnitInformation : SentryUnit +SENTRY_NO_INIT + +/** Bit (`"bit"`), corresponding to 1/8 of a byte. */ +@property (class, readonly, copy) SentryUnitInformation *bit; + +// ... + +@end + +@interface SentryUnitFraction : SentryUnit +SENTRY_NO_INIT + +/** Floating point fraction of `1`. */ +@property (class, readonly, copy) SentryUnitFraction *ratio; + +/** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ +@property (class, readonly, copy) SentryUnitFraction *percent; + +// ... + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryMeasurement.m b/Sources/Sentry/SentryMeasurement.m new file mode 100644 index 00000000000..2012becba5c --- /dev/null +++ b/Sources/Sentry/SentryMeasurement.m @@ -0,0 +1,24 @@ +#import "SentryMeasurement.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SentryMeasurement + +- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +{ + if (self = [super init]) { + _name = name; + _value = value; + _unit = unit; + } + return self; +} + +- (NSDictionary *)serialize +{ + return @{ @"name" : self.name, @"value" : self.value, @"unit" : self.unit.symbol }; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index 77ddd42bc0a..b30c7e8db01 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -64,29 +64,7 @@ - (void)removeTagForKey:(NSString *)key { } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - durationUnit:(SentryDurationUnit)durationUnit -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - informationUnit:(SentryInformationUnit)informationUnit -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - fractionUnit:(SentryFractionUnit)fractionUnit -{ -} - -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit +- (void)setMeasurement:(SentryMeasurement *)measurement { } diff --git a/Sources/Sentry/SentryOptions.m b/Sources/Sentry/SentryOptions.m index 150b7f440a6..02fac2d4729 100644 --- a/Sources/Sentry/SentryOptions.m +++ b/Sources/Sentry/SentryOptions.m @@ -20,6 +20,10 @@ @implementation SentryOptions +- (void)setMeasurement:(SentryMeasurement *)measurement +{ +} + + (NSArray *)defaultIntegrations { return @[ diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 06104e901be..11037db7ebe 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -3,6 +3,7 @@ #import "NSDictionary+SentrySanitize.h" #import "SentryCurrentDate.h" #import "SentryLog.h" +#import "SentryMeasurement.h" #import "SentryNoOpSpan.h" #import "SentryTraceHeader.h" #import "SentryTracer.h" @@ -89,29 +90,7 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - durationUnit:(SentryDurationUnit)durationUnit -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - informationUnit:(SentryInformationUnit)informationUnit -{ -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - fractionUnit:(SentryFractionUnit)fractionUnit -{ -} - -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit +- (void)setMeasurement:(SentryMeasurement *)measurement { } diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index c212d123c22..aae0aeb37a1 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -22,6 +22,7 @@ #import "SentryTransactionContext.h" #import "SentryUIViewControllerPerformanceTracker.h" #import +#import #import #import @@ -61,7 +62,7 @@ @implementation SentryTracer { SentryAppStartMeasurement *appStartMeasurement; NSMutableDictionary *_tags; NSMutableDictionary *_data; - NSMutableDictionary *_measurements; + NSMutableArray *_measurements; dispatch_block_t _idleTimeoutBlock; NSMutableArray> *_children; @@ -161,7 +162,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti _waitForChildren = waitForChildren; _tags = [[NSMutableDictionary alloc] init]; _data = [[NSMutableDictionary alloc] init]; - _measurements = [[NSMutableDictionary alloc] init]; + _measurements = [[NSMutableArray alloc] init]; self.finishStatus = kSentrySpanStatusUndefined; self.idleTimeout = idleTimeout; self.dispatchQueueWrapper = dispatchQueueWrapper; @@ -397,104 +398,9 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +- (void)setMeasurement:(SentryMeasurement *)measurement { - _measurements[name] = @{ @"value" : value, @"unit" : @"none" }; -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - durationUnit:(SentryDurationUnit)durationUnit -{ - _measurements[name] = - @{ @"value" : value, @"unit" : [self stringForDurationUnit:durationUnit] }; -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - informationUnit:(SentryInformationUnit)informationUnit -{ - _measurements[name] = - @{ @"value" : value, @"unit" : [self stringForInformationUnit:informationUnit] }; -} - -- (void)setMeasurement:(NSString *)name - value:(NSNumber *)value - fractionUnit:(SentryFractionUnit)fractionUnit -{ - _measurements[name] = - @{ @"value" : value, @"unit" : [self stringForFractionUnit:fractionUnit] }; -} - -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value customUnit:(NSString *)customUnit -{ - _measurements[name] = @{ @"value" : value, @"unit" : customUnit }; -} - -- (NSString *)stringForDurationUnit:(SentryDurationUnit)duration -{ - switch (duration) { - case kSentryDurationUnitNanoSecond: - return @"nanosecond"; - case kSentryDurationUnitMicroSecond: - return @"microsecond"; - case kSentryDurationUnitMilliSecond: - return @"millisecond"; - case kSentryDurationUnitSecond: - return @"second"; - case kSentryDurationUnitMinute: - return @"minute"; - case kSentryDurationUnitHour: - return @"hour"; - case kSentryDurationUnitDay: - return @"day"; - case kSentryDurationUnitWeek: - return @"week"; - } -} - -- (NSString *)stringForInformationUnit:(SentryInformationUnit)informationUnit -{ - switch (informationUnit) { - case kSentryInformationUnitBit: - return @"bit"; - case kSentryInformationUnitByte: - return @"byte"; - case kSentryInformationUnitKilobyte: - return @"kilobyte"; - case kSentryInformationUnitKibibyte: - return @"kibibyte"; - case kSentryInformationUnitMegabyte: - return @"megabyte"; - case kSentryInformationUnitMebibyte: - return @"mebibyte"; - case kSentryInformationUnitGigabyte: - return @"gigabyte"; - case kSentryInformationUnitGibibyte: - return @"gibibyte"; - case kSentryInformationUnitTerabyte: - return @"terabyte"; - case kSentryInformationUnitTebibyte: - return @"tebibyte"; - case kSentryInformationUnitPetabyte: - return @"petabyte"; - case kSentryInformationUnitPebibyte: - return @"pebibyte"; - case kSentryInformationUnitExabyte: - return @"exabyte"; - case kSentryInformationUnitExbibyte: - return @"exbibyte"; - } -} - -- (NSString *)stringForFractionUnit:(SentryFractionUnit)fraction -{ - switch (fraction) { - case kSentryFractionUnitRatio: - return @"ratio"; - case kSentryFractionUnitPercent: - return @"percent"; - } + [_measurements addObject:measurement]; } - (SentryTraceHeader *)toTraceHeader @@ -830,8 +736,10 @@ - (void)addMeasurements:(SentryTransaction *)transaction } #endif - for (NSString *key in _measurements) { - [transaction setMeasurementValue:_measurements[key] forKey:key]; + for (SentryMeasurement *measurement in _measurements) { + [transaction + setMeasurementValue:@{ @"value" : measurement.value, @"unit" : measurement.unit.symbol } + forKey:measurement.name]; } } diff --git a/Sources/Sentry/SentryUnit.m b/Sources/Sentry/SentryUnit.m new file mode 100644 index 00000000000..4912d91c61e --- /dev/null +++ b/Sources/Sentry/SentryUnit.m @@ -0,0 +1,54 @@ +#import "SentryUnit.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SentryUnit + +- (instancetype)initWithSymbol:(NSString *)symbol +{ + if (self = [super init]) { + _symbol = symbol; + } + return self; +} + +- (id)copyWithZone:(nullable NSZone *)zone +{ + return [[[self class] allocWithZone:zone] initWithSymbol:self.symbol]; +} + +@end + +@implementation SentryUnitDuration + ++ (SentryUnitDuration *)nanoseconds +{ + return [[SentryUnitDuration alloc] initWithSymbol:@"nanoseconds"]; +} + +@end + +@implementation SentryUnitInformation + ++ (SentryUnitDuration *)bit +{ + return [[SentryUnitDuration alloc] initWithSymbol:@"bit"]; +} + +@end + +@implementation SentryUnitFraction + ++ (SentryUnitFraction *)ratio +{ + return [[SentryUnitFraction alloc] initWithSymbol:@"ratio"]; +} + ++ (SentryUnitFraction *)percent +{ + return [[SentryUnitFraction alloc] initWithSymbol:@"percent"]; +} + +@end + +NS_ASSUME_NONNULL_END From 9d1c9b21de2304d45ae5a9fec6ecc7a485bf287e Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Mon, 10 Oct 2022 11:54:58 +0200 Subject: [PATCH 03/17] Rename symbol to unit --- Samples/iOS-Swift/iOS-Swift/ViewController.swift | 4 +++- Sources/Sentry/Public/SentryUnit.h | 4 ++-- Sources/Sentry/SentryMeasurement.m | 2 +- Sources/Sentry/SentryTracer.m | 2 +- Sources/Sentry/SentryUnit.m | 14 +++++++------- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index 632a9d36a08..3d4c2ff483d 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -143,7 +143,9 @@ class ViewController: UIViewController { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") transaction.setMeasurement(SentryMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanoseconds)) - transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(symbol: "custom"))) + transaction.setMeasurement(SentryMeasurement(name: "information", value: 44, unit: SentryUnitInformation.bit)) + transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom"))) + transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom"))) let span = transaction.startChild(operation: "user", description: "calls out") diff --git a/Sources/Sentry/Public/SentryUnit.h b/Sources/Sentry/Public/SentryUnit.h index d8ad32fb4fc..8572a1a219a 100644 --- a/Sources/Sentry/Public/SentryUnit.h +++ b/Sources/Sentry/Public/SentryUnit.h @@ -5,9 +5,9 @@ NS_ASSUME_NONNULL_BEGIN @interface SentryUnit : NSObject SENTRY_NO_INIT -- (instancetype)initWithSymbol:(NSString *)symbol; +- (instancetype)initWithUnit:(NSString *)unit; -@property (readonly, copy) NSString *symbol; +@property (readonly, copy) NSString *unit; @end diff --git a/Sources/Sentry/SentryMeasurement.m b/Sources/Sentry/SentryMeasurement.m index 2012becba5c..39df0631edf 100644 --- a/Sources/Sentry/SentryMeasurement.m +++ b/Sources/Sentry/SentryMeasurement.m @@ -16,7 +16,7 @@ - (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(Sent - (NSDictionary *)serialize { - return @{ @"name" : self.name, @"value" : self.value, @"unit" : self.unit.symbol }; + return @{ @"name" : self.name, @"value" : self.value, @"unit" : self.unit.unit }; } @end diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index aae0aeb37a1..698edc27a39 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -738,7 +738,7 @@ - (void)addMeasurements:(SentryTransaction *)transaction for (SentryMeasurement *measurement in _measurements) { [transaction - setMeasurementValue:@{ @"value" : measurement.value, @"unit" : measurement.unit.symbol } + setMeasurementValue:@{ @"value" : measurement.value, @"unit" : measurement.unit.unit } forKey:measurement.name]; } } diff --git a/Sources/Sentry/SentryUnit.m b/Sources/Sentry/SentryUnit.m index 4912d91c61e..fb13e15b2d3 100644 --- a/Sources/Sentry/SentryUnit.m +++ b/Sources/Sentry/SentryUnit.m @@ -4,17 +4,17 @@ @implementation SentryUnit -- (instancetype)initWithSymbol:(NSString *)symbol +- (instancetype)initWithUnit:(NSString *)unit { if (self = [super init]) { - _symbol = symbol; + _unit = unit; } return self; } - (id)copyWithZone:(nullable NSZone *)zone { - return [[[self class] allocWithZone:zone] initWithSymbol:self.symbol]; + return [[[self class] allocWithZone:zone] initWithSymbol:self.unit]; } @end @@ -23,7 +23,7 @@ @implementation SentryUnitDuration + (SentryUnitDuration *)nanoseconds { - return [[SentryUnitDuration alloc] initWithSymbol:@"nanoseconds"]; + return [[SentryUnitDuration alloc] initWithUnit:@"nanoseconds"]; } @end @@ -32,7 +32,7 @@ @implementation SentryUnitInformation + (SentryUnitDuration *)bit { - return [[SentryUnitDuration alloc] initWithSymbol:@"bit"]; + return [[SentryUnitDuration alloc] initWithUnit:@"bit"]; } @end @@ -41,12 +41,12 @@ @implementation SentryUnitFraction + (SentryUnitFraction *)ratio { - return [[SentryUnitFraction alloc] initWithSymbol:@"ratio"]; + return [[SentryUnitFraction alloc] initWithUnit:@"ratio"]; } + (SentryUnitFraction *)percent { - return [[SentryUnitFraction alloc] initWithSymbol:@"percent"]; + return [[SentryUnitFraction alloc] initWithUnit:@"percent"]; } @end From e424dafa3460bcc0c68d27b89a24a66c9c2d4efb Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 07:47:54 +0200 Subject: [PATCH 04/17] Simplify API --- .../iOS-Swift/iOS-Swift/ViewController.swift | 8 ++-- .../iOS-SwiftUI.xcodeproj/project.pbxproj | 41 +++++++++++++++++++ Sources/Sentry/Public/SentrySpanProtocol.h | 6 ++- Sources/Sentry/SentryNoOpSpan.m | 2 +- Sources/Sentry/SentrySpan.m | 3 +- Sources/Sentry/SentryTracer.m | 5 ++- .../SentryTests/Transaction/TestSentrySpan.m | 4 ++ 7 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index 3d4c2ff483d..49bd935f7b0 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -142,10 +142,10 @@ class ViewController: UIViewController { @IBAction func captureTransaction(_ sender: Any) { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") - transaction.setMeasurement(SentryMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanoseconds)) - transaction.setMeasurement(SentryMeasurement(name: "information", value: 44, unit: SentryUnitInformation.bit)) - transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom"))) - transaction.setMeasurement(SentryMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom"))) + transaction.setMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanoseconds) + transaction.setMeasurement(name: "information", value: 44, unit: SentryUnitInformation.bit) + transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) + transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) let span = transaction.startChild(operation: "user", description: "calls out") diff --git a/Samples/iOS-SwiftUI/iOS-SwiftUI.xcodeproj/project.pbxproj b/Samples/iOS-SwiftUI/iOS-SwiftUI.xcodeproj/project.pbxproj index 7f2fe9a967c..9a7cf1b0942 100644 --- a/Samples/iOS-SwiftUI/iOS-SwiftUI.xcodeproj/project.pbxproj +++ b/Samples/iOS-SwiftUI/iOS-SwiftUI.xcodeproj/project.pbxproj @@ -26,6 +26,20 @@ remoteGlobalIDString = 7BB6224826A56C4E00D0E75E; remoteInfo = "iOS-SwiftUI"; }; + 7BF01DB528F536BC00302035 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 84D4FEA828ECD52700EDAAFE /* Sentry.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 63AA759B1EB8AEF500D153DE; + remoteInfo = Sentry; + }; + 7BF01DB728F536BC00302035 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 84D4FEA828ECD52700EDAAFE /* Sentry.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 63AA76651EB8CB2F00D153DE; + remoteInfo = SentryTests; + }; 84D4FEAD28ECD52E00EDAAFE /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 84D4FEAA28ECD52E00EDAAFE /* Sentry.xcodeproj */; @@ -163,6 +177,15 @@ name = Frameworks; sourceTree = ""; }; + 7BF01DB128F536BC00302035 /* Products */ = { + isa = PBXGroup; + children = ( + 7BF01DB628F536BC00302035 /* Sentry.framework */, + 7BF01DB828F536BC00302035 /* SentryTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; 84D4FEAB28ECD52E00EDAAFE /* Products */ = { isa = PBXGroup; children = ( @@ -242,6 +265,10 @@ productRefGroup = 7BB6224A26A56C4E00D0E75E /* Products */; projectDirPath = ""; projectReferences = ( + { + ProductGroup = 7BF01DB128F536BC00302035 /* Products */; + ProjectRef = 84D4FEA828ECD52700EDAAFE /* Sentry.xcodeproj */; + }, { ProductGroup = 84D4FEAB28ECD52E00EDAAFE /* Products */; ProjectRef = 84D4FEAA28ECD52E00EDAAFE /* Sentry.xcodeproj */; @@ -256,6 +283,20 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 7BF01DB628F536BC00302035 /* Sentry.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = Sentry.framework; + remoteRef = 7BF01DB528F536BC00302035 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 7BF01DB828F536BC00302035 /* SentryTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SentryTests.xctest; + remoteRef = 7BF01DB728F536BC00302035 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 84D4FEB228ECD52E00EDAAFE /* Sentry.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 67f3c856190..87b24da2c7d 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurement; +@class SentrySpanId, SentryId, SentryTraceHeader, SentryUnit; NS_SWIFT_NAME(Span) @protocol SentrySpan @@ -87,7 +87,9 @@ NS_SWIFT_NAME(Span) */ - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); -- (void)setMeasurement:(SentryMeasurement *)measurement; +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value + unit:(SentryUnit *)unit NS_SWIFT_NAME(setMeasurement(name:value:unit:)); /** * Finishes the span by setting the end time. diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index b30c7e8db01..5fff0d14a0a 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -64,7 +64,7 @@ - (void)removeTagForKey:(NSString *)key { } -- (void)setMeasurement:(SentryMeasurement *)measurement +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit { } diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 11037db7ebe..6db3fc391a4 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -90,8 +90,9 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(SentryMeasurement *)measurement +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit { + [self.tracer setMeasurement:name value:value unit:unit]; } - (NSDictionary *)tags diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 698edc27a39..428e9554077 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -398,8 +398,11 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(SentryMeasurement *)measurement +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit { + SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name + value:value + unit:unit]; [_measurements addObject:measurement]; } diff --git a/Tests/SentryTests/Transaction/TestSentrySpan.m b/Tests/SentryTests/Transaction/TestSentrySpan.m index aeb14e8aeb4..f47aa7abc4f 100644 --- a/Tests/SentryTests/Transaction/TestSentrySpan.m +++ b/Tests/SentryTests/Transaction/TestSentrySpan.m @@ -59,4 +59,8 @@ - (void)setTagValue:(nonnull NSString *)value forKey:(nonnull NSString *)key { } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +{ +} + @end From 93cd097461fc0603e1e90683965d9d37d1a9ec42 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 08:12:06 +0200 Subject: [PATCH 05/17] Add missing units --- .../iOS-Swift/iOS-Swift/ViewController.swift | 2 +- Sources/Sentry/Public/SentryDefines.h | 81 ------------- Sources/Sentry/Public/SentryUnit.h | 68 +++++++++-- Sources/Sentry/SentryUnit.m | 107 +++++++++++++++++- 4 files changed, 166 insertions(+), 92 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index 49bd935f7b0..e4f88e67bf7 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -142,7 +142,7 @@ class ViewController: UIViewController { @IBAction func captureTransaction(_ sender: Any) { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") - transaction.setMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanoseconds) + transaction.setMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanosecond) transaction.setMeasurement(name: "information", value: 44, unit: SentryUnitInformation.bit) transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) diff --git a/Sources/Sentry/Public/SentryDefines.h b/Sources/Sentry/Public/SentryDefines.h index 2012fa3a160..48a7698048e 100644 --- a/Sources/Sentry/Public/SentryDefines.h +++ b/Sources/Sentry/Public/SentryDefines.h @@ -142,84 +142,3 @@ typedef NS_ENUM(NSInteger, SentryTransactionNameSource) { kSentryTransactionNameSourceComponent, kSentryTransactionNameSourceTask }; - -/** - * A time duration. - */ -typedef NS_ENUM(NSInteger, SentryDurationUnit) { - /** Nanosecond (`"nanosecond"`), 10^-9 seconds. */ - kSentryDurationUnitNanoSecond = 0, - /** Microsecond (`"microsecond"`), 10^-6 seconds. */ - kSentryDurationUnitMicroSecond, - /** Millisecond (`"millisecond"`), 10^-3 seconds. */ - kSentryDurationUnitMilliSecond, - /** Full second (`"second"`). */ - kSentryDurationUnitSecond, - /** Minute (`"minute"`), 60 seconds. */ - kSentryDurationUnitMinute, - /** Hour (`"hour"`), 3600 seconds. */ - kSentryDurationUnitHour, - /** Day (`"day"`), 86,400 seconds. */ - kSentryDurationUnitDay, - /** Week (`"week"`), 604,800 seconds. */ - kSentryDurationUnitWeek -} NS_SWIFT_NAME(DurationUnit); - -/** - * Size of information derived from bytes. - */ -typedef NS_ENUM(NSInteger, SentryInformationUnit) { - /** Bit (`"bit"`), corresponding to 1/8 of a byte. */ - kSentryInformationUnitBit, - - /** Byte (`"byte"`). */ - kSentryInformationUnitByte, - - /** Kilobyte (`"kilobyte"`), 10^3 bytes. */ - kSentryInformationUnitKilobyte, - - /** Kibibyte (`"kibibyte"`), 2^10 bytes. */ - kSentryInformationUnitKibibyte, - - /** Megabyte (`"megabyte"`), 10^6 bytes. */ - kSentryInformationUnitMegabyte, - - /** Mebibyte (`"mebibyte"`), 2^20 bytes. */ - kSentryInformationUnitMebibyte, - - /** Gigabyte (`"gigabyte"`), 10^9 bytes. */ - kSentryInformationUnitGigabyte, - - /** Gibibyte (`"gibibyte"`), 2^30 bytes. */ - kSentryInformationUnitGibibyte, - - /** Terabyte (`"terabyte"`), 10^12 bytes. */ - kSentryInformationUnitTerabyte, - - /** Tebibyte (`"tebibyte"`), 2^40 bytes. */ - kSentryInformationUnitTebibyte, - - /** Petabyte (`"petabyte"`), 10^15 bytes. */ - kSentryInformationUnitPetabyte, - - /** Pebibyte (`"pebibyte"`), 2^50 bytes. */ - kSentryInformationUnitPebibyte, - - /** Exabyte (`"exabyte"`), 10^18 bytes. */ - kSentryInformationUnitExabyte, - - /** Exbibyte (`"exbibyte"`), 2^60 bytes. */ - kSentryInformationUnitExbibyte -} NS_SWIFT_NAME(InformationUnit); - -/** - * Fractions such as percentages. - */ -typedef NS_ENUM(NSInteger, SentryFractionUnit) { - - /** Floating point fraction of `1`. */ - kSentryFractionUnitRatio = 0, - - /** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ - kSentryFractionUnitPercent -} NS_SWIFT_NAME(FractionUnit); diff --git a/Sources/Sentry/Public/SentryUnit.h b/Sources/Sentry/Public/SentryUnit.h index 8572a1a219a..6d37f24bcb5 100644 --- a/Sources/Sentry/Public/SentryUnit.h +++ b/Sources/Sentry/Public/SentryUnit.h @@ -14,20 +14,76 @@ SENTRY_NO_INIT @interface SentryUnitDuration : SentryUnit SENTRY_NO_INIT -/** Nanosecond (`"nanosecond"`), 10^-9 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *nanoseconds; +/** Nanosecond, 10^-9 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *nanosecond; -// ... +/** Microsecond , 10^-6 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *microsecond; + +/** Millisecond, 10^-3 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *millisecond; + +/** Full second. */ +@property (class, readonly, copy) SentryUnitDuration *second; + +/** Minute, 60 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *minute; + +/** Hour, 3600 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *hour; + +/** Day, 86,400 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *day; + +/** Week, 604,800 seconds. */ +@property (class, readonly, copy) SentryUnitDuration *week; @end @interface SentryUnitInformation : SentryUnit SENTRY_NO_INIT -/** Bit (`"bit"`), corresponding to 1/8 of a byte. */ +/** Bit, corresponding to 1/8 of a byte. */ @property (class, readonly, copy) SentryUnitInformation *bit; -// ... +/** Byte. */ +@property (class, readonly, copy) SentryUnitInformation *byte; + +/** Kilobyte, 10^3 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *kilobyte; + +/** Kibibyte, 2^10 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *kibibyte; + +/** Megabyte, 10^6 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *megabyte; + +/** Mebibyte, 2^20 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *mebibyte; + +/** Gigabyte, 10^9 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *gigabyte; + +/** Gibibyte, 2^30 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *gibibyte; + +/** Terabyte, 10^12 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *terabyte; + +/** Tebibyte, 2^40 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *tebibyte; + +/** Petabyte, 10^15 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *petabyte; + +/** Pebibyte, 2^50 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *pebibyte; + +/** Exabyte, 10^18 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *exabyte; + +/** Exbibyte, 2^60 bytes. */ +@property (class, readonly, copy) SentryUnitInformation *exbibyte; @end @@ -40,8 +96,6 @@ SENTRY_NO_INIT /** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ @property (class, readonly, copy) SentryUnitFraction *percent; -// ... - @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryUnit.m b/Sources/Sentry/SentryUnit.m index fb13e15b2d3..9ab50fa9c0e 100644 --- a/Sources/Sentry/SentryUnit.m +++ b/Sources/Sentry/SentryUnit.m @@ -21,21 +21,122 @@ - (id)copyWithZone:(nullable NSZone *)zone @implementation SentryUnitDuration -+ (SentryUnitDuration *)nanoseconds ++ (SentryUnitDuration *)nanosecond { return [[SentryUnitDuration alloc] initWithUnit:@"nanoseconds"]; } ++ (SentryUnitDuration *)microsecond +{ + return [[SentryUnitDuration alloc] initWithUnit:@"microsecond"]; +} + ++ (SentryUnitDuration *)millisecond +{ + return [[SentryUnitDuration alloc] initWithUnit:@"millisecond"]; +} + ++ (SentryUnitDuration *)second +{ + return [[SentryUnitDuration alloc] initWithUnit:@"second"]; +} + ++ (SentryUnitDuration *)minute +{ + return [[SentryUnitDuration alloc] initWithUnit:@"minute"]; +} + ++ (SentryUnitDuration *)hour +{ + return [[SentryUnitDuration alloc] initWithUnit:@"hour"]; +} + ++ (SentryUnitDuration *)day +{ + return [[SentryUnitDuration alloc] initWithUnit:@"day"]; +} + ++ (SentryUnitDuration *)week +{ + return [[SentryUnitDuration alloc] initWithUnit:@"week"]; +} + @end @implementation SentryUnitInformation -+ (SentryUnitDuration *)bit ++ (SentryUnitInformation *)bit +{ + return [[SentryUnitInformation alloc] initWithUnit:@"bit"]; +} + ++ (SentryUnitInformation *)byte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"byte"]; +} + ++ (SentryUnitInformation *)kilobyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"kilobyte"]; +} + ++ (SentryUnitInformation *)kibibyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"kibibyte"]; +} + ++ (SentryUnitInformation *)megabyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"megabyte"]; +} + ++ (SentryUnitInformation *)mebibyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"mebibyte"]; +} + ++ (SentryUnitInformation *)gigabyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"gigabyte"]; +} + ++ (SentryUnitInformation *)gibibyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"gibibyte"]; +} + ++ (SentryUnitInformation *)terabyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"terabyte"]; +} + ++ (SentryUnitInformation *)tebibyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"tebibyte"]; +} + ++ (SentryUnitInformation *)petabyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"petabyte"]; +} + ++ (SentryUnitInformation *)pebibyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"pebibyte"]; +} + ++ (SentryUnitInformation *)exabyte +{ + return [[SentryUnitInformation alloc] initWithUnit:@"exabyte"]; +} + ++ (SentryUnitInformation *)exbibyte { - return [[SentryUnitDuration alloc] initWithUnit:@"bit"]; + return [[SentryUnitInformation alloc] initWithUnit:@"exbibyte"]; } @end +; @implementation SentryUnitFraction From 9fc5b73361e89525cccdc7f8334aa1afe852b3b8 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 08:16:51 +0200 Subject: [PATCH 06/17] Rename to SentryMeasurmentUnit --- .../iOS-Swift/iOS-Swift/ViewController.swift | 8 +- Sentry.xcodeproj/project.pbxproj | 16 +- Sources/Sentry/Public/Sentry.h | 2 +- Sources/Sentry/Public/SentryMeasurement.h | 4 +- Sources/Sentry/Public/SentryMeasurementUnit.h | 104 ++++++++++++ Sources/Sentry/Public/SentrySpanProtocol.h | 5 +- Sources/Sentry/Public/SentryUnit.h | 101 ------------ Sources/Sentry/SentryMeasurement.m | 4 +- Sources/Sentry/SentryMeasurementUnit.m | 155 ++++++++++++++++++ Sources/Sentry/SentryNoOpSpan.m | 2 +- Sources/Sentry/SentrySpan.m | 2 +- Sources/Sentry/SentryTracer.m | 2 +- Sources/Sentry/SentryUnit.m | 155 ------------------ .../SentryTests/Transaction/TestSentrySpan.m | 2 +- 14 files changed, 284 insertions(+), 278 deletions(-) create mode 100644 Sources/Sentry/Public/SentryMeasurementUnit.h delete mode 100644 Sources/Sentry/Public/SentryUnit.h create mode 100644 Sources/Sentry/SentryMeasurementUnit.m delete mode 100644 Sources/Sentry/SentryUnit.m diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index e4f88e67bf7..e00f695ae18 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -142,10 +142,10 @@ class ViewController: UIViewController { @IBAction func captureTransaction(_ sender: Any) { let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation") - transaction.setMeasurement(name: "duration", value: 44, unit: SentryUnitDuration.nanosecond) - transaction.setMeasurement(name: "information", value: 44, unit: SentryUnitInformation.bit) - transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) - transaction.setMeasurement(name: "duration-custom", value: 22, unit: SentryUnit(unit: "custom")) + transaction.setMeasurement(name: "duration", value: 44, unit: MeasurementUnitDuration.nanosecond) + transaction.setMeasurement(name: "information", value: 44, unit: MeasurementUnitInformation.bit) + transaction.setMeasurement(name: "duration-custom", value: 22, unit: MeasurementUnit(unit: "custom")) + transaction.setMeasurement(name: "duration-custom", value: 22, unit: MeasurementUnit(unit: "custom")) let span = transaction.startChild(operation: "user", description: "calls out") diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 2d35832bcd6..e803d8e4cbf 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -493,9 +493,9 @@ 7BC852392458830A005A70F0 /* SentryEnvelopeItemType.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC8523B2458849E005A70F0 /* SentryDataCategoryMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */; }; 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7BC9A20228F41350001E7C4C /* SentryUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A20128F41350001E7C4C /* SentryUnit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */; }; - 7BC9A20628F41781001E7C4C /* SentryUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20528F41781001E7C4C /* SentryUnit.m */; }; + 7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */; }; 7BCFA71627D0BB50008C662C /* SentryANRTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BCFA71527D0BB50008C662C /* SentryANRTracker.m */; }; 7BCFBD672681C95000BC27D8 /* SentryScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD662681C95000BC27D8 /* SentryScopeObserver.h */; }; 7BCFBD6D2681D0A900BC27D8 /* SentryCrashScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD6C2681D0A900BC27D8 /* SentryCrashScopeObserver.h */; }; @@ -1229,9 +1229,9 @@ 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeItemType.h; path = Public/SentryEnvelopeItemType.h; sourceTree = ""; }; 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDataCategoryMapperTests.swift; sourceTree = ""; }; 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = Public/SentryMeasurement.h; sourceTree = ""; }; - 7BC9A20128F41350001E7C4C /* SentryUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUnit.h; path = Public/SentryUnit.h; sourceTree = ""; }; + 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementUnit.h; path = Public/SentryMeasurementUnit.h; sourceTree = ""; }; 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurement.m; sourceTree = ""; }; - 7BC9A20528F41781001E7C4C /* SentryUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUnit.m; sourceTree = ""; }; + 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementUnit.m; sourceTree = ""; }; 7BC9CD4326A99F660047518E /* SentryUIViewControllerSwizzling+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryUIViewControllerSwizzling+Test.h"; sourceTree = ""; }; 7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTracker.h; path = include/SentryANRTracker.h; sourceTree = ""; }; 7BCFA71527D0BB50008C662C /* SentryANRTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryANRTracker.m; sourceTree = ""; }; @@ -1622,8 +1622,8 @@ 7BD4BD4827EB2A5D0071F4FF /* SentryDiscardedEvent.m */, 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */, 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */, - 7BC9A20128F41350001E7C4C /* SentryUnit.h */, - 7BC9A20528F41781001E7C4C /* SentryUnit.m */, + 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */, + 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */, ); name = Protocol; sourceTree = ""; @@ -3000,7 +3000,7 @@ 7DC27EC523997EB7006998B5 /* SentryAutoBreadcrumbTrackingIntegration.h in Headers */, 63FE707F20DA4C1000CDBAE8 /* SentryCrashVarArgs.h in Headers */, 03F84D2627DD414C008FE43F /* SentryThreadMetadataCache.hpp in Headers */, - 7BC9A20228F41350001E7C4C /* SentryUnit.h in Headers */, + 7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */, 7BB654FB253DC14A00887E87 /* SentryUserFeedback.h in Headers */, 7B8ECBFA26498907005FE2EF /* SentryAppStateManager.h in Headers */, 639FCFA01EBC804600778193 /* SentryException.h in Headers */, @@ -3445,7 +3445,7 @@ 0356A571288B4612008BF593 /* SentryProfilesSampler.m in Sources */, 63FE710B20DA4C1000CDBAE8 /* SentryCrashMach.c in Sources */, 63FE707720DA4C1000CDBAE8 /* Container+SentryDeepSearch.m in Sources */, - 7BC9A20628F41781001E7C4C /* SentryUnit.m in Sources */, + 7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */, 63FE71A020DA4C1100CDBAE8 /* SentryCrashInstallation.m in Sources */, 63FE713520DA4C1100CDBAE8 /* SentryCrashMemory.c in Sources */, 63FE714520DA4C1100CDBAE8 /* SentryCrashObjC.c in Sources */, diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index 88391a59285..982c4cdf2b4 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -26,6 +26,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryId.h" #import "SentryIntegrationProtocol.h" #import "SentryMeasurement.h" +#import "SentryMeasurementUnit.h" #import "SentryMechanism.h" #import "SentryMechanismMeta.h" #import "SentryMessage.h" @@ -47,6 +48,5 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryThread.h" #import "SentryTraceHeader.h" #import "SentryTransactionContext.h" -#import "SentryUnit.h" #import "SentryUser.h" #import "SentryUserFeedback.h" diff --git a/Sources/Sentry/Public/SentryMeasurement.h b/Sources/Sentry/Public/SentryMeasurement.h index 56a59b262b6..f9e2dcdd3f5 100644 --- a/Sources/Sentry/Public/SentryMeasurement.h +++ b/Sources/Sentry/Public/SentryMeasurement.h @@ -1,10 +1,10 @@ #import "SentryDefines.h" +#import "SentryMeasurementUnit.h" #import "SentrySerializable.h" -#import "SentryUnit.h" NS_ASSUME_NONNULL_BEGIN -@interface SentryMeasurement : NSObject +@interface SentryMeasurement : NSObject SENTRY_NO_INIT - (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(UnitType)unit; diff --git a/Sources/Sentry/Public/SentryMeasurementUnit.h b/Sources/Sentry/Public/SentryMeasurementUnit.h new file mode 100644 index 00000000000..b6d8aa4dcaa --- /dev/null +++ b/Sources/Sentry/Public/SentryMeasurementUnit.h @@ -0,0 +1,104 @@ +#import "SentryDefines.h" + +NS_ASSUME_NONNULL_BEGIN + +NS_SWIFT_NAME(MeasurementUnit) +@interface SentryMeasurementUnit : NSObject +SENTRY_NO_INIT + +- (instancetype)initWithUnit:(NSString *)unit; + +@property (readonly, copy) NSString *unit; + +@end + +NS_SWIFT_NAME(MeasurementUnitDuration) +@interface SentryMeasurementUnitDuration : SentryMeasurementUnit +SENTRY_NO_INIT + +/** Nanosecond, 10^-9 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *nanosecond; + +/** Microsecond , 10^-6 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *microsecond; + +/** Millisecond, 10^-3 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *millisecond; + +/** Full second. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *second; + +/** Minute, 60 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *minute; + +/** Hour, 3600 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *hour; + +/** Day, 86,400 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *day; + +/** Week, 604,800 seconds. */ +@property (class, readonly, copy) SentryMeasurementUnitDuration *week; + +@end + +NS_SWIFT_NAME(MeasurementUnitInformation) +@interface SentryMeasurementUnitInformation : SentryMeasurementUnit +SENTRY_NO_INIT + +/** Bit, corresponding to 1/8 of a byte. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *bit; + +/** Byte. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *byte; + +/** Kilobyte, 10^3 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *kilobyte; + +/** Kibibyte, 2^10 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *kibibyte; + +/** Megabyte, 10^6 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *megabyte; + +/** Mebibyte, 2^20 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *mebibyte; + +/** Gigabyte, 10^9 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *gigabyte; + +/** Gibibyte, 2^30 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *gibibyte; + +/** Terabyte, 10^12 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *terabyte; + +/** Tebibyte, 2^40 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *tebibyte; + +/** Petabyte, 10^15 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *petabyte; + +/** Pebibyte, 2^50 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *pebibyte; + +/** Exabyte, 10^18 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *exabyte; + +/** Exbibyte, 2^60 bytes. */ +@property (class, readonly, copy) SentryMeasurementUnitInformation *exbibyte; + +@end + +@interface SentryUnitFraction : SentryMeasurementUnit +SENTRY_NO_INIT + +/** Floating point fraction of `1`. */ +@property (class, readonly, copy) SentryUnitFraction *ratio; + +/** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ +@property (class, readonly, copy) SentryUnitFraction *percent; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 87b24da2c7d..9a968b6d42c 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentrySpanId, SentryId, SentryTraceHeader, SentryUnit; +@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurementUnit; NS_SWIFT_NAME(Span) @protocol SentrySpan @@ -89,7 +89,8 @@ NS_SWIFT_NAME(Span) - (void)setMeasurement:(NSString *)name value:(NSNumber *)value - unit:(SentryUnit *)unit NS_SWIFT_NAME(setMeasurement(name:value:unit:)); + unit:(SentryMeasurementUnit *)unit + NS_SWIFT_NAME(setMeasurement(name:value:unit:)); /** * Finishes the span by setting the end time. diff --git a/Sources/Sentry/Public/SentryUnit.h b/Sources/Sentry/Public/SentryUnit.h deleted file mode 100644 index 6d37f24bcb5..00000000000 --- a/Sources/Sentry/Public/SentryUnit.h +++ /dev/null @@ -1,101 +0,0 @@ -#import "SentryDefines.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface SentryUnit : NSObject -SENTRY_NO_INIT - -- (instancetype)initWithUnit:(NSString *)unit; - -@property (readonly, copy) NSString *unit; - -@end - -@interface SentryUnitDuration : SentryUnit -SENTRY_NO_INIT - -/** Nanosecond, 10^-9 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *nanosecond; - -/** Microsecond , 10^-6 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *microsecond; - -/** Millisecond, 10^-3 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *millisecond; - -/** Full second. */ -@property (class, readonly, copy) SentryUnitDuration *second; - -/** Minute, 60 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *minute; - -/** Hour, 3600 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *hour; - -/** Day, 86,400 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *day; - -/** Week, 604,800 seconds. */ -@property (class, readonly, copy) SentryUnitDuration *week; - -@end - -@interface SentryUnitInformation : SentryUnit -SENTRY_NO_INIT - -/** Bit, corresponding to 1/8 of a byte. */ -@property (class, readonly, copy) SentryUnitInformation *bit; - -/** Byte. */ -@property (class, readonly, copy) SentryUnitInformation *byte; - -/** Kilobyte, 10^3 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *kilobyte; - -/** Kibibyte, 2^10 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *kibibyte; - -/** Megabyte, 10^6 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *megabyte; - -/** Mebibyte, 2^20 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *mebibyte; - -/** Gigabyte, 10^9 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *gigabyte; - -/** Gibibyte, 2^30 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *gibibyte; - -/** Terabyte, 10^12 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *terabyte; - -/** Tebibyte, 2^40 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *tebibyte; - -/** Petabyte, 10^15 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *petabyte; - -/** Pebibyte, 2^50 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *pebibyte; - -/** Exabyte, 10^18 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *exabyte; - -/** Exbibyte, 2^60 bytes. */ -@property (class, readonly, copy) SentryUnitInformation *exbibyte; - -@end - -@interface SentryUnitFraction : SentryUnit -SENTRY_NO_INIT - -/** Floating point fraction of `1`. */ -@property (class, readonly, copy) SentryUnitFraction *ratio; - -/** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ -@property (class, readonly, copy) SentryUnitFraction *percent; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryMeasurement.m b/Sources/Sentry/SentryMeasurement.m index 39df0631edf..aea96fb6ab1 100644 --- a/Sources/Sentry/SentryMeasurement.m +++ b/Sources/Sentry/SentryMeasurement.m @@ -4,7 +4,9 @@ @implementation SentryMeasurement -- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +- (instancetype)initWithName:(NSString *)name + value:(NSNumber *)value + unit:(SentryMeasurementUnit *)unit { if (self = [super init]) { _name = name; diff --git a/Sources/Sentry/SentryMeasurementUnit.m b/Sources/Sentry/SentryMeasurementUnit.m new file mode 100644 index 00000000000..08369319c17 --- /dev/null +++ b/Sources/Sentry/SentryMeasurementUnit.m @@ -0,0 +1,155 @@ +#import "SentryMeasurementUnit.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SentryMeasurementUnit + +- (instancetype)initWithUnit:(NSString *)unit +{ + if (self = [super init]) { + _unit = unit; + } + return self; +} + +- (id)copyWithZone:(nullable NSZone *)zone +{ + return [[[self class] allocWithZone:zone] initWithSymbol:self.unit]; +} + +@end + +@implementation SentryMeasurementUnitDuration + ++ (SentryMeasurementUnitDuration *)nanosecond +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"nanoseconds"]; +} + ++ (SentryMeasurementUnitDuration *)microsecond +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"microsecond"]; +} + ++ (SentryMeasurementUnitDuration *)millisecond +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"millisecond"]; +} + ++ (SentryMeasurementUnitDuration *)second +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"second"]; +} + ++ (SentryMeasurementUnitDuration *)minute +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"minute"]; +} + ++ (SentryMeasurementUnitDuration *)hour +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"hour"]; +} + ++ (SentryMeasurementUnitDuration *)day +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"day"]; +} + ++ (SentryMeasurementUnitDuration *)week +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"week"]; +} + +@end + +@implementation SentryMeasurementUnitInformation + ++ (SentryMeasurementUnitInformation *)bit +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"bit"]; +} + ++ (SentryMeasurementUnitInformation *)byte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"byte"]; +} + ++ (SentryMeasurementUnitInformation *)kilobyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"kilobyte"]; +} + ++ (SentryMeasurementUnitInformation *)kibibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"kibibyte"]; +} + ++ (SentryMeasurementUnitInformation *)megabyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"megabyte"]; +} + ++ (SentryMeasurementUnitInformation *)mebibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"mebibyte"]; +} + ++ (SentryMeasurementUnitInformation *)gigabyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"gigabyte"]; +} + ++ (SentryMeasurementUnitInformation *)gibibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"gibibyte"]; +} + ++ (SentryMeasurementUnitInformation *)terabyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"terabyte"]; +} + ++ (SentryMeasurementUnitInformation *)tebibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"tebibyte"]; +} + ++ (SentryMeasurementUnitInformation *)petabyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"petabyte"]; +} + ++ (SentryMeasurementUnitInformation *)pebibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"pebibyte"]; +} + ++ (SentryMeasurementUnitInformation *)exabyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"exabyte"]; +} + ++ (SentryMeasurementUnitInformation *)exbibyte +{ + return [[SentryMeasurementUnitInformation alloc] initWithUnit:@"exbibyte"]; +} + +@end +; + +@implementation SentryUnitFraction + ++ (SentryUnitFraction *)ratio +{ + return [[SentryUnitFraction alloc] initWithUnit:@"ratio"]; +} + ++ (SentryUnitFraction *)percent +{ + return [[SentryUnitFraction alloc] initWithUnit:@"percent"]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index 5fff0d14a0a..565330a4154 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -64,7 +64,7 @@ - (void)removeTagForKey:(NSString *)key { } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { } diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 6db3fc391a4..133a1211ab2 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -90,7 +90,7 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { [self.tracer setMeasurement:name value:value unit:unit]; } diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 428e9554077..a4c8c0ef346 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -398,7 +398,7 @@ - (void)removeTagForKey:(NSString *)key } } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name value:value diff --git a/Sources/Sentry/SentryUnit.m b/Sources/Sentry/SentryUnit.m deleted file mode 100644 index 9ab50fa9c0e..00000000000 --- a/Sources/Sentry/SentryUnit.m +++ /dev/null @@ -1,155 +0,0 @@ -#import "SentryUnit.h" - -NS_ASSUME_NONNULL_BEGIN - -@implementation SentryUnit - -- (instancetype)initWithUnit:(NSString *)unit -{ - if (self = [super init]) { - _unit = unit; - } - return self; -} - -- (id)copyWithZone:(nullable NSZone *)zone -{ - return [[[self class] allocWithZone:zone] initWithSymbol:self.unit]; -} - -@end - -@implementation SentryUnitDuration - -+ (SentryUnitDuration *)nanosecond -{ - return [[SentryUnitDuration alloc] initWithUnit:@"nanoseconds"]; -} - -+ (SentryUnitDuration *)microsecond -{ - return [[SentryUnitDuration alloc] initWithUnit:@"microsecond"]; -} - -+ (SentryUnitDuration *)millisecond -{ - return [[SentryUnitDuration alloc] initWithUnit:@"millisecond"]; -} - -+ (SentryUnitDuration *)second -{ - return [[SentryUnitDuration alloc] initWithUnit:@"second"]; -} - -+ (SentryUnitDuration *)minute -{ - return [[SentryUnitDuration alloc] initWithUnit:@"minute"]; -} - -+ (SentryUnitDuration *)hour -{ - return [[SentryUnitDuration alloc] initWithUnit:@"hour"]; -} - -+ (SentryUnitDuration *)day -{ - return [[SentryUnitDuration alloc] initWithUnit:@"day"]; -} - -+ (SentryUnitDuration *)week -{ - return [[SentryUnitDuration alloc] initWithUnit:@"week"]; -} - -@end - -@implementation SentryUnitInformation - -+ (SentryUnitInformation *)bit -{ - return [[SentryUnitInformation alloc] initWithUnit:@"bit"]; -} - -+ (SentryUnitInformation *)byte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"byte"]; -} - -+ (SentryUnitInformation *)kilobyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"kilobyte"]; -} - -+ (SentryUnitInformation *)kibibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"kibibyte"]; -} - -+ (SentryUnitInformation *)megabyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"megabyte"]; -} - -+ (SentryUnitInformation *)mebibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"mebibyte"]; -} - -+ (SentryUnitInformation *)gigabyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"gigabyte"]; -} - -+ (SentryUnitInformation *)gibibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"gibibyte"]; -} - -+ (SentryUnitInformation *)terabyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"terabyte"]; -} - -+ (SentryUnitInformation *)tebibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"tebibyte"]; -} - -+ (SentryUnitInformation *)petabyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"petabyte"]; -} - -+ (SentryUnitInformation *)pebibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"pebibyte"]; -} - -+ (SentryUnitInformation *)exabyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"exabyte"]; -} - -+ (SentryUnitInformation *)exbibyte -{ - return [[SentryUnitInformation alloc] initWithUnit:@"exbibyte"]; -} - -@end -; - -@implementation SentryUnitFraction - -+ (SentryUnitFraction *)ratio -{ - return [[SentryUnitFraction alloc] initWithUnit:@"ratio"]; -} - -+ (SentryUnitFraction *)percent -{ - return [[SentryUnitFraction alloc] initWithUnit:@"percent"]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/Transaction/TestSentrySpan.m b/Tests/SentryTests/Transaction/TestSentrySpan.m index f47aa7abc4f..7b513d8e978 100644 --- a/Tests/SentryTests/Transaction/TestSentrySpan.m +++ b/Tests/SentryTests/Transaction/TestSentrySpan.m @@ -59,7 +59,7 @@ - (void)setTagValue:(nonnull NSString *)value forKey:(nonnull NSString *)key { } -- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryUnit *)unit +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { } From 9a678ff439a450e61b94b32c90b79acd1dffe6d4 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 09:53:57 +0200 Subject: [PATCH 07/17] Refactoring --- Sentry.xcodeproj/project.pbxproj | 12 ++-- Sources/Sentry/Public/Sentry.h | 1 - Sources/Sentry/Public/SentryMeasurementUnit.h | 3 + Sources/Sentry/Public/SentrySpanProtocol.h | 3 + Sources/Sentry/SentryMeasurement.m | 14 +++-- Sources/Sentry/SentryMeasurementUnit.m | 6 +- Sources/Sentry/SentryNoOpSpan.m | 4 ++ Sources/Sentry/SentrySpan.m | 5 ++ Sources/Sentry/SentryTracer.m | 33 +++++------ Sources/Sentry/SentryTransaction.m | 24 +++++--- .../{Public => include}/SentryMeasurement.h | 10 +++- Sources/Sentry/include/SentryTracer.h | 5 +- .../include/SentryTransaction+Private.h | 12 ---- Tests/SentryTests/SentryClientTests.swift | 2 +- .../SentryTests/SentryTests-Bridging-Header.h | 1 - .../Transaction/SentrySpanTests.swift | 4 +- .../Transaction/SentryTransactionTests.swift | 56 +++++++++++++------ .../SentryTests/Transaction/TestSentrySpan.m | 4 ++ 18 files changed, 121 insertions(+), 78 deletions(-) rename Sources/Sentry/{Public => include}/SentryMeasurement.h (55%) delete mode 100644 Sources/Sentry/include/SentryTransaction+Private.h diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index e803d8e4cbf..20fac1fde55 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -354,7 +354,6 @@ 7B6438AB26A70F24000D0F65 /* UIViewController+Sentry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6438A926A70F24000D0F65 /* UIViewController+Sentry.m */; }; 7B68D93625FF5F1A0082D139 /* SentryAppState+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */; }; 7B6ADFCF26A02CAE0076C206 /* SentryCrashReportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6ADFCE26A02CAE0076C206 /* SentryCrashReportTests.swift */; }; - 7B6C5ED2264E5D6C0010D138 /* SentryTransaction+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6C5ED0264E5D6C0010D138 /* SentryTransaction+Private.h */; }; 7B6C5ED6264E62CA0010D138 /* SentryTransactionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */; }; 7B6C5EDA264E8D860010D138 /* SentryFramesTrackingIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */; }; 7B6C5EDC264E8DA80010D138 /* SentryFramesTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */; }; @@ -492,7 +491,7 @@ 7BC8523724588115005A70F0 /* SentryDataCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC8523624588115005A70F0 /* SentryDataCategory.h */; }; 7BC852392458830A005A70F0 /* SentryEnvelopeItemType.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC8523B2458849E005A70F0 /* SentryDataCategoryMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */; }; - 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */; }; 7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */; }; 7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */; }; @@ -1084,7 +1083,6 @@ 7B68D93425FF5F1A0082D139 /* SentryAppState+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryAppState+Equality.h"; sourceTree = ""; }; 7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryAppState+Equality.m"; sourceTree = ""; }; 7B6ADFCE26A02CAE0076C206 /* SentryCrashReportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashReportTests.swift; sourceTree = ""; }; - 7B6C5ED0264E5D6C0010D138 /* SentryTransaction+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryTransaction+Private.h"; path = "include/SentryTransaction+Private.h"; sourceTree = ""; }; 7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionTests.swift; sourceTree = ""; }; 7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryFramesTrackingIntegration.h; path = include/SentryFramesTrackingIntegration.h; sourceTree = ""; }; 7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFramesTrackingIntegration.m; sourceTree = ""; }; @@ -1228,7 +1226,7 @@ 7BC8523624588115005A70F0 /* SentryDataCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDataCategory.h; path = include/SentryDataCategory.h; sourceTree = ""; }; 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeItemType.h; path = Public/SentryEnvelopeItemType.h; sourceTree = ""; }; 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDataCategoryMapperTests.swift; sourceTree = ""; }; - 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = Public/SentryMeasurement.h; sourceTree = ""; }; + 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = include/SentryMeasurement.h; sourceTree = ""; }; 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementUnit.h; path = Public/SentryMeasurementUnit.h; sourceTree = ""; }; 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurement.m; sourceTree = ""; }; 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementUnit.m; sourceTree = ""; }; @@ -1620,8 +1618,6 @@ 7BD4BD4427EB29F50071F4FF /* SentryClientReport.m */, 7BD4BD4627EB2A3D0071F4FF /* SentryDiscardedEvent.h */, 7BD4BD4827EB2A5D0071F4FF /* SentryDiscardedEvent.m */, - 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */, - 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */, 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */, 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */, ); @@ -2765,7 +2761,6 @@ 8ECC674525C23A20000E2BF6 /* SentrySpanId.m */, 8E4E7C6B25DAAAFE006AB9E2 /* SentryTransaction.h */, 8ECC674425C23A1F000E2BF6 /* SentryTransaction.m */, - 7B6C5ED0264E5D6C0010D138 /* SentryTransaction+Private.h */, 8ECC673B25C23996000E2BF6 /* SentryTransactionContext.h */, 8ECC674625C23A20000E2BF6 /* SentryTransactionContext.m */, 0A56DA5E28ABA01B00C400D5 /* SentryTransactionContext+Private.h */, @@ -2785,6 +2780,8 @@ D88817D626D7149100BF2251 /* SentryTraceContext.m */, D8603DD7284F894C000E1227 /* SentryBaggage.h */, D8603DD4284F8497000E1227 /* SentryBaggage.m */, + 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */, + 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */, ); name = Transaction; sourceTree = ""; @@ -3054,7 +3051,6 @@ 8E5D38E3261D4B57000D363D /* SentryPerformanceTrackingIntegration.h in Headers */, 63FE70F920DA4C1000CDBAE8 /* SentryCrashMonitor.h in Headers */, 7B98D7CB25FB64EC00C5A389 /* SentryOutOfMemoryTrackingIntegration.h in Headers */, - 7B6C5ED2264E5D6C0010D138 /* SentryTransaction+Private.h in Headers */, 63FE710920DA4C1000CDBAE8 /* SentryCrashFileUtils.h in Headers */, 03F84D1F27DD414C008FE43F /* SentryAsyncSafeLogging.h in Headers */, 7BE3C76B2445C27A00A38442 /* SentryCurrentDateProvider.h in Headers */, diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index 982c4cdf2b4..01784d2553b 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -25,7 +25,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryHub.h" #import "SentryId.h" #import "SentryIntegrationProtocol.h" -#import "SentryMeasurement.h" #import "SentryMeasurementUnit.h" #import "SentryMechanism.h" #import "SentryMechanismMeta.h" diff --git a/Sources/Sentry/Public/SentryMeasurementUnit.h b/Sources/Sentry/Public/SentryMeasurementUnit.h index b6d8aa4dcaa..6956a18ae33 100644 --- a/Sources/Sentry/Public/SentryMeasurementUnit.h +++ b/Sources/Sentry/Public/SentryMeasurementUnit.h @@ -10,6 +10,9 @@ SENTRY_NO_INIT @property (readonly, copy) NSString *unit; +/** Untyped value without a unit. */ +@property (class, readonly, copy) SentryMeasurementUnit *none; + @end NS_SWIFT_NAME(MeasurementUnitDuration) diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 9a968b6d42c..629f9c3d3ee 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -87,6 +87,9 @@ NS_SWIFT_NAME(Span) */ - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); +- (void)setMeasurement:(NSString *)name + value:(NSNumber *)value NS_SWIFT_NAME(setMeasurement(name:value:)); + - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit diff --git a/Sources/Sentry/SentryMeasurement.m b/Sources/Sentry/SentryMeasurement.m index aea96fb6ab1..7474a90b646 100644 --- a/Sources/Sentry/SentryMeasurement.m +++ b/Sources/Sentry/SentryMeasurement.m @@ -4,6 +4,15 @@ @implementation SentryMeasurement +- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value +{ + if (self = [super init]) { + _name = name; + _value = value; + } + return self; +} + - (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit @@ -16,11 +25,6 @@ - (instancetype)initWithName:(NSString *)name return self; } -- (NSDictionary *)serialize -{ - return @{ @"name" : self.name, @"value" : self.value, @"unit" : self.unit.unit }; -} - @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryMeasurementUnit.m b/Sources/Sentry/SentryMeasurementUnit.m index 08369319c17..fa6884eeebf 100644 --- a/Sources/Sentry/SentryMeasurementUnit.m +++ b/Sources/Sentry/SentryMeasurementUnit.m @@ -12,6 +12,11 @@ - (instancetype)initWithUnit:(NSString *)unit return self; } ++ (SentryMeasurementUnit *)none +{ + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@""]; +} + - (id)copyWithZone:(nullable NSZone *)zone { return [[[self class] allocWithZone:zone] initWithSymbol:self.unit]; @@ -136,7 +141,6 @@ + (SentryMeasurementUnitInformation *)exbibyte } @end -; @implementation SentryUnitFraction diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index 565330a4154..e62d67a54c9 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -64,6 +64,10 @@ - (void)removeTagForKey:(NSString *)key { } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ +} + - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { } diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 133a1211ab2..d9aaf93cca6 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -90,6 +90,11 @@ - (void)removeTagForKey:(NSString *)key } } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ + [self.tracer setMeasurement:name value:value]; +} + - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { [self.tracer setMeasurement:name value:value unit:unit]; diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index a4c8c0ef346..166d8b6359e 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -17,7 +17,6 @@ #import "SentrySpanContext.h" #import "SentrySpanId.h" #import "SentryTraceContext.h" -#import "SentryTransaction+Private.h" #import "SentryTransaction.h" #import "SentryTransactionContext.h" #import "SentryUIViewControllerPerformanceTracker.h" @@ -62,7 +61,7 @@ @implementation SentryTracer { SentryAppStartMeasurement *appStartMeasurement; NSMutableDictionary *_tags; NSMutableDictionary *_data; - NSMutableArray *_measurements; + NSMutableDictionary *_measurements; dispatch_block_t _idleTimeoutBlock; NSMutableArray> *_children; @@ -162,7 +161,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti _waitForChildren = waitForChildren; _tags = [[NSMutableDictionary alloc] init]; _data = [[NSMutableDictionary alloc] init]; - _measurements = [[NSMutableArray alloc] init]; + _measurements = [[NSMutableDictionary alloc] init]; self.finishStatus = kSentrySpanStatusUndefined; self.idleTimeout = idleTimeout; self.dispatchQueueWrapper = dispatchQueueWrapper; @@ -398,12 +397,18 @@ - (void)removeTagForKey:(NSString *)key } } +- (void)setMeasurement:(NSString *)name value:(NSNumber *)value +{ + SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name value:value]; + _measurements[name] = measurement; +} + - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name value:value unit:unit]; - [_measurements addObject:measurement]; + _measurements[name] = measurement; } - (SentryTraceHeader *)toTraceHeader @@ -698,8 +703,6 @@ - (nullable SentryAppStartMeasurement *)getAppStartMeasurement - (void)addMeasurements:(SentryTransaction *)transaction { - NSString *valueKey = @"value"; - if (appStartMeasurement != nil && appStartMeasurement.type != SentryAppStartTypeUnknown) { NSString *type = nil; if (appStartMeasurement.type == SentryAppStartTypeCold) { @@ -709,8 +712,9 @@ - (void)addMeasurements:(SentryTransaction *)transaction } if (type != nil) { - [transaction setMeasurementValue:@{ valueKey : @(appStartMeasurement.duration * 1000) } - forKey:type]; + [self setMeasurement:type + value:@(appStartMeasurement.duration * 1000) + unit:SentryMeasurementUnitDuration.millisecond]; } } @@ -728,22 +732,15 @@ - (void)addMeasurements:(SentryTransaction *)transaction BOOL oneBiggerThanZero = totalFrames > 0 || slowFrames > 0 || frozenFrames > 0; if (allBiggerThanZero && oneBiggerThanZero) { - [transaction setMeasurementValue:@{ valueKey : @(totalFrames) } forKey:@"frames_total"]; - [transaction setMeasurementValue:@{ valueKey : @(slowFrames) } forKey:@"frames_slow"]; - [transaction setMeasurementValue:@{ valueKey : @(frozenFrames) } - forKey:@"frames_frozen"]; + [self setMeasurement:@"frames_total" value:@(totalFrames)]; + [self setMeasurement:@"frames_slow" value:@(slowFrames)]; + [self setMeasurement:@"frames_frozen" value:@(frozenFrames)]; SENTRY_LOG_DEBUG(@"Frames for transaction \"%@\" Total:%ld Slow:%ld Frozen:%ld", self.context.operation, (long)totalFrames, (long)slowFrames, (long)frozenFrames); } } #endif - - for (SentryMeasurement *measurement in _measurements) { - [transaction - setMeasurementValue:@{ @"value" : measurement.value, @"unit" : measurement.unit.unit } - forKey:measurement.name]; - } } - (id)buildSpan:(SentrySpanId *)parentId diff --git a/Sources/Sentry/SentryTransaction.m b/Sources/Sentry/SentryTransaction.m index a90f3935042..0092ed2e9f2 100644 --- a/Sources/Sentry/SentryTransaction.m +++ b/Sources/Sentry/SentryTransaction.m @@ -1,6 +1,7 @@ #import "SentryTransaction.h" #import "NSDictionary+SentrySanitize.h" #import "SentryEnvelopeItemType.h" +#import "SentryMeasurement.h" #import "SentryTransactionContext.h" NS_ASSUME_NONNULL_BEGIN @@ -9,7 +10,6 @@ SentryTransaction () @property (nonatomic, strong) NSArray> *spans; -@property (nonatomic, strong) NSMutableDictionary *measurements; @end @@ -23,16 +23,10 @@ - (instancetype)initWithTrace:(SentryTracer *)trace children:(NSArray *)serialize { NSMutableDictionary *serializedData = @@ -80,8 +74,20 @@ - (void)setMeasurementValue:(id)value forKey:(NSString *)key serializedData[@"extra"] = traceData; } - if (self.measurements.count > 0) { - serializedData[@"measurements"] = [self.measurements.copy sentry_sanitize]; + if (self.trace.measurements.count > 0) { + NSMutableDictionary *measurements = [NSMutableDictionary dictionary]; + for (SentryMeasurement *measurement in self.trace.measurements.allValues) { + NSDictionary *value; + if (measurement.unit != nil) { + value = @{ @"value" : measurement.value, @"unit" : measurement.unit.unit }; + } else { + value = @{ @"value" : measurement.value }; + } + + measurements[measurement.name] = value; + } + + serializedData[@"measurements"] = measurements; } if (self.trace) { diff --git a/Sources/Sentry/Public/SentryMeasurement.h b/Sources/Sentry/include/SentryMeasurement.h similarity index 55% rename from Sources/Sentry/Public/SentryMeasurement.h rename to Sources/Sentry/include/SentryMeasurement.h index f9e2dcdd3f5..84651ea61d2 100644 --- a/Sources/Sentry/Public/SentryMeasurement.h +++ b/Sources/Sentry/include/SentryMeasurement.h @@ -4,14 +4,18 @@ NS_ASSUME_NONNULL_BEGIN -@interface SentryMeasurement : NSObject +@interface SentryMeasurement : NSObject SENTRY_NO_INIT -- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value unit:(UnitType)unit; +- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value; + +- (instancetype)initWithName:(NSString *)name + value:(NSNumber *)value + unit:(SentryMeasurementUnit *)unit; @property (nonatomic, copy, readonly) NSString *name; @property (nonatomic, copy, readonly) NSNumber *value; -@property (readonly, copy) UnitType unit; +@property (nullable, readonly, copy) SentryMeasurementUnit *unit; @end diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 2881ace6d50..9888fe3fe14 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN @class SentryHub, SentryTransactionContext, SentryTraceHeader, SentryTraceContext, - SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision; + SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision, SentryMeasurement; static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; @@ -19,6 +19,7 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; @end @interface SentryTracer : NSObject +SENTRY_NO_INIT @property (nonatomic, strong) SentryTransactionContext *transactionContext; @@ -76,6 +77,8 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; */ @property (nullable, nonatomic, weak) id delegate; +@property (nonatomic, readonly) NSDictionary *measurements; + /** * Init a SentryTracer with given transaction context and hub and set other fields by default * diff --git a/Sources/Sentry/include/SentryTransaction+Private.h b/Sources/Sentry/include/SentryTransaction+Private.h deleted file mode 100644 index 9d9f38ff096..00000000000 --- a/Sources/Sentry/include/SentryTransaction+Private.h +++ /dev/null @@ -1,12 +0,0 @@ -#import "SentryTransaction.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface -SentryTransaction (Private) - -- (void)setMeasurementValue:(id)value forKey:(NSString *)key; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index 8f169d9a579..a179a5d7ef3 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -1209,7 +1209,7 @@ class SentryClientTest: XCTestCase { let event = Event(level: SentryLevel.warning) event.message = fixture.message let scope = Scope() - scope.span = SentryTracer() + scope.span = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) let client = fixture.getSut() client.capture(event: event, scope: scope) diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index 9a335992fc6..4ad7b2c913a 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -149,7 +149,6 @@ #import "SentryTraceContext.h" #import "SentryTracer+Test.h" #import "SentryTracer.h" -#import "SentryTransaction+Private.h" #import "SentryTransaction.h" #import "SentryTransactionContext+Private.h" #import "SentryTransport.h" diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index ed0b0ce1ab3..cc88efa43e4 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -13,7 +13,7 @@ class SentrySpanTests: XCTestCase { let extraValue = "extra_value" let options: Options let currentDateProvider = TestCurrentDateProvider() - let tracer = SentryTracer() + let tracer = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) init() { options = Options() @@ -316,7 +316,7 @@ class SentrySpanTests: XCTestCase { // Span has a weak reference to tracer. If we don't keep a reference // to the tracer ARC will deallocate the tracer. let sutGenerator: () -> Span = { - let tracer = SentryTracer() + let tracer = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) return SentrySpan(tracer: tracer, context: SpanContext(operation: "")) } diff --git a/Tests/SentryTests/Transaction/SentryTransactionTests.swift b/Tests/SentryTests/Transaction/SentryTransactionTests.swift index 61747cfa02c..8b220469337 100644 --- a/Tests/SentryTests/Transaction/SentryTransactionTests.swift +++ b/Tests/SentryTests/Transaction/SentryTransactionTests.swift @@ -8,8 +8,8 @@ class SentryTransactionTests: XCTestCase { let testKey = "extra_key" let testValue = "extra_value" - func getTransaction() -> Transaction { - return Transaction(trace: SentryTracer(), children: []) + func getTransaction(trace: SentryTracer = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil))) -> Transaction { + return Transaction(trace: trace, children: []) } func getContext() -> TransactionContext { @@ -51,26 +51,50 @@ class SentryTransactionTests: XCTestCase { XCTAssertNil(actual["measurements"]) } - func testSerializeMeasurements_Measurements() { - let transaction = fixture.getTransaction() - - let appStart = ["value": 15_000.0] - transaction.setMeasurementValue(appStart, forKey: "app_start_cold") + func testSerializeMeasurements_AppStartMeasurement() { + let name = "app_start_cold" + let value: NSNumber = 15_000.0 + let unit = MeasurementUnitDuration.millisecond + + let trace = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) + trace.setMeasurement(name: name, value: value, unit: unit) + let transaction = fixture.getTransaction(trace: trace) + let actual = transaction.serialize() - let actualMeasurements = actual["measurements"] as? [String: [String: Double]] - XCTAssertEqual(appStart, actualMeasurements?["app_start_cold"] ) + let actualMeasurements = actual["measurements"] as? [String: [String: Any]] + XCTAssertNotNil(actualMeasurements) + + let coldStartMeasurement = actualMeasurements?[name] as? [String: Any] + XCTAssertEqual(value, coldStartMeasurement?["value"] as! NSNumber) + XCTAssertEqual(unit.unit, coldStartMeasurement?["unit"] as! String) } - - func testSerializeMeasurements_GarbageInMeasurements_GarbageSanitized() { - let transaction = fixture.getTransaction() + + func testSerializeMeasurements_MultipleMeasurements() { + let frameName = "frames_total" + let frameValue: NSNumber = 60 + + let customName = "custom-name" + let customValue: NSNumber = 20.1 + let customUnit = MeasurementUnit(unit: "custom") + + let trace = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) + trace.setMeasurement(name: frameName, value: frameValue) + trace.setMeasurement(name: customName, value: customValue, unit: customUnit) + let transaction = fixture.getTransaction(trace: trace) - let appStart = ["value": self] - transaction.setMeasurementValue(appStart, forKey: "app_start_cold") let actual = transaction.serialize() - let actualMeasurements = actual["measurements"] as? [String: [String: String]] - XCTAssertEqual(["value": self.description], actualMeasurements?["app_start_cold"] ) + let actualMeasurements = actual["measurements"] as? [String: [String: Any]] + XCTAssertNotNil(actualMeasurements) + + let frameMeasurement = actualMeasurements?[frameName] as? [String: Any] + XCTAssertEqual(frameValue, frameMeasurement?["value"] as! NSNumber) + XCTAssertNil(frameMeasurement?["unit"]) + + let customMeasurement = actualMeasurements?[customName] as? [String: Any] + XCTAssertEqual(customValue, customMeasurement?["value"] as! NSNumber) + XCTAssertEqual(customUnit.unit, customMeasurement?["unit"] as! String) } func testSerialize_Tags() { diff --git a/Tests/SentryTests/Transaction/TestSentrySpan.m b/Tests/SentryTests/Transaction/TestSentrySpan.m index 7b513d8e978..21ad154bd5f 100644 --- a/Tests/SentryTests/Transaction/TestSentrySpan.m +++ b/Tests/SentryTests/Transaction/TestSentrySpan.m @@ -59,6 +59,10 @@ - (void)setTagValue:(nonnull NSString *)value forKey:(nonnull NSString *)key { } +- (void)setMeasurement:(nonnull NSString *)name value:(nonnull NSNumber *)value +{ +} + - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { } From 0f7a782e19be9face7c5406928ff69f7078d34aa Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 10:06:32 +0200 Subject: [PATCH 08/17] Rename SentryMeasurement to SentryMeasurementValue --- Sentry.xcodeproj/project.pbxproj | 16 ++++----- Sources/Sentry/Public/SentryOptions.h | 4 +-- Sources/Sentry/SentryMeasurement.m | 30 ---------------- Sources/Sentry/SentryMeasurementValue.m | 36 +++++++++++++++++++ Sources/Sentry/SentryOptions.m | 2 +- Sources/Sentry/SentrySpan.m | 2 +- Sources/Sentry/SentryTracer.m | 11 +++--- Sources/Sentry/SentryTransaction.m | 14 +++----- Sources/Sentry/include/SentryMeasurement.h | 22 ------------ .../Sentry/include/SentryMeasurementValue.h | 19 ++++++++++ Sources/Sentry/include/SentryTracer.h | 4 +-- 11 files changed, 78 insertions(+), 82 deletions(-) delete mode 100644 Sources/Sentry/SentryMeasurement.m create mode 100644 Sources/Sentry/SentryMeasurementValue.m delete mode 100644 Sources/Sentry/include/SentryMeasurement.h create mode 100644 Sources/Sentry/include/SentryMeasurementValue.h diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 20fac1fde55..874db95f92e 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -491,9 +491,9 @@ 7BC8523724588115005A70F0 /* SentryDataCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC8523624588115005A70F0 /* SentryDataCategory.h */; }; 7BC852392458830A005A70F0 /* SentryEnvelopeItemType.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7BC8523B2458849E005A70F0 /* SentryDataCategoryMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */; }; - 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */; }; + 7BC9A20028F41016001E7C4C /* SentryMeasurementValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A1FF28F41016001E7C4C /* SentryMeasurementValue.h */; }; 7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */; }; + 7BC9A20428F4166D001E7C4C /* SentryMeasurementValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20328F4166D001E7C4C /* SentryMeasurementValue.m */; }; 7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */; }; 7BCFA71627D0BB50008C662C /* SentryANRTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BCFA71527D0BB50008C662C /* SentryANRTracker.m */; }; 7BCFBD672681C95000BC27D8 /* SentryScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD662681C95000BC27D8 /* SentryScopeObserver.h */; }; @@ -1226,9 +1226,9 @@ 7BC8523624588115005A70F0 /* SentryDataCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDataCategory.h; path = include/SentryDataCategory.h; sourceTree = ""; }; 7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeItemType.h; path = Public/SentryEnvelopeItemType.h; sourceTree = ""; }; 7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDataCategoryMapperTests.swift; sourceTree = ""; }; - 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = include/SentryMeasurement.h; sourceTree = ""; }; + 7BC9A1FF28F41016001E7C4C /* SentryMeasurementValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementValue.h; path = include/SentryMeasurementValue.h; sourceTree = ""; }; 7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementUnit.h; path = Public/SentryMeasurementUnit.h; sourceTree = ""; }; - 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurement.m; sourceTree = ""; }; + 7BC9A20328F4166D001E7C4C /* SentryMeasurementValue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementValue.m; sourceTree = ""; }; 7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementUnit.m; sourceTree = ""; }; 7BC9CD4326A99F660047518E /* SentryUIViewControllerSwizzling+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryUIViewControllerSwizzling+Test.h"; sourceTree = ""; }; 7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTracker.h; path = include/SentryANRTracker.h; sourceTree = ""; }; @@ -2780,8 +2780,8 @@ D88817D626D7149100BF2251 /* SentryTraceContext.m */, D8603DD7284F894C000E1227 /* SentryBaggage.h */, D8603DD4284F8497000E1227 /* SentryBaggage.m */, - 7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */, - 7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */, + 7BC9A1FF28F41016001E7C4C /* SentryMeasurementValue.h */, + 7BC9A20328F4166D001E7C4C /* SentryMeasurementValue.m */, ); name = Transaction; sourceTree = ""; @@ -2904,7 +2904,7 @@ 0A2D8DA8289BC905008720F6 /* SentryViewHierarchy.h in Headers */, 8EAE980C261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h in Headers */, 63FE717D20DA4C1100CDBAE8 /* SentryCrashCachedData.h in Headers */, - 7BC9A20028F41016001E7C4C /* SentryMeasurement.h in Headers */, + 7BC9A20028F41016001E7C4C /* SentryMeasurementValue.h in Headers */, 7BBC826D25DFCFDE005F1ED8 /* SentryInAppLogic.h in Headers */, 03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */, 7B0A54222521C21E00A71716 /* SentryFrameRemover.h in Headers */, @@ -3424,7 +3424,7 @@ 8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */, D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */, 8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */, - 7BC9A20428F4166D001E7C4C /* SentryMeasurement.m in Sources */, + 7BC9A20428F4166D001E7C4C /* SentryMeasurementValue.m in Sources */, D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */, 7BD86EC7264A641D005439DB /* SentrySysctl.m in Sources */, D859697327BECDD20036A46E /* SentryCoreDataSwizzling.m in Sources */, diff --git a/Sources/Sentry/Public/SentryOptions.h b/Sources/Sentry/Public/SentryOptions.h index 109478fafa7..82f8db84537 100644 --- a/Sources/Sentry/Public/SentryOptions.h +++ b/Sources/Sentry/Public/SentryOptions.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentryDsn, SentrySdkInfo, SentryMeasurement; +@class SentryDsn, SentrySdkInfo, SentryMeasurementValue; NS_SWIFT_NAME(Options) @interface SentryOptions : NSObject @@ -196,7 +196,7 @@ NS_SWIFT_NAME(Options) */ @property (nonatomic, assign) BOOL enableAutoPerformanceTracking; -- (void)setMeasurement:(SentryMeasurement *)measurement; +- (void)setMeasurement:(SentryMeasurementValue *)measurement; #if SENTRY_HAS_UIKIT /** diff --git a/Sources/Sentry/SentryMeasurement.m b/Sources/Sentry/SentryMeasurement.m deleted file mode 100644 index 7474a90b646..00000000000 --- a/Sources/Sentry/SentryMeasurement.m +++ /dev/null @@ -1,30 +0,0 @@ -#import "SentryMeasurement.h" - -NS_ASSUME_NONNULL_BEGIN - -@implementation SentryMeasurement - -- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value -{ - if (self = [super init]) { - _name = name; - _value = value; - } - return self; -} - -- (instancetype)initWithName:(NSString *)name - value:(NSNumber *)value - unit:(SentryMeasurementUnit *)unit -{ - if (self = [super init]) { - _name = name; - _value = value; - _unit = unit; - } - return self; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryMeasurementValue.m b/Sources/Sentry/SentryMeasurementValue.m new file mode 100644 index 00000000000..6099ede4ac5 --- /dev/null +++ b/Sources/Sentry/SentryMeasurementValue.m @@ -0,0 +1,36 @@ +#import "SentryMeasurementValue.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SentryMeasurementValue + +- (instancetype)initWithValue:(NSNumber *)value +{ + if (self = [super init]) { + _value = value; + } + return self; +} + +- (instancetype)initWithValue:(NSNumber *)value unit:(SentryMeasurementUnit *)unit +{ + if (self = [super init]) { + _value = value; + _unit = unit; + } + return self; +} + +- (NSDictionary *)serialize +{ + + if (self.unit != nil) { + return @{ @"value" : _value, @"unit" : _unit.unit }; + } else { + return @{ @"value" : _value }; + } +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryOptions.m b/Sources/Sentry/SentryOptions.m index 02fac2d4729..8f9bc0b5036 100644 --- a/Sources/Sentry/SentryOptions.m +++ b/Sources/Sentry/SentryOptions.m @@ -20,7 +20,7 @@ @implementation SentryOptions -- (void)setMeasurement:(SentryMeasurement *)measurement +- (void)setMeasurement:(SentryMeasurementValue *)measurement { } diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index d9aaf93cca6..d0a0b656269 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -3,7 +3,7 @@ #import "NSDictionary+SentrySanitize.h" #import "SentryCurrentDate.h" #import "SentryLog.h" -#import "SentryMeasurement.h" +#import "SentryMeasurementValue.h" #import "SentryNoOpSpan.h" #import "SentryTraceHeader.h" #import "SentryTracer.h" diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 166d8b6359e..b91acf3a87f 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -21,7 +21,7 @@ #import "SentryTransactionContext.h" #import "SentryUIViewControllerPerformanceTracker.h" #import -#import +#import #import #import @@ -61,7 +61,7 @@ @implementation SentryTracer { SentryAppStartMeasurement *appStartMeasurement; NSMutableDictionary *_tags; NSMutableDictionary *_data; - NSMutableDictionary *_measurements; + NSMutableDictionary *_measurements; dispatch_block_t _idleTimeoutBlock; NSMutableArray> *_children; @@ -399,15 +399,14 @@ - (void)removeTagForKey:(NSString *)key - (void)setMeasurement:(NSString *)name value:(NSNumber *)value { - SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name value:value]; + SentryMeasurementValue *measurement = [[SentryMeasurementValue alloc] initWithValue:value]; _measurements[name] = measurement; } - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit { - SentryMeasurement *measurement = [[SentryMeasurement alloc] initWithName:name - value:value - unit:unit]; + SentryMeasurementValue *measurement = [[SentryMeasurementValue alloc] initWithValue:value + unit:unit]; _measurements[name] = measurement; } diff --git a/Sources/Sentry/SentryTransaction.m b/Sources/Sentry/SentryTransaction.m index 0092ed2e9f2..a9efc76bf7c 100644 --- a/Sources/Sentry/SentryTransaction.m +++ b/Sources/Sentry/SentryTransaction.m @@ -1,7 +1,7 @@ #import "SentryTransaction.h" #import "NSDictionary+SentrySanitize.h" #import "SentryEnvelopeItemType.h" -#import "SentryMeasurement.h" +#import "SentryMeasurementValue.h" #import "SentryTransactionContext.h" NS_ASSUME_NONNULL_BEGIN @@ -76,15 +76,9 @@ - (instancetype)initWithTrace:(SentryTracer *)trace children:(NSArray 0) { NSMutableDictionary *measurements = [NSMutableDictionary dictionary]; - for (SentryMeasurement *measurement in self.trace.measurements.allValues) { - NSDictionary *value; - if (measurement.unit != nil) { - value = @{ @"value" : measurement.value, @"unit" : measurement.unit.unit }; - } else { - value = @{ @"value" : measurement.value }; - } - - measurements[measurement.name] = value; + + for (NSString *measurementName in self.trace.measurements.allKeys) { + measurements[measurementName] = [self.trace.measurements[measurementName] serialize]; } serializedData[@"measurements"] = measurements; diff --git a/Sources/Sentry/include/SentryMeasurement.h b/Sources/Sentry/include/SentryMeasurement.h deleted file mode 100644 index 84651ea61d2..00000000000 --- a/Sources/Sentry/include/SentryMeasurement.h +++ /dev/null @@ -1,22 +0,0 @@ -#import "SentryDefines.h" -#import "SentryMeasurementUnit.h" -#import "SentrySerializable.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface SentryMeasurement : NSObject -SENTRY_NO_INIT - -- (instancetype)initWithName:(NSString *)name value:(NSNumber *)value; - -- (instancetype)initWithName:(NSString *)name - value:(NSNumber *)value - unit:(SentryMeasurementUnit *)unit; - -@property (nonatomic, copy, readonly) NSString *name; -@property (nonatomic, copy, readonly) NSNumber *value; -@property (nullable, readonly, copy) SentryMeasurementUnit *unit; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryMeasurementValue.h b/Sources/Sentry/include/SentryMeasurementValue.h new file mode 100644 index 00000000000..ec8a61bd275 --- /dev/null +++ b/Sources/Sentry/include/SentryMeasurementValue.h @@ -0,0 +1,19 @@ +#import "SentryDefines.h" +#import "SentryMeasurementUnit.h" +#import "SentrySerializable.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SentryMeasurementValue : NSObject +SENTRY_NO_INIT + +- (instancetype)initWithValue:(NSNumber *)value; + +- (instancetype)initWithValue:(NSNumber *)value unit:(SentryMeasurementUnit *)unit; + +@property (nonatomic, copy, readonly) NSNumber *value; +@property (nullable, readonly, copy) SentryMeasurementUnit *unit; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 9888fe3fe14..c502c51c250 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN @class SentryHub, SentryTransactionContext, SentryTraceHeader, SentryTraceContext, - SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision, SentryMeasurement; + SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision, SentryMeasurementValue; static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; @@ -77,7 +77,7 @@ SENTRY_NO_INIT */ @property (nullable, nonatomic, weak) id delegate; -@property (nonatomic, readonly) NSDictionary *measurements; +@property (nonatomic, readonly) NSDictionary *measurements; /** * Init a SentryTracer with given transaction context and hub and set other fields by default From 3b4ba4ea8c0b4e81e96401c422dc3ceeb1cfd6e8 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 10:32:31 +0200 Subject: [PATCH 09/17] Add TracerTests --- Sources/Sentry/Public/SentryMeasurementUnit.h | 7 +++--- Sources/Sentry/SentryMeasurementUnit.m | 10 ++++---- Sources/Sentry/SentryTracer.m | 4 +-- .../Performance/SentryTracerTests.swift | 25 +++++++++++++++++++ .../Transaction/SentryTransactionTests.swift | 4 +-- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Sources/Sentry/Public/SentryMeasurementUnit.h b/Sources/Sentry/Public/SentryMeasurementUnit.h index 6956a18ae33..bf878a10aa8 100644 --- a/Sources/Sentry/Public/SentryMeasurementUnit.h +++ b/Sources/Sentry/Public/SentryMeasurementUnit.h @@ -93,14 +93,15 @@ SENTRY_NO_INIT @end -@interface SentryUnitFraction : SentryMeasurementUnit +NS_SWIFT_NAME(MeasurementUnitFraction) +@interface SentryMeasurementUnitFraction : SentryMeasurementUnit SENTRY_NO_INIT /** Floating point fraction of `1`. */ -@property (class, readonly, copy) SentryUnitFraction *ratio; +@property (class, readonly, copy) SentryMeasurementUnitFraction *ratio; /** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */ -@property (class, readonly, copy) SentryUnitFraction *percent; +@property (class, readonly, copy) SentryMeasurementUnitFraction *percent; @end diff --git a/Sources/Sentry/SentryMeasurementUnit.m b/Sources/Sentry/SentryMeasurementUnit.m index fa6884eeebf..645a3929300 100644 --- a/Sources/Sentry/SentryMeasurementUnit.m +++ b/Sources/Sentry/SentryMeasurementUnit.m @@ -142,16 +142,16 @@ + (SentryMeasurementUnitInformation *)exbibyte @end -@implementation SentryUnitFraction +@implementation SentryMeasurementUnitFraction -+ (SentryUnitFraction *)ratio ++ (SentryMeasurementUnitFraction *)ratio { - return [[SentryUnitFraction alloc] initWithUnit:@"ratio"]; + return [[SentryMeasurementUnitFraction alloc] initWithUnit:@"ratio"]; } -+ (SentryUnitFraction *)percent ++ (SentryMeasurementUnitFraction *)percent { - return [[SentryUnitFraction alloc] initWithUnit:@"percent"]; + return [[SentryMeasurementUnitFraction alloc] initWithUnit:@"percent"]; } @end diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index b91acf3a87f..6e999e97e4a 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -711,9 +711,7 @@ - (void)addMeasurements:(SentryTransaction *)transaction } if (type != nil) { - [self setMeasurement:type - value:@(appStartMeasurement.duration * 1000) - unit:SentryMeasurementUnitDuration.millisecond]; + [self setMeasurement:type value:@(appStartMeasurement.duration * 1000)]; } } diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index c42763268ff..0517cd0d4a0 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -546,6 +546,31 @@ class SentryTracerTests: XCTestCase { assertAppStartMeasurementNotPutOnTransaction() } + func testMeasurementOnChildSpan_SetTwice_OverwritesMeasurement() { + let name = "something" + let value: NSNumber = -12.34 + let unit = MeasurementUnitFraction.percent + + let sut = fixture.getSut() + let childSpan = sut.startChild(operation: "operation") + sut.setMeasurement(name: name, value: 12.0, unit: unit) + childSpan.setMeasurement(name: name, value: value, unit: unit) + childSpan.finish() + sut.finish() + fixture.hub.group.wait() + + XCTAssertEqual(1, fixture.hub.capturedEventsWithScopes.count) + let serializedTransaction = fixture.hub.capturedEventsWithScopes.first?.event.serialize() + + let measurements = serializedTransaction?["measurements"] as? [String: [String: Any]] + XCTAssertEqual(1, measurements?.count) + + let measurement = measurements?[name] as? [String: Any] + XCTAssertNotNil(measurement) + XCTAssertEqual(value, measurement?["value"] as! NSNumber) + XCTAssertEqual(unit.unit, measurement?["unit"] as! String) + } + func testFinish_WithUnfinishedChildren() { CurrentDate.setCurrentDateProvider(DefaultCurrentDateProvider.sharedInstance()) let sut = fixture.getSut(waitForChildren: false) diff --git a/Tests/SentryTests/Transaction/SentryTransactionTests.swift b/Tests/SentryTests/Transaction/SentryTransactionTests.swift index 8b220469337..54d78581ea0 100644 --- a/Tests/SentryTests/Transaction/SentryTransactionTests.swift +++ b/Tests/SentryTests/Transaction/SentryTransactionTests.swift @@ -51,8 +51,8 @@ class SentryTransactionTests: XCTestCase { XCTAssertNil(actual["measurements"]) } - func testSerializeMeasurements_AppStartMeasurement() { - let name = "app_start_cold" + func testSerializeMeasurements_DurationMeasurement() { + let name = "some_duration" let value: NSNumber = 15_000.0 let unit = MeasurementUnitDuration.millisecond From 98964e0179b8ff7a6fbe74916859901e492a82f1 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 10:35:44 +0200 Subject: [PATCH 10/17] Changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e2ec4d81c..ef172d39110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Custom measurements API (#2268) + ## 7.27.1 ### Fixes From 98992d9598769065ff73d7abe92c1b8daf8ad118 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 10:54:40 +0200 Subject: [PATCH 11/17] Undo SENTRY_NO_INIT for SentryTracer fix this in another PR --- Samples/iOS-Swift/iOS-Swift/ViewController.swift | 1 - Sources/Sentry/Public/SentrySpanProtocol.h | 3 +++ Sources/Sentry/include/SentryTracer.h | 1 - Tests/SentryTests/SentryClientTests.swift | 2 +- Tests/SentryTests/Transaction/SentrySpanTests.swift | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewController.swift index e00f695ae18..d3e87f34d99 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewController.swift @@ -145,7 +145,6 @@ class ViewController: UIViewController { transaction.setMeasurement(name: "duration", value: 44, unit: MeasurementUnitDuration.nanosecond) transaction.setMeasurement(name: "information", value: 44, unit: MeasurementUnitInformation.bit) transaction.setMeasurement(name: "duration-custom", value: 22, unit: MeasurementUnit(unit: "custom")) - transaction.setMeasurement(name: "duration-custom", value: 22, unit: MeasurementUnit(unit: "custom")) let span = transaction.startChild(operation: "user", description: "calls out") diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 629f9c3d3ee..53596099af3 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -87,6 +87,9 @@ NS_SWIFT_NAME(Span) */ - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); +/** + * + */ - (void)setMeasurement:(NSString *)name value:(NSNumber *)value NS_SWIFT_NAME(setMeasurement(name:value:)); diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index c502c51c250..c6dc2b7e110 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -19,7 +19,6 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; @end @interface SentryTracer : NSObject -SENTRY_NO_INIT @property (nonatomic, strong) SentryTransactionContext *transactionContext; diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index a179a5d7ef3..8f169d9a579 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -1209,7 +1209,7 @@ class SentryClientTest: XCTestCase { let event = Event(level: SentryLevel.warning) event.message = fixture.message let scope = Scope() - scope.span = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) + scope.span = SentryTracer() let client = fixture.getSut() client.capture(event: event, scope: scope) diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index cc88efa43e4..ed0b0ce1ab3 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -13,7 +13,7 @@ class SentrySpanTests: XCTestCase { let extraValue = "extra_value" let options: Options let currentDateProvider = TestCurrentDateProvider() - let tracer = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) + let tracer = SentryTracer() init() { options = Options() @@ -316,7 +316,7 @@ class SentrySpanTests: XCTestCase { // Span has a weak reference to tracer. If we don't keep a reference // to the tracer ARC will deallocate the tracer. let sutGenerator: () -> Span = { - let tracer = SentryTracer(transactionContext: TransactionContext(operation: "operation"), hub: TestHub(client: nil, andScope: nil)) + let tracer = SentryTracer() return SentrySpan(tracer: tracer, context: SpanContext(operation: "")) } From 9175ae1cd1b8d09e33358d26093316aecb6fd09a Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 11:02:40 +0200 Subject: [PATCH 12/17] Add code docs --- Sources/Sentry/Public/SentrySpanProtocol.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 53596099af3..ce206fe8778 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -88,11 +88,29 @@ NS_SWIFT_NAME(Span) - (void)removeTagForKey:(NSString *)key NS_SWIFT_NAME(removeTag(key:)); /** + * Set a measurement without unit. When setting the measurement without the unit, no formatting + * will be applied to the measurement value in the Sentry product, and the value will be shown as + * is. * + * @discussion Setting a measurement with the same name on the same transaction multiple times only + * keeps the last value. + * + * @param name the name of the measurement + * @param value the value of the measurement */ - (void)setMeasurement:(NSString *)name value:(NSNumber *)value NS_SWIFT_NAME(setMeasurement(name:value:)); +/** + * Set a measurement with specific unit. + * + * @discussion Setting a measurement with the same name on the same transaction multiple times only + * keeps the last value. + * + * @param name the name of the measurement + * @param value the value of the measurement + * @param unit the unit the value is measured in + */ - (void)setMeasurement:(NSString *)name value:(NSNumber *)value unit:(SentryMeasurementUnit *)unit From d857a63683c4fde43a204eb1cb7bac839f1c2f6e Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 11:17:12 +0200 Subject: [PATCH 13/17] Remove not needed casting --- Tests/SentryTests/Transaction/SentryTransactionTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/SentryTests/Transaction/SentryTransactionTests.swift b/Tests/SentryTests/Transaction/SentryTransactionTests.swift index 54d78581ea0..f6bd6da0ae1 100644 --- a/Tests/SentryTests/Transaction/SentryTransactionTests.swift +++ b/Tests/SentryTests/Transaction/SentryTransactionTests.swift @@ -65,7 +65,7 @@ class SentryTransactionTests: XCTestCase { let actualMeasurements = actual["measurements"] as? [String: [String: Any]] XCTAssertNotNil(actualMeasurements) - let coldStartMeasurement = actualMeasurements?[name] as? [String: Any] + let coldStartMeasurement = actualMeasurements?[name] XCTAssertEqual(value, coldStartMeasurement?["value"] as! NSNumber) XCTAssertEqual(unit.unit, coldStartMeasurement?["unit"] as! String) } @@ -88,11 +88,11 @@ class SentryTransactionTests: XCTestCase { let actualMeasurements = actual["measurements"] as? [String: [String: Any]] XCTAssertNotNil(actualMeasurements) - let frameMeasurement = actualMeasurements?[frameName] as? [String: Any] + let frameMeasurement = actualMeasurements?[frameName] XCTAssertEqual(frameValue, frameMeasurement?["value"] as! NSNumber) XCTAssertNil(frameMeasurement?["unit"]) - let customMeasurement = actualMeasurements?[customName] as? [String: Any] + let customMeasurement = actualMeasurements?[customName] XCTAssertEqual(customValue, customMeasurement?["value"] as! NSNumber) XCTAssertEqual(customUnit.unit, customMeasurement?["unit"] as! String) } From b98b249e721fe43c99b49db2d28fa72f7e6041bd Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 11 Oct 2022 11:18:16 +0200 Subject: [PATCH 14/17] One more --- Tests/SentryTests/Performance/SentryTracerTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 0517cd0d4a0..24f681a9ac8 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -565,7 +565,7 @@ class SentryTracerTests: XCTestCase { let measurements = serializedTransaction?["measurements"] as? [String: [String: Any]] XCTAssertEqual(1, measurements?.count) - let measurement = measurements?[name] as? [String: Any] + let measurement = measurements?[name] XCTAssertNotNil(measurement) XCTAssertEqual(value, measurement?["value"] as! NSNumber) XCTAssertEqual(unit.unit, measurement?["unit"] as! String) From 6eceb6923dac34fed50f0cea2b7483c8e54c94d1 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 12 Oct 2022 08:53:46 +0200 Subject: [PATCH 15/17] Remove setMeasurements from SentryOptions --- Sources/Sentry/Public/SentryOptions.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/Sentry/Public/SentryOptions.h b/Sources/Sentry/Public/SentryOptions.h index 82f8db84537..0bdd4c97741 100644 --- a/Sources/Sentry/Public/SentryOptions.h +++ b/Sources/Sentry/Public/SentryOptions.h @@ -196,8 +196,6 @@ NS_SWIFT_NAME(Options) */ @property (nonatomic, assign) BOOL enableAutoPerformanceTracking; -- (void)setMeasurement:(SentryMeasurementValue *)measurement; - #if SENTRY_HAS_UIKIT /** * When enabled, the SDK tracks performance for UIViewController subclasses. The default is From c47880724e3ea624aa41b2400919f6cd5c29841b Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 13 Oct 2022 08:58:19 +0200 Subject: [PATCH 16/17] Add tests and docs for measurement unit --- Sentry.xcodeproj/project.pbxproj | 4 ++ Sources/Sentry/Public/SentryMeasurementUnit.h | 30 +++++++++ Sources/Sentry/SentryMeasurementUnit.m | 4 +- .../Protocol/SentryMeasurementUnitTests.swift | 62 +++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 Tests/SentryTests/Protocol/SentryMeasurementUnitTests.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 874db95f92e..499d6ae9ebc 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -352,6 +352,7 @@ 7B6438A726A70DDB000D0F65 /* UIViewControllerSentryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6438A626A70DDB000D0F65 /* UIViewControllerSentryTests.swift */; }; 7B6438AA26A70F24000D0F65 /* UIViewController+Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6438A826A70F24000D0F65 /* UIViewController+Sentry.h */; }; 7B6438AB26A70F24000D0F65 /* UIViewController+Sentry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6438A926A70F24000D0F65 /* UIViewController+Sentry.m */; }; + 7B68345128F7EB3D00FB7064 /* SentryMeasurementUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B68345028F7EB3D00FB7064 /* SentryMeasurementUnitTests.swift */; }; 7B68D93625FF5F1A0082D139 /* SentryAppState+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */; }; 7B6ADFCF26A02CAE0076C206 /* SentryCrashReportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6ADFCE26A02CAE0076C206 /* SentryCrashReportTests.swift */; }; 7B6C5ED6264E62CA0010D138 /* SentryTransactionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */; }; @@ -1080,6 +1081,7 @@ 7B6438A626A70DDB000D0F65 /* UIViewControllerSentryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIViewControllerSentryTests.swift; path = Tests/SentryTests/Categories/UIViewControllerSentryTests.swift; sourceTree = SOURCE_ROOT; }; 7B6438A826A70F24000D0F65 /* UIViewController+Sentry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIViewController+Sentry.h"; path = "include/UIViewController+Sentry.h"; sourceTree = ""; }; 7B6438A926A70F24000D0F65 /* UIViewController+Sentry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Sentry.m"; sourceTree = ""; }; + 7B68345028F7EB3D00FB7064 /* SentryMeasurementUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMeasurementUnitTests.swift; sourceTree = ""; }; 7B68D93425FF5F1A0082D139 /* SentryAppState+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryAppState+Equality.h"; sourceTree = ""; }; 7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryAppState+Equality.m"; sourceTree = ""; }; 7B6ADFCE26A02CAE0076C206 /* SentryCrashReportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashReportTests.swift; sourceTree = ""; }; @@ -2249,6 +2251,7 @@ 7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */, 7BD4BD4A27EB2DC20071F4FF /* SentryDiscardedEventTests.swift */, 7BD4BD4C27EB31820071F4FF /* SentryClientReportTests.swift */, + 7B68345028F7EB3D00FB7064 /* SentryMeasurementUnitTests.swift */, ); path = Protocol; sourceTree = ""; @@ -3474,6 +3477,7 @@ 7B5AB65D27E48E5200F1D1BA /* TestThreadInspector.swift in Sources */, 7BF9EF742722A85B00B5BBEF /* SentryClassRegistrator.m in Sources */, 63B819141EC352A7002FDF4C /* SentryInterfacesTests.m in Sources */, + 7B68345128F7EB3D00FB7064 /* SentryMeasurementUnitTests.swift in Sources */, 7B14089A248791660035403D /* SentryCrashStackEntryMapperTests.swift in Sources */, 7B869EBC249B91D8004F4FDB /* SentryDebugMetaEquality.swift in Sources */, 7B01CE3D271993AC00B5AF31 /* SentryTransportFactoryTests.swift in Sources */, diff --git a/Sources/Sentry/Public/SentryMeasurementUnit.h b/Sources/Sentry/Public/SentryMeasurementUnit.h index bf878a10aa8..e7a5b3462af 100644 --- a/Sources/Sentry/Public/SentryMeasurementUnit.h +++ b/Sources/Sentry/Public/SentryMeasurementUnit.h @@ -2,12 +2,31 @@ NS_ASSUME_NONNULL_BEGIN +/** + * The unit of measurement of a metric value. + * + * Units augment metric values by giving them a magnitude and semantics. There are certain types + * of units that are subdivided in their precision, such as the ``SentryMeasurementUnitDuration`` + * for time measurements. The following unit types are available: ``SentryMeasurementUnitDuration``, + * ``SentryMeasurementUnitInformation``, and``SentryMeasurementUnitFraction``. + * + * When using the units to custom measurements, Sentry will apply formatting to display + * measurement values in the UI. + */ NS_SWIFT_NAME(MeasurementUnit) @interface SentryMeasurementUnit : NSObject SENTRY_NO_INIT +/** + * Returns an initialized SentryMeasurementUnit with a custom measurement unit. + * + * @param unit Your own custom unit without built-in conversion in Sentry. + */ - (instancetype)initWithUnit:(NSString *)unit; +/** + * The NSString representation of the measurement unit. + */ @property (readonly, copy) NSString *unit; /** Untyped value without a unit. */ @@ -15,6 +34,9 @@ SENTRY_NO_INIT @end +/** + * Time duration units. + */ NS_SWIFT_NAME(MeasurementUnitDuration) @interface SentryMeasurementUnitDuration : SentryMeasurementUnit SENTRY_NO_INIT @@ -45,6 +67,11 @@ SENTRY_NO_INIT @end +/** + * Size of information units derived from bytes. + * + * See also [Units of information](https://en.wikipedia.org/wiki/Units_of_information) + */ NS_SWIFT_NAME(MeasurementUnitInformation) @interface SentryMeasurementUnitInformation : SentryMeasurementUnit SENTRY_NO_INIT @@ -93,6 +120,9 @@ SENTRY_NO_INIT @end +/** + * Units of fraction. + */ NS_SWIFT_NAME(MeasurementUnitFraction) @interface SentryMeasurementUnitFraction : SentryMeasurementUnit SENTRY_NO_INIT diff --git a/Sources/Sentry/SentryMeasurementUnit.m b/Sources/Sentry/SentryMeasurementUnit.m index 645a3929300..f9174857b4a 100644 --- a/Sources/Sentry/SentryMeasurementUnit.m +++ b/Sources/Sentry/SentryMeasurementUnit.m @@ -19,7 +19,7 @@ + (SentryMeasurementUnit *)none - (id)copyWithZone:(nullable NSZone *)zone { - return [[[self class] allocWithZone:zone] initWithSymbol:self.unit]; + return [[[self class] allocWithZone:zone] initWithUnit:self.unit]; } @end @@ -28,7 +28,7 @@ @implementation SentryMeasurementUnitDuration + (SentryMeasurementUnitDuration *)nanosecond { - return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"nanoseconds"]; + return [[SentryMeasurementUnitDuration alloc] initWithUnit:@"nanosecond"]; } + (SentryMeasurementUnitDuration *)microsecond diff --git a/Tests/SentryTests/Protocol/SentryMeasurementUnitTests.swift b/Tests/SentryTests/Protocol/SentryMeasurementUnitTests.swift new file mode 100644 index 00000000000..874ddf07ac7 --- /dev/null +++ b/Tests/SentryTests/Protocol/SentryMeasurementUnitTests.swift @@ -0,0 +1,62 @@ +import XCTest + +final class SentryMeasurementUnitTests: XCTestCase { + + func testCustomUnit() { + let unit = "custom" + let sut = MeasurementUnit(unit: unit) + + XCTAssertEqual(unit, sut.unit) + } + + func testUnitNone() { + XCTAssertEqual("", MeasurementUnit.none.unit) + } + + func testCopy() { + let unit = "custom" + let sut = MeasurementUnit(unit: unit).copy() as! MeasurementUnit + + XCTAssertEqual(unit, sut.unit) + } + + func testCopyOfSubclass() { + let unit = "custom" + let sut = MeasurementUnitDuration(unit: unit).copy() as! MeasurementUnitDuration + + XCTAssertEqual(unit, sut.unit) + } + + func testMeasurementUnitDuration() { + XCTAssertEqual("nanosecond", MeasurementUnitDuration.nanosecond.unit) + XCTAssertEqual("microsecond", MeasurementUnitDuration.microsecond.unit) + XCTAssertEqual("millisecond", MeasurementUnitDuration.millisecond.unit) + XCTAssertEqual("second", MeasurementUnitDuration.second.unit) + XCTAssertEqual("minute", MeasurementUnitDuration.minute.unit) + XCTAssertEqual("hour", MeasurementUnitDuration.hour.unit) + XCTAssertEqual("day", MeasurementUnitDuration.day.unit) + XCTAssertEqual("week", MeasurementUnitDuration.week.unit) + } + + func testMeasurementUnitInformation() { + XCTAssertEqual("bit", MeasurementUnitInformation.bit.unit) + XCTAssertEqual("byte", MeasurementUnitInformation.byte.unit) + XCTAssertEqual("kilobyte", MeasurementUnitInformation.kilobyte.unit) + XCTAssertEqual("kibibyte", MeasurementUnitInformation.kibibyte.unit) + XCTAssertEqual("megabyte", MeasurementUnitInformation.megabyte.unit) + XCTAssertEqual("mebibyte", MeasurementUnitInformation.mebibyte.unit) + XCTAssertEqual("gigabyte", MeasurementUnitInformation.gigabyte.unit) + XCTAssertEqual("gibibyte", MeasurementUnitInformation.gibibyte.unit) + XCTAssertEqual("terabyte", MeasurementUnitInformation.terabyte.unit) + XCTAssertEqual("tebibyte", MeasurementUnitInformation.tebibyte.unit) + XCTAssertEqual("petabyte", MeasurementUnitInformation.petabyte.unit) + XCTAssertEqual("pebibyte", MeasurementUnitInformation.pebibyte.unit) + XCTAssertEqual("exabyte", MeasurementUnitInformation.exabyte.unit) + XCTAssertEqual("exbibyte", MeasurementUnitInformation.exbibyte.unit) + } + + func testMeasurementUnitFraction() { + XCTAssertEqual("ratio", MeasurementUnitFraction.ratio.unit) + XCTAssertEqual("percent", MeasurementUnitFraction.percent.unit) + } +} From 1ac57ea443227021d3157ade06a764b7ac9da94a Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 13 Oct 2022 09:08:34 +0200 Subject: [PATCH 17/17] Add link to docs in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef172d39110..ecb1cfa779e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Features -- Custom measurements API (#2268) +- [Custom measurements API](https://docs.sentry.io/platforms/apple/performance/instrumentation/custom-instrumentation/) (#2268) ## 7.27.1