Skip to content

Commit

Permalink
Make API similar to NSMEasurement
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Oct 10, 2022
1 parent febcbbb commit 4ae6b3f
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 175 deletions.
7 changes: 2 additions & 5 deletions Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
16 changes: 16 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1224,6 +1228,10 @@
7BC8523624588115005A70F0 /* SentryDataCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDataCategory.h; path = include/SentryDataCategory.h; sourceTree = "<group>"; };
7BC852382458830A005A70F0 /* SentryEnvelopeItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeItemType.h; path = Public/SentryEnvelopeItemType.h; sourceTree = "<group>"; };
7BC8523A2458849E005A70F0 /* SentryDataCategoryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDataCategoryMapperTests.swift; sourceTree = "<group>"; };
7BC9A1FF28F41016001E7C4C /* SentryMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurement.h; path = Public/SentryMeasurement.h; sourceTree = "<group>"; };
7BC9A20128F41350001E7C4C /* SentryUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUnit.h; path = Public/SentryUnit.h; sourceTree = "<group>"; };
7BC9A20328F4166D001E7C4C /* SentryMeasurement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurement.m; sourceTree = "<group>"; };
7BC9A20528F41781001E7C4C /* SentryUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUnit.m; sourceTree = "<group>"; };
7BC9CD4326A99F660047518E /* SentryUIViewControllerSwizzling+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryUIViewControllerSwizzling+Test.h"; sourceTree = "<group>"; };
7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTracker.h; path = include/SentryANRTracker.h; sourceTree = "<group>"; };
7BCFA71527D0BB50008C662C /* SentryANRTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryANRTracker.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sentry/Public/Sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
18 changes: 18 additions & 0 deletions Sources/Sentry/Public/SentryMeasurement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import "SentryDefines.h"
#import "SentrySerializable.h"
#import "SentryUnit.h"

NS_ASSUME_NONNULL_BEGIN

@interface SentryMeasurement<UnitType : SentryUnit *> : NSObject <SentrySerializable>
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
4 changes: 3 additions & 1 deletion Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN

@class SentryDsn, SentrySdkInfo;
@class SentryDsn, SentrySdkInfo, SentryMeasurement;

NS_SWIFT_NAME(Options)
@interface SentryOptions : NSObject
Expand Down Expand Up @@ -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
Expand Down
24 changes: 2 additions & 22 deletions Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NS_ASSUME_NONNULL_BEGIN

@class SentrySpanId, SentryId, SentryTraceHeader;
@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurement;

NS_SWIFT_NAME(Span)
@protocol SentrySpan <SentrySerializable>
Expand Down Expand Up @@ -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.
Expand Down
47 changes: 47 additions & 0 deletions Sources/Sentry/Public/SentryUnit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#import "SentryDefines.h"

NS_ASSUME_NONNULL_BEGIN

@interface SentryUnit : NSObject <NSCopying>
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
24 changes: 24 additions & 0 deletions Sources/Sentry/SentryMeasurement.m
Original file line number Diff line number Diff line change
@@ -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<NSString *, id> *)serialize
{
return @{ @"name" : self.name, @"value" : self.value, @"unit" : self.unit.symbol };
}

@end

NS_ASSUME_NONNULL_END
24 changes: 1 addition & 23 deletions Sources/Sentry/SentryNoOpSpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

@implementation SentryOptions

- (void)setMeasurement:(SentryMeasurement *)measurement
{
}

+ (NSArray<NSString *> *)defaultIntegrations
{
return @[
Expand Down
25 changes: 2 additions & 23 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
{
}

Expand Down
Loading

0 comments on commit 4ae6b3f

Please sign in to comment.