Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom measurements API #2268

Merged
merged 18 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Custom measurements API (#2268)

## 7.27.1

### Fixes
Expand Down
5 changes: 5 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ 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: MeasurementUnitDuration.nanosecond)
transaction.setMeasurement(name: "information", value: 44, unit: MeasurementUnitInformation.bit)
transaction.setMeasurement(name: "duration-custom", value: 22, unit: MeasurementUnit(unit: "custom"))

let span = transaction.startChild(operation: "user", description: "calls out")

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
Expand Down
41 changes: 41 additions & 0 deletions Samples/iOS-SwiftUI/iOS-SwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
Expand Down Expand Up @@ -163,6 +177,15 @@
name = Frameworks;
sourceTree = "<group>";
};
7BF01DB128F536BC00302035 /* Products */ = {
isa = PBXGroup;
children = (
7BF01DB628F536BC00302035 /* Sentry.framework */,
7BF01DB828F536BC00302035 /* SentryTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
84D4FEAB28ECD52E00EDAAFE /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -242,6 +265,10 @@
productRefGroup = 7BB6224A26A56C4E00D0E75E /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 7BF01DB128F536BC00302035 /* Products */;
ProjectRef = 84D4FEA828ECD52700EDAAFE /* Sentry.xcodeproj */;
},
{
ProductGroup = 84D4FEAB28ECD52E00EDAAFE /* Products */;
ProjectRef = 84D4FEAA28ECD52E00EDAAFE /* Sentry.xcodeproj */;
Expand All @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -492,6 +491,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 /* 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 /* 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 */; };
7BCFBD6D2681D0A900BC27D8 /* SentryCrashScopeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFBD6C2681D0A900BC27D8 /* SentryCrashScopeObserver.h */; };
Expand Down Expand Up @@ -1080,7 +1083,6 @@
7B68D93425FF5F1A0082D139 /* SentryAppState+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryAppState+Equality.h"; sourceTree = "<group>"; };
7B68D93525FF5F1A0082D139 /* SentryAppState+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryAppState+Equality.m"; sourceTree = "<group>"; };
7B6ADFCE26A02CAE0076C206 /* SentryCrashReportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashReportTests.swift; sourceTree = "<group>"; };
7B6C5ED0264E5D6C0010D138 /* SentryTransaction+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryTransaction+Private.h"; path = "include/SentryTransaction+Private.h"; sourceTree = "<group>"; };
7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionTests.swift; sourceTree = "<group>"; };
7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryFramesTrackingIntegration.h; path = include/SentryFramesTrackingIntegration.h; sourceTree = "<group>"; };
7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFramesTrackingIntegration.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1224,6 +1226,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 /* SentryMeasurementValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementValue.h; path = include/SentryMeasurementValue.h; sourceTree = "<group>"; };
7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMeasurementUnit.h; path = Public/SentryMeasurementUnit.h; sourceTree = "<group>"; };
7BC9A20328F4166D001E7C4C /* SentryMeasurementValue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementValue.m; sourceTree = "<group>"; };
7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMeasurementUnit.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 +1618,8 @@
7BD4BD4427EB29F50071F4FF /* SentryClientReport.m */,
7BD4BD4627EB2A3D0071F4FF /* SentryDiscardedEvent.h */,
7BD4BD4827EB2A5D0071F4FF /* SentryDiscardedEvent.m */,
7BC9A20128F41350001E7C4C /* SentryMeasurementUnit.h */,
7BC9A20528F41781001E7C4C /* SentryMeasurementUnit.m */,
);
name = Protocol;
sourceTree = "<group>";
Expand Down Expand Up @@ -2753,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 */,
Expand All @@ -2773,6 +2780,8 @@
D88817D626D7149100BF2251 /* SentryTraceContext.m */,
D8603DD7284F894C000E1227 /* SentryBaggage.h */,
D8603DD4284F8497000E1227 /* SentryBaggage.m */,
7BC9A1FF28F41016001E7C4C /* SentryMeasurementValue.h */,
7BC9A20328F4166D001E7C4C /* SentryMeasurementValue.m */,
);
name = Transaction;
sourceTree = "<group>";
Expand Down Expand Up @@ -2895,6 +2904,7 @@
0A2D8DA8289BC905008720F6 /* SentryViewHierarchy.h in Headers */,
8EAE980C261E9F530073B6B3 /* SentryUIViewControllerPerformanceTracker.h in Headers */,
63FE717D20DA4C1100CDBAE8 /* SentryCrashCachedData.h in Headers */,
7BC9A20028F41016001E7C4C /* SentryMeasurementValue.h in Headers */,
7BBC826D25DFCFDE005F1ED8 /* SentryInAppLogic.h in Headers */,
03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */,
7B0A54222521C21E00A71716 /* SentryFrameRemover.h in Headers */,
Expand Down Expand Up @@ -2987,6 +2997,7 @@
7DC27EC523997EB7006998B5 /* SentryAutoBreadcrumbTrackingIntegration.h in Headers */,
63FE707F20DA4C1000CDBAE8 /* SentryCrashVarArgs.h in Headers */,
03F84D2627DD414C008FE43F /* SentryThreadMetadataCache.hpp in Headers */,
7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */,
7BB654FB253DC14A00887E87 /* SentryUserFeedback.h in Headers */,
7B8ECBFA26498907005FE2EF /* SentryAppStateManager.h in Headers */,
639FCFA01EBC804600778193 /* SentryException.h in Headers */,
Expand Down Expand Up @@ -3040,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 */,
Expand Down Expand Up @@ -3414,6 +3424,7 @@
8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */,
D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */,
8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */,
7BC9A20428F4166D001E7C4C /* SentryMeasurementValue.m in Sources */,
D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */,
7BD86EC7264A641D005439DB /* SentrySysctl.m in Sources */,
D859697327BECDD20036A46E /* SentryCoreDataSwizzling.m in Sources */,
Expand All @@ -3430,6 +3441,7 @@
0356A571288B4612008BF593 /* SentryProfilesSampler.m in Sources */,
63FE710B20DA4C1000CDBAE8 /* SentryCrashMach.c in Sources */,
63FE707720DA4C1000CDBAE8 /* Container+SentryDeepSearch.m in Sources */,
7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */,
63FE71A020DA4C1100CDBAE8 /* SentryCrashInstallation.m in Sources */,
63FE713520DA4C1100CDBAE8 /* SentryCrashMemory.c in Sources */,
63FE714520DA4C1100CDBAE8 /* SentryCrashObjC.c in Sources */,
Expand Down
1 change: 1 addition & 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 "SentryMeasurementUnit.h"
#import "SentryMechanism.h"
#import "SentryMechanismMeta.h"
#import "SentryMessage.h"
Expand Down
108 changes: 108 additions & 0 deletions Sources/Sentry/Public/SentryMeasurementUnit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#import "SentryDefines.h"

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(MeasurementUnit)
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved
@interface SentryMeasurementUnit : NSObject <NSCopying>
Copy link
Member

