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

Add mutators to Span Options for cleaner API usage #161

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

## TBD

### Breaking changes

The following changes need attention when updating to this version of the library:

* Replaced the constructor of BugsnagPerformanceSpanOptions with chained setters
[161](https://github.com/bugsnag/bugsnag-cocoa-performance/pull/161)

## 0.5.0 (2023-05-31)

### Breaking changes
Expand Down
72 changes: 59 additions & 13 deletions Sources/BugsnagPerformance/Public/BugsnagPerformanceSpanOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
#import <BugsnagPerformance/BugsnagPerformanceSpan.h>
#import <BugsnagPerformance/BugsnagPerformanceSpanOptions.h>

@interface BugsnagPerformanceSpanOptions()
@property(nonatomic,strong) NSDate *startTime_;
@property(nonatomic,strong) BugsnagPerformanceSpan *parentContext_;
@property(nonatomic) BOOL makeCurrentContext_;
@property(nonatomic) BSGFirstClass firstClass_;
@end

@implementation BugsnagPerformanceSpanOptions

+ (instancetype)optionsWithStartTime:(NSDate *)startTime
parentContext:(BugsnagPerformanceSpan *)parentContext
makeCurrentContext:(BOOL)makeCurrentContext
firstClass:(BSGFirstClass)firstClass {
return [[self alloc] initWithStartTime:startTime
parentContext:parentContext
makeCurrentContext:makeCurrentContext
firstClass:firstClass];
}
@synthesize startTime_ = _startTime;
@synthesize parentContext_ = _parentContext;
@synthesize makeCurrentContext_ = _makeCurrentContext;
@synthesize firstClass_ = _firstClass;

- (instancetype)init {
// These defaults must match the defaults in SpanOptions.h
Expand All @@ -43,12 +45,56 @@ - (instancetype)initWithStartTime:(NSDate *)startTime
return self;
}

- (NSDate *)startTime {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
return _startTime;
}

- (BugsnagPerformanceSpan *)parentContext {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
return _parentContext;
}

- (BOOL)makeCurrentContext {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
return _makeCurrentContext;
}

- (BSGFirstClass)firstClass {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
return _firstClass;
}

- (instancetype)setStartTime:(NSDate *)startTime {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
_startTime = startTime;
return self;
}

- (instancetype)setParentContext:(BugsnagPerformanceSpan *)parentContext {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
_parentContext = parentContext;
return self;
}

- (instancetype)setMakeCurrentContext:(BOOL)makeCurrentContext {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
_makeCurrentContext = makeCurrentContext;
return self;
}

- (instancetype)setFirstClass:(BSGFirstClass)firstClass {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
_firstClass = firstClass;
return self;
}

- (instancetype)clone {
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
return [BugsnagPerformanceSpanOptions optionsWithStartTime:_startTime
parentContext:_parentContext
makeCurrentContext:_makeCurrentContext
firstClass:_firstClass];
return [[BugsnagPerformanceSpanOptions alloc] initWithStartTime:_startTime
parentContext:_parentContext
makeCurrentContext:_makeCurrentContext
firstClass:_firstClass];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ OBJC_EXPORT
@interface BugsnagPerformanceSpanOptions: NSObject

// The time that this span is deemed to have started.
@property(nonatomic,readwrite,strong) NSDate *startTime;
@property(nonatomic, readonly) NSDate * _Nullable startTime;

// The context that this span is to be a child of, or nil if this will be a top-level span.
@property(nonatomic,readwrite,strong) BugsnagPerformanceSpan *parentContext;
@property(nonatomic, readonly) BugsnagPerformanceSpan * _Nullable parentContext;

// If true, the span will be added to the current context stack.
@property(nonatomic,readwrite) BOOL makeCurrentContext;
@property(nonatomic, readonly) BOOL makeCurrentContext;

// If true, this span will be considered "first class" on the dashboard.
@property(nonatomic,readwrite) BSGFirstClass firstClass;
@property(nonatomic, readonly) BSGFirstClass firstClass;

+ (instancetype)optionsWithStartTime:(NSDate *)starttime
parentContext:(BugsnagPerformanceSpan *)parentContext
makeCurrentContext:(BOOL)makeCurrentContext
firstClass:(BSGFirstClass)firstClass;

- (instancetype)initWithStartTime:(NSDate *)starttime
parentContext:(BugsnagPerformanceSpan *)parentContext
makeCurrentContext:(BOOL)makeCurrentContext
firstClass:(BSGFirstClass)firstClass;
- (instancetype _Nonnull)setStartTime:(NSDate * _Nullable)startTime;
- (instancetype _Nonnull)setParentContext:(BugsnagPerformanceSpan * _Nullable)parentContext;
- (instancetype _Nonnull)setMakeCurrentContext:(BOOL)makeCurrentContext;
- (instancetype _Nonnull)setFirstClass:(BSGFirstClass)firstClass;

- (instancetype)clone;
- (instancetype _Nonnull)clone;

@end
3 changes: 1 addition & 2 deletions features/fixtures/ios/Scenarios/FirstClassNoScenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import BugsnagPerformance
class FirstClassNoScenario: Scenario {

override func run() {
let opts = BugsnagPerformanceSpanOptions()
opts.firstClass = BSGFirstClass.no;
let opts = BugsnagPerformanceSpanOptions().setFirstClass(.no)
BugsnagPerformance.startSpan(name: "FirstClassNoScenario", options: opts).end()
}
}
3 changes: 1 addition & 2 deletions features/fixtures/ios/Scenarios/FirstClassYesScenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import BugsnagPerformance
class FirstClassYesScenario: Scenario {

override func run() {
let opts = BugsnagPerformanceSpanOptions()
opts.firstClass = BSGFirstClass.yes;
let opts = BugsnagPerformanceSpanOptions().setFirstClass(.yes)
BugsnagPerformance.startSpan(name: "FirstClassYesScenario", options: opts).end()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class ManualUIViewLoadScenario: Scenario {

override func run() {
let controller = UIViewController()
let options = BugsnagPerformanceSpanOptions()
options.startTime = Date()
let options = BugsnagPerformanceSpanOptions().setStartTime(Date())
BugsnagPerformance.startViewLoadSpan(controller: controller, options: options)
BugsnagPerformance.endViewLoadSpan(controller: controller, endTime: Date())
}
Expand Down
3 changes: 1 addition & 2 deletions features/fixtures/ios/Scenarios/ManualViewLoadScenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class ManualViewLoadScenario: Scenario {

override func run() {
BugsnagPerformance.startViewLoadSpan(name: "ManualViewController", viewType: .uiKit).end()
let options = BugsnagPerformanceSpanOptions()
options.startTime = Date()
let options = BugsnagPerformanceSpanOptions().setStartTime(Date())
BugsnagPerformance.startViewLoadSpan(name: "ManualView", viewType: .swiftUI, options:options).end()
}
}
Loading