Choose a reason for hiding this comment

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

Some explanatory headerdoc would be helpful for these class definitions.

SENTRY_NO_INIT

- (instancetype)initWithUnit:(NSString *)unit;
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

@property (readonly, copy) NSString *unit;

/** Untyped value without a unit. */
@property (class, readonly, copy) SentryMeasurementUnit *none;

@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
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved
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

NS_SWIFT_NAME(MeasurementUnitFraction)
@interface SentryMeasurementUnitFraction : SentryMeasurementUnit
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved
SENTRY_NO_INIT

/** Floating point fraction of `1`. */
@property (class, readonly, copy) SentryMeasurementUnitFraction *ratio;

/** Ratio expressed as a fraction of `100`. `100%` equals a ratio of `1.0`. */
@property (class, readonly, copy) SentryMeasurementUnitFraction *percent;

@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, SentryMeasurementValue;

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:(SentryMeasurementValue *)measurement;
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

#if SENTRY_HAS_UIKIT
/**
* When enabled, the SDK tracks performance for UIViewController subclasses. The default is
Expand Down
31 changes: 30 additions & 1 deletion 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, SentryMeasurementUnit;

NS_SWIFT_NAME(Span)
@protocol SentrySpan <SentrySerializable>
Expand Down Expand Up @@ -87,6 +87,35 @@ 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
Copy link
Member

Choose a reason for hiding this comment

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

Should we add some comments briefly explaining which units can be used with which overload or do we expect people to simply drill down on the enum they can pass?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will add comments for sure. Thanks for pointing that out.

Copy link
Contributor

@marandaneto marandaneto Oct 7, 2022

Choose a reason for hiding this comment

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

So apparently ObjC has the same issues as Dart, on Dart, we've used a single enum for now (with all the units), and will refactor later once we are able to upgrade to the latest version.
Here we have an overload per unit type, not sure if it's good or bad, maybe just a method that takes a String would be enough.
Dart does not have overloads, so I could not do this either.
Maybe drop a message to folks that were part of the setMeasurement API and see if they are fine with that due to the restrictions of the language?

The trade-off here is:
Exposing many public APIs, maybe more in the future, so it's overwhelming for the user.

Or a single setMeasurement method that takes a unit of the type String which is open and users would need to learn all the unit types thru the docs.
@sl0thentr0py and @jan-auer specifically were driver and approver.

Copy link
Member

Choose a reason for hiding this comment

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

we said we wouldn't validate sdk side, so it's just a string in most sdks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, but the implementation should be UX friendly, at least for strongly typed languages, an enum would be ideal, but one can set a string as well.
On java one can do:

transaction.setMeasurement("metric1", 2, MeasurementUnit.Duration.DAY)
transaction.setMeasurement("metric1", 2, MeasurementUnit.Custom("myOwnUnit"))

Copy link
Member

Choose a reason for hiding this comment

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

yea that's fine, i think i added type hints to python as well

Copy link
Member

Choose a reason for hiding this comment

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

sry forgot to follow up earlier, was on phone.
I have these type hints in python
https://github.com/getsentry/sentry-python/blob/f71a8f45e780525e52fa5868f45bb876dcf0994b/sentry_sdk/_types.py#L53-L82

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
NS_SWIFT_NAME(setMeasurement(name:value:unit:));
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

/**
* Finishes the span by setting the end time.
*/
Expand Down
Loading