From 7998c7ba715c20843f39be4055e921d073562e37 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 21 Mar 2023 11:20:05 +0100 Subject: [PATCH 01/12] feat: Interaction to next print measure --- Sources/Sentry/SentryHub.m | 49 ++---- Sources/Sentry/SentryPerformanceTracker.m | 5 +- Sources/Sentry/SentryTracer.m | 179 +++++++++------------ Sources/Sentry/SentryUIEventTracker.m | 6 +- Sources/Sentry/include/SentryHub+Private.h | 12 +- Sources/Sentry/include/SentryTracer.h | 100 ++++++------ 6 files changed, 148 insertions(+), 203 deletions(-) diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index 0abe5bdefd3..233e93fb0cd 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -367,9 +367,8 @@ - (SentryId *)captureEvent:(SentryEvent *)event { return [self startTransactionWithContext:transactionContext bindToScope:bindToScope - waitForChildren:NO customSamplingContext:customSamplingContext - timerWrapper:nil]; + configure:nil]; } - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)context @@ -386,42 +385,10 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con parentSampled:context.parentSampled]; } -- (id)startTransactionWithContext:(SentryTransactionContext *)transactionContext - bindToScope:(BOOL)bindToScope - waitForChildren:(BOOL)waitForChildren - customSamplingContext:(NSDictionary *)customSamplingContext - timerWrapper:(nullable SentryNSTimerWrapper *)timerWrapper -{ - SentrySamplingContext *samplingContext = - [[SentrySamplingContext alloc] initWithTransactionContext:transactionContext - customSamplingContext:customSamplingContext]; - - SentryTracesSamplerDecision *samplerDecision = [_tracesSampler sample:samplingContext]; - transactionContext = [self transactionContext:transactionContext - withSampled:samplerDecision.decision]; - transactionContext.sampleRate = samplerDecision.sampleRate; - - SentryProfilesSamplerDecision *profilesSamplerDecision = - [_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision]; - - id tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext - hub:self - profilesSamplerDecision:profilesSamplerDecision - waitForChildren:waitForChildren - timerWrapper:timerWrapper]; - - if (bindToScope) - self.scope.span = tracer; - - return tracer; -} - - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - idleTimeout:(NSTimeInterval)idleTimeout - dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper -{ + configure:(nullable SentryTracerConfigure)configure { SentrySamplingContext *samplingContext = [[SentrySamplingContext alloc] initWithTransactionContext:transactionContext customSamplingContext:customSamplingContext]; @@ -434,11 +401,15 @@ - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transa SentryProfilesSamplerDecision *profilesSamplerDecision = [_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision]; - SentryTracer *tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext + SentryTracer* tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext hub:self - profilesSamplerDecision:profilesSamplerDecision - idleTimeout:idleTimeout - dispatchQueueWrapper:dispatchQueueWrapper]; + configure:^(SentryTracerConfiguration * configuration) { + if (configure) { + configure(configuration); + } + configuration->profilesSamplerDecision = profilesSamplerDecision; + }]; + if (bindToScope) self.scope.span = tracer; diff --git a/Sources/Sentry/SentryPerformanceTracker.m b/Sources/Sentry/SentryPerformanceTracker.m index 1bdc5279060..c67feac9b28 100644 --- a/Sources/Sentry/SentryPerformanceTracker.m +++ b/Sources/Sentry/SentryPerformanceTracker.m @@ -81,9 +81,10 @@ - (SentrySpanId *)startSpanWithName:(NSString *)name SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope); newSpan = [SentrySDK.currentHub startTransactionWithContext:context bindToScope:bindToScope - waitForChildren:YES customSamplingContext:@{} - timerWrapper:nil]; + configure:^(SentryTracerConfiguration * configuration) { + configuration->waitForChildren = YES; + }]; if ([newSpan isKindOfClass:[SentryTracer class]]) { [(SentryTracer *)newSpan setDelegate:self]; diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 64b718789f2..f746d6f8688 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -54,9 +54,7 @@ * necessarily lead to finishing the tracer, because it could still wait for child spans to finish * if waitForChildren is YES. */ @property (nonatomic) BOOL wasFinishCalled; -@property (nonatomic) NSTimeInterval idleTimeout; -@property (nonatomic, nullable, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper; -@property (nonatomic, nullable, strong) SentryNSTimerWrapper *timerWrapper; +@property (nonatomic) BOOL wasCaptured; @property (nonatomic, nullable, strong) NSTimer *deadlineTimer; #if SENTRY_TARGET_PROFILING_SUPPORTED @property (nonatomic) BOOL isProfiling; @@ -77,11 +75,12 @@ @implementation SentryTracer { NSDate *_originalStartTimestamp; #if SENTRY_HAS_UIKIT - NSUInteger initTotalFrames; NSUInteger initSlowFrames; NSUInteger initFrozenFrames; #endif + + SentryTracerConfiguration _configuration; } static NSObject *appStartMeasurementLock; @@ -100,113 +99,70 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti { return [self initWithTransactionContext:transactionContext hub:hub - profilesSamplerDecision:nil - waitForChildren:NO - timerWrapper:nil]; + configure:nil]; } -- (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext - hub:(nullable SentryHub *)hub - waitForChildren:(BOOL)waitForChildren -{ - return [self initWithTransactionContext:transactionContext - hub:hub - profilesSamplerDecision:nil - waitForChildren:waitForChildren - idleTimeout:0.0 - dispatchQueueWrapper:nil - timerWrapper:nil]; -} - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - profilesSamplerDecision: - (nullable SentryProfilesSamplerDecision *)profilesSamplerDecision - waitForChildren:(BOOL)waitForChildren - timerWrapper:(nullable SentryNSTimerWrapper *)timerWrapper -{ - return [self initWithTransactionContext:transactionContext - hub:hub - profilesSamplerDecision:profilesSamplerDecision - waitForChildren:waitForChildren - idleTimeout:0.0 - dispatchQueueWrapper:nil - timerWrapper:timerWrapper]; -} + configure:(nullable SentryTracerConfigure)configure { + if (!(self = [super initWithContext:transactionContext])) { + return nil; + } -- (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext - hub:(nullable SentryHub *)hub - profilesSamplerDecision: - (nullable SentryProfilesSamplerDecision *)profilesSamplerDecision - idleTimeout:(NSTimeInterval)idleTimeout - dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper -{ - return [self initWithTransactionContext:transactionContext - hub:hub - profilesSamplerDecision:profilesSamplerDecision - waitForChildren:YES - idleTimeout:idleTimeout - dispatchQueueWrapper:dispatchQueueWrapper - timerWrapper:nil]; -} - -- (instancetype) - initWithTransactionContext:(SentryTransactionContext *)transactionContext - hub:(nullable SentryHub *)hub - profilesSamplerDecision:(nullable SentryProfilesSamplerDecision *)profilesSamplerDecision - waitForChildren:(BOOL)waitForChildren - idleTimeout:(NSTimeInterval)idleTimeout - dispatchQueueWrapper:(nullable SentryDispatchQueueWrapper *)dispatchQueueWrapper - timerWrapper:(nullable SentryNSTimerWrapper *)timerWrapper -{ - if (self = [super initWithContext:transactionContext]) { - self.transactionContext = transactionContext; - _children = [[NSMutableArray alloc] init]; - self.hub = hub; - self.wasFinishCalled = NO; - _waitForChildren = waitForChildren; - _measurements = [[NSMutableDictionary alloc] init]; - self.finishStatus = kSentrySpanStatusUndefined; - self.idleTimeout = idleTimeout; - self.dispatchQueueWrapper = dispatchQueueWrapper; - - if (timerWrapper == nil) { - self.timerWrapper = [[SentryNSTimerWrapper alloc] init]; - } else { - self.timerWrapper = timerWrapper; - } + SentryTracerConfiguration configuration; + configuration.autoCapture = NO; + configuration.idleTimeout = 0.0; + configuration.dispatchQueueWrapper = nil; + configuration.profilesSamplerDecision = nil; + configuration.timerWrapper = nil; + configuration.waitForChildren = NO; + if (configure) { + configure(&configuration); + } + _configuration = configuration; - appStartMeasurement = [self getAppStartMeasurement]; + self.transactionContext = transactionContext; + _children = [[NSMutableArray alloc] init]; + self.hub = hub; + self.wasFinishCalled = NO; + _measurements = [[NSMutableDictionary alloc] init]; + self.finishStatus = kSentrySpanStatusUndefined; - if ([self hasIdleTimeout]) { - [self dispatchIdleTimeout]; - } + if (_configuration.timerWrapper == nil) { + _configuration.timerWrapper = [[SentryNSTimerWrapper alloc] init]; + } - if ([self isAutoGeneratedTransaction]) { - [self startDeadlineTimer]; - } + appStartMeasurement = [self getAppStartMeasurement]; + + if ([self hasIdleTimeout]) { + [self dispatchIdleTimeout]; + } + + if ([self isAutoGeneratedTransaction]) { + [self startDeadlineTimer]; + } #if SENTRY_HAS_UIKIT - // Store current amount of frames at the beginning to be able to calculate the amount of - // frames at the end of the transaction. - SentryFramesTracker *framesTracker = [SentryFramesTracker sharedInstance]; - if (framesTracker.isRunning) { - SentryScreenFrames *currentFrames = framesTracker.currentFrames; - initTotalFrames = currentFrames.total; - initSlowFrames = currentFrames.slow; - initFrozenFrames = currentFrames.frozen; - } + // Store current amount of frames at the beginning to be able to calculate the amount of + // frames at the end of the transaction. + SentryFramesTracker *framesTracker = [SentryFramesTracker sharedInstance]; + if (framesTracker.isRunning) { + SentryScreenFrames *currentFrames = framesTracker.currentFrames; + initTotalFrames = currentFrames.total; + initSlowFrames = currentFrames.slow; + initFrozenFrames = currentFrames.frozen; + } #endif // SENTRY_HAS_UIKIT #if SENTRY_TARGET_PROFILING_SUPPORTED - if (profilesSamplerDecision.decision == kSentrySampleDecisionYes) { - _isProfiling = YES; - _startSystemTime = getAbsoluteTime(); - [SentryProfiler startWithHub:hub]; - trackTracerWithID(self.traceId); - } -#endif // SENTRY_TARGET_PROFILING_SUPPORTED + if (_configuration.profilesSamplerDecision.decision == kSentrySampleDecisionYes) { + _isProfiling = YES; + _startSystemTime = getAbsoluteTime(); + [SentryProfiler startWithHub:hub]; + trackTracerWithID(self.traceId); } +#endif // SENTRY_TARGET_PROFILING_SUPPORTED return self; } @@ -214,7 +170,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti - (void)dispatchIdleTimeout { if (_idleTimeoutBlock != nil) { - [self.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; + [_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; } __weak SentryTracer *weakSelf = self; _idleTimeoutBlock = dispatch_block_create(0, ^{ @@ -224,23 +180,23 @@ - (void)dispatchIdleTimeout } [weakSelf finishInternal]; }); - [self.dispatchQueueWrapper dispatchAfter:self.idleTimeout block:_idleTimeoutBlock]; + [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout block:_idleTimeoutBlock]; } - (BOOL)hasIdleTimeout { - return self.idleTimeout > 0 && self.dispatchQueueWrapper != nil; + return _configuration.idleTimeout > 0 && _configuration.dispatchQueueWrapper != nil; } - (BOOL)isAutoGeneratedTransaction { - return self.waitForChildren || [self hasIdleTimeout]; + return _configuration.waitForChildren || [self hasIdleTimeout]; } - (void)cancelIdleTimeout { if ([self hasIdleTimeout]) { - [self.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; + [_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; } } @@ -248,7 +204,7 @@ - (void)startDeadlineTimer { __weak SentryTracer *weakSelf = self; self.deadlineTimer = - [self.timerWrapper scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE + [_configuration.timerWrapper scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE repeats:NO block:^(NSTimer *_Nonnull timer) { if (weakSelf == nil) { @@ -479,7 +435,7 @@ - (void)finishInternal }]; @synchronized(_children) { - if (self.idleTimeout > 0.0 && _children.count == 0) { + if (_configuration.idleTimeout > 0.0 && _children.count == 0) { SENTRY_LOG_DEBUG(@"Was waiting for timeout for UI event trace but it had no children, " @"will not keep transaction."); return; @@ -500,6 +456,23 @@ - (void)finishInternal } } + if (_configuration.autoCapture) { + [self capture]; + } +} + +- (void)capture { + + if (self.wasCaptured) { + return; + } + @synchronized (self) { + if (self.wasCaptured) { + return; + } + self.wasCaptured = true; + } + SentryTransaction *transaction = [self toTransaction]; // Prewarming can execute code up to viewDidLoad of a UIViewController, and keep the app in the diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index f15cbf752eb..479d252949c 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -125,8 +125,10 @@ - (void)start [SentrySDK.currentHub startTransactionWithContext:context bindToScope:bindToScope customSamplingContext:@{} - idleTimeout:self.idleTimeout - dispatchQueueWrapper:self.dispatchQueueWrapper]; + configure:^(SentryTracerConfiguration * _Nonnull configuration) { + configuration->idleTimeout = self.idleTimeout; + configuration->dispatchQueueWrapper = self.dispatchQueueWrapper; + }]; SENTRY_LOG_DEBUG(@"SentryUIEventTracker automatically started a new transaction " @"with name: %@, bindToScope: %@", diff --git a/Sources/Sentry/include/SentryHub+Private.h b/Sources/Sentry/include/SentryHub+Private.h index 21692e7d22c..8fc3005a656 100644 --- a/Sources/Sentry/include/SentryHub+Private.h +++ b/Sources/Sentry/include/SentryHub+Private.h @@ -1,7 +1,8 @@ #import "SentryHub.h" +#import "SentryTracer.h" @class SentryEnvelopeItem, SentryId, SentryScope, SentryTransaction, SentryDispatchQueueWrapper, - SentryEnvelope, SentryTracer, SentryNSTimerWrapper; + SentryEnvelope, SentryNSTimerWrapper; NS_ASSUME_NONNULL_BEGIN @@ -33,17 +34,10 @@ SentryHub (Private) operation:(NSString *)operation bindToScope:(BOOL)bindToScope; -- (id)startTransactionWithContext:(SentryTransactionContext *)transactionContext - bindToScope:(BOOL)bindToScope - waitForChildren:(BOOL)waitForChildren - customSamplingContext:(NSDictionary *)customSamplingContext - timerWrapper:(nullable SentryNSTimerWrapper *)timerWrapper; - - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - idleTimeout:(NSTimeInterval)idleTimeout - dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper; + configure:(nullable SentryTracerConfigure)configure; - (SentryId *)captureEvent:(SentryEvent *)event withScope:(SentryScope *)scope diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 8999c467e43..104a5048f5d 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -10,6 +10,49 @@ NS_ASSUME_NONNULL_BEGIN static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; +typedef struct { + /** + * Indicates whether the tracer will be finished only if all children have been finished. + * If this property is YES and the finish function is called before all children are finished + * the tracer will automatically finish when the last child finishes. + * + * Default is NO. + */ + BOOL waitForChildren; + + /** + * A dispatch queue wrapper to intermediate between the tracer and dispatch calls. + */ + SentryDispatchQueueWrapper * _Nullable dispatchQueueWrapper; + + /** + * Whether to sample a profile corresponding to this transaction + */ + SentryProfilesSamplerDecision * _Nullable profilesSamplerDecision; + + /** + * The idle time to wait until to finish the transaction + * + * Default is 0 seconds + */ + NSTimeInterval idleTimeout; + + /** + * A writer around NSTimer, to make it testable + */ + SentryNSTimerWrapper * _Nullable timerWrapper; + + /** + * Indicates whether the tracer should automatically capture the transaction after finishing. + * + * Default is YES. + */ + BOOL autoCapture; + +} SentryTracerConfiguration; + +typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); + @protocol SentryTracerDelegate /** @@ -26,13 +69,6 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; @property (nullable, nonatomic, copy) void (^finishCallback)(SentryTracer *); -/** - * Indicates whether this tracer will be finished only if all children have been finished. - * If this property is YES and the finish function is called before all children are finished - * the tracer will automatically finish when the last child finishes. - */ -@property (readonly) BOOL waitForChildren; - /** * Retrieves a trace context from this tracer. */ @@ -70,55 +106,16 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; hub:(nullable SentryHub *)hub; /** - * Init a SentryTracer with given transaction context, hub and whether the tracer should wait - * for all children to finish before it finishes. - * - * @param transactionContext Transaction context - * @param hub A hub to bind this transaction - * @param waitForChildren Whether this tracer should wait all children to finish. - * - * @return SentryTracer - */ -- (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext - hub:(nullable SentryHub *)hub - waitForChildren:(BOOL)waitForChildren; - -/** - * Init a SentryTracer with given transaction context, hub and whether the tracer should wait - * for all children to finish before it finishes. - * - * @param transactionContext Transaction context - * @param hub A hub to bind this transaction - * @param profilesSamplerDecision Whether to sample a profile corresponding to this transaction - * @param waitForChildren Whether this tracer should wait all children to finish. - * @param timerWrapper A writer around NSTimer, to make it testable - * - * @return SentryTracer - */ -- (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext - hub:(nullable SentryHub *)hub - profilesSamplerDecision: - (nullable SentryProfilesSamplerDecision *)profilesSamplerDecision - waitForChildren:(BOOL)waitForChildren - timerWrapper:(nullable SentryNSTimerWrapper *)timerWrapper; - -/** - * Init a SentryTracer with given transaction context, hub and whether the tracer should wait - * for all children to finish before it finishes. + * Init a SentryTracer with given transaction context and hub and set other fields by default * * @param transactionContext Transaction context * @param hub A hub to bind this transaction - * @param profilesSamplerDecision Whether to sample a profile corresponding to this transaction - * @param idleTimeout The idle time to wait until to finish the transaction. * * @return SentryTracer */ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - profilesSamplerDecision: - (nullable SentryProfilesSamplerDecision *)profilesSamplerDecision - idleTimeout:(NSTimeInterval)idleTimeout - dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper; + configure:(nullable SentryTracerConfigure)configure; - (id)startChildWithParentId:(SentrySpanId *)parentId operation:(NSString *)operation @@ -130,6 +127,13 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; */ - (void)spanFinished:(id)finishedSpan; + +/** + * Capture the transaction in case it was not captured yet. + */ +- (void)capture; + + /** * Get the tracer from a span. */ From aaabd9955834e4da0e80c6ff6414f3419c96a215 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 21 Mar 2023 10:25:07 +0000 Subject: [PATCH 02/12] Format code --- Sources/Sentry/SentryHub.m | 22 +++++++++-------- Sources/Sentry/SentryPerformanceTracker.m | 10 ++++---- Sources/Sentry/SentryTracer.m | 30 +++++++++++------------ Sources/Sentry/SentryUIEventTracker.m | 9 +++---- Sources/Sentry/include/SentryTracer.h | 10 +++----- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index 233e93fb0cd..ac358db687d 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -368,7 +368,7 @@ - (SentryId *)captureEvent:(SentryEvent *)event return [self startTransactionWithContext:transactionContext bindToScope:bindToScope customSamplingContext:customSamplingContext - configure:nil]; + configure:nil]; } - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)context @@ -388,7 +388,8 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - configure:(nullable SentryTracerConfigure)configure { + configure:(nullable SentryTracerConfigure)configure +{ SentrySamplingContext *samplingContext = [[SentrySamplingContext alloc] initWithTransactionContext:transactionContext customSamplingContext:customSamplingContext]; @@ -401,14 +402,15 @@ - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transa SentryProfilesSamplerDecision *profilesSamplerDecision = [_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision]; - SentryTracer* tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext - hub:self - configure:^(SentryTracerConfiguration * configuration) { - if (configure) { - configure(configuration); - } - configuration->profilesSamplerDecision = profilesSamplerDecision; - }]; + SentryTracer *tracer = [[SentryTracer alloc] + initWithTransactionContext:transactionContext + hub:self + configure:^(SentryTracerConfiguration *configuration) { + if (configure) { + configure(configuration); + } + configuration->profilesSamplerDecision = profilesSamplerDecision; + }]; if (bindToScope) self.scope.span = tracer; diff --git a/Sources/Sentry/SentryPerformanceTracker.m b/Sources/Sentry/SentryPerformanceTracker.m index c67feac9b28..35d28120adb 100644 --- a/Sources/Sentry/SentryPerformanceTracker.m +++ b/Sources/Sentry/SentryPerformanceTracker.m @@ -80,11 +80,11 @@ - (SentrySpanId *)startSpanWithName:(NSString *)name SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope); newSpan = [SentrySDK.currentHub startTransactionWithContext:context - bindToScope:bindToScope - customSamplingContext:@{} - configure:^(SentryTracerConfiguration * configuration) { - configuration->waitForChildren = YES; - }]; + bindToScope:bindToScope + customSamplingContext:@{} + configure:^(SentryTracerConfiguration *configuration) { + configuration->waitForChildren = YES; + }]; if ([newSpan isKindOfClass:[SentryTracer class]]) { [(SentryTracer *)newSpan setDelegate:self]; diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index f746d6f8688..a3cac73d974 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -97,15 +97,13 @@ + (void)initialize - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub { - return [self initWithTransactionContext:transactionContext - hub:hub - configure:nil]; + return [self initWithTransactionContext:transactionContext hub:hub configure:nil]; } - - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - configure:(nullable SentryTracerConfigure)configure { + configure:(nullable SentryTracerConfigure)configure +{ if (!(self = [super initWithContext:transactionContext])) { return nil; } @@ -180,7 +178,8 @@ - (void)dispatchIdleTimeout } [weakSelf finishInternal]; }); - [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout block:_idleTimeoutBlock]; + [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout + block:_idleTimeoutBlock]; } - (BOOL)hasIdleTimeout @@ -205,13 +204,13 @@ - (void)startDeadlineTimer __weak SentryTracer *weakSelf = self; self.deadlineTimer = [_configuration.timerWrapper scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE - repeats:NO - block:^(NSTimer *_Nonnull timer) { - if (weakSelf == nil) { - return; - } - [weakSelf deadlineTimerFired]; - }]; + repeats:NO + block:^(NSTimer *_Nonnull timer) { + if (weakSelf == nil) { + return; + } + [weakSelf deadlineTimerFired]; + }]; } - (void)deadlineTimerFired @@ -461,12 +460,13 @@ - (void)finishInternal } } -- (void)capture { +- (void)capture +{ if (self.wasCaptured) { return; } - @synchronized (self) { + @synchronized(self) { if (self.wasCaptured) { return; } diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index 479d252949c..9328a3af535 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -121,11 +121,10 @@ - (void)start && ![span.operation containsString:SentrySpanOperationUIAction]; BOOL bindToScope = !ongoingScreenLoadTransaction && !ongoingManualTransaction; - transaction = - [SentrySDK.currentHub startTransactionWithContext:context - bindToScope:bindToScope - customSamplingContext:@{} - configure:^(SentryTracerConfiguration * _Nonnull configuration) { + transaction = [SentrySDK.currentHub startTransactionWithContext:context + bindToScope:bindToScope + customSamplingContext:@{} + configure:^(SentryTracerConfiguration *_Nonnull configuration) { configuration->idleTimeout = self.idleTimeout; configuration->dispatchQueueWrapper = self.dispatchQueueWrapper; }]; diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 104a5048f5d..0d590a43d3d 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -23,12 +23,12 @@ typedef struct { /** * A dispatch queue wrapper to intermediate between the tracer and dispatch calls. */ - SentryDispatchQueueWrapper * _Nullable dispatchQueueWrapper; + SentryDispatchQueueWrapper *_Nullable dispatchQueueWrapper; /** * Whether to sample a profile corresponding to this transaction */ - SentryProfilesSamplerDecision * _Nullable profilesSamplerDecision; + SentryProfilesSamplerDecision *_Nullable profilesSamplerDecision; /** * The idle time to wait until to finish the transaction @@ -40,7 +40,7 @@ typedef struct { /** * A writer around NSTimer, to make it testable */ - SentryNSTimerWrapper * _Nullable timerWrapper; + SentryNSTimerWrapper *_Nullable timerWrapper; /** * Indicates whether the tracer should automatically capture the transaction after finishing. @@ -51,7 +51,7 @@ typedef struct { } SentryTracerConfiguration; -typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); +typedef void (^SentryTracerConfigure)(SentryTracerConfiguration *configuration); @protocol SentryTracerDelegate @@ -127,13 +127,11 @@ typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); */ - (void)spanFinished:(id)finishedSpan; - /** * Capture the transaction in case it was not captured yet. */ - (void)capture; - /** * Get the tracer from a span. */ From b5d80ee5a2e1a7beb76639f7df98c754a2e98166 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 21 Mar 2023 14:54:56 +0100 Subject: [PATCH 03/12] Trace configuration as objc --- Sentry.xcodeproj/project.pbxproj | 8 +++ Sources/Sentry/SentryHub.m | 16 +++-- Sources/Sentry/SentryPerformanceTracker.m | 15 +++-- Sources/Sentry/SentryTracer.m | 59 +++++-------------- Sources/Sentry/SentryTracerConfiguration.m | 23 ++++++++ Sources/Sentry/SentryUIEventTracker.m | 18 +++--- Sources/Sentry/include/SentryHub+Private.h | 2 +- Sources/Sentry/include/SentryTracer.h | 54 +---------------- .../include/SentryTracerConfiguration.h | 45 ++++++++++++++ Sources/SentryCrash/Recording/SentryCrash.m | 5 +- 10 files changed, 125 insertions(+), 120 deletions(-) create mode 100644 Sources/Sentry/SentryTracerConfiguration.m create mode 100644 Sources/Sentry/include/SentryTracerConfiguration.h diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 53fe837d691..cbd3bd910cb 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -759,6 +759,8 @@ D8ACE3CD2762187D00F5A213 /* SentryNSDataSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = D8ACE3CA2762187D00F5A213 /* SentryNSDataSwizzling.h */; }; D8ACE3CE2762187D00F5A213 /* SentryNSDataTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = D8ACE3CB2762187D00F5A213 /* SentryNSDataTracker.h */; }; D8ACE3CF2762187D00F5A213 /* SentryFileIOTrackingIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8ACE3CC2762187D00F5A213 /* SentryFileIOTrackingIntegration.h */; }; + D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */; }; + D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */; }; D8B76B062808066D000A58C4 /* SentryScreenshotIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */; }; D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */; }; D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BBD32628FD9FBF0011F850 /* SentrySwift.h */; }; @@ -1663,6 +1665,8 @@ D8ACE3CA2762187D00F5A213 /* SentryNSDataSwizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryNSDataSwizzling.h; path = include/SentryNSDataSwizzling.h; sourceTree = ""; }; D8ACE3CB2762187D00F5A213 /* SentryNSDataTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryNSDataTracker.h; path = include/SentryNSDataTracker.h; sourceTree = ""; }; D8ACE3CC2762187D00F5A213 /* SentryFileIOTrackingIntegration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryFileIOTrackingIntegration.h; path = include/SentryFileIOTrackingIntegration.h; sourceTree = ""; }; + D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = ""; }; + D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = ""; }; D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshotIntegrationTests.swift; sourceTree = ""; }; D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryScreenShot.swift; sourceTree = ""; }; D8BBD32628FD9FBF0011F850 /* SentrySwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySwift.h; path = include/SentrySwift.h; sourceTree = ""; }; @@ -3121,6 +3125,8 @@ 8E133FA025E72DEF00ABD0BF /* SentrySamplingContext.m */, 8E4E7C7B25DAB287006AB9E2 /* SentryTracer.h */, 8E4E7C8125DAB2A5006AB9E2 /* SentryTracer.m */, + D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */, + D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */, 84AF45A429A7FFA500FBB177 /* SentryTracerConcurrency.h */, 84AF45A529A7FFA500FBB177 /* SentryTracerConcurrency.mm */, 8E8C57A525EEFC42001CEEFA /* SentryTracesSampler.h */, @@ -3471,6 +3477,7 @@ 63BE85701ECEC6DE00DC44F5 /* NSDate+SentryExtras.h in Headers */, 63FE709520DA4C1000CDBAE8 /* SentryCrashReportFilterBasic.h in Headers */, 844EDCE52947DC3100C86F34 /* SentryNSTimerWrapper.h in Headers */, + D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */, 63FE70A120DA4C1000CDBAE8 /* SentryCrashCString.h in Headers */, 7B63459D280EBA6300CFA05A /* SentryUIEventTracker.h in Headers */, 7B7D873424864C6600D2ECFF /* SentryCrashDefaultMachineContextWrapper.h in Headers */, @@ -3822,6 +3829,7 @@ 7B3B473825D6CC7E00D01640 /* SentryNSError.m in Sources */, D8ACE3C82762187200F5A213 /* SentryNSDataTracker.m in Sources */, 7BE3C77D2446112C00A38442 /* SentryRateLimitParser.m in Sources */, + D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */, 8ECC674A25C23A20000E2BF6 /* SentryTransactionContext.mm in Sources */, 03BCC38C27E1C01A003232C7 /* SentryTime.mm in Sources */, A8F17B342902870300990B25 /* SentryHttpStatusCodeRange.m in Sources */, diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index 233e93fb0cd..02e6913918f 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -368,7 +368,7 @@ - (SentryId *)captureEvent:(SentryEvent *)event return [self startTransactionWithContext:transactionContext bindToScope:bindToScope customSamplingContext:customSamplingContext - configure:nil]; + configuration:nil]; } - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)context @@ -388,7 +388,8 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - configure:(nullable SentryTracerConfigure)configure { + configuration:(nullable SentryTracerConfiguration *)configuration +{ SentrySamplingContext *samplingContext = [[SentrySamplingContext alloc] initWithTransactionContext:transactionContext customSamplingContext:customSamplingContext]; @@ -401,14 +402,11 @@ - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transa SentryProfilesSamplerDecision *profilesSamplerDecision = [_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision]; - SentryTracer* tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext + configuration.profilesSamplerDecision = profilesSamplerDecision; + + SentryTracer *tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext hub:self - configure:^(SentryTracerConfiguration * configuration) { - if (configure) { - configure(configuration); - } - configuration->profilesSamplerDecision = profilesSamplerDecision; - }]; + configuration:configuration]; if (bindToScope) self.scope.span = tracer; diff --git a/Sources/Sentry/SentryPerformanceTracker.m b/Sources/Sentry/SentryPerformanceTracker.m index c67feac9b28..5264d9ebff6 100644 --- a/Sources/Sentry/SentryPerformanceTracker.m +++ b/Sources/Sentry/SentryPerformanceTracker.m @@ -79,12 +79,15 @@ - (SentrySpanId *)startSpanWithName:(NSString *)name } SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope); - newSpan = [SentrySDK.currentHub startTransactionWithContext:context - bindToScope:bindToScope - customSamplingContext:@{} - configure:^(SentryTracerConfiguration * configuration) { - configuration->waitForChildren = YES; - }]; + + newSpan = [SentrySDK.currentHub + startTransactionWithContext:context + bindToScope:bindToScope + customSamplingContext:@{} + configuration:[SentryTracerConfiguration configurationWithBlock:^( + SentryTracerConfiguration *configuration) { + configuration.waitForChildren = YES; + }]]; if ([newSpan isKindOfClass:[SentryTracer class]]) { [(SentryTracer *)newSpan setDelegate:self]; diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index f746d6f8688..084f2b2f4f3 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -54,8 +54,9 @@ * necessarily lead to finishing the tracer, because it could still wait for child spans to finish * if waitForChildren is YES. */ @property (nonatomic) BOOL wasFinishCalled; -@property (nonatomic) BOOL wasCaptured; @property (nonatomic, nullable, strong) NSTimer *deadlineTimer; +@property (nonnull, strong) SentryTracerConfiguration *configuration; + #if SENTRY_TARGET_PROFILING_SUPPORTED @property (nonatomic) BOOL isProfiling; @property (nonatomic) uint64_t startSystemTime; @@ -79,8 +80,6 @@ @implementation SentryTracer { NSUInteger initSlowFrames; NSUInteger initFrozenFrames; #endif - - SentryTracerConfiguration _configuration; } static NSObject *appStartMeasurementLock; @@ -97,30 +96,18 @@ + (void)initialize - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub { - return [self initWithTransactionContext:transactionContext - hub:hub - configure:nil]; + return [self initWithTransactionContext:transactionContext hub:hub configuration:nil]; } - - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - configure:(nullable SentryTracerConfigure)configure { + configuration:(nullable SentryTracerConfiguration *)configuration; +{ if (!(self = [super initWithContext:transactionContext])) { return nil; } - SentryTracerConfiguration configuration; - configuration.autoCapture = NO; - configuration.idleTimeout = 0.0; - configuration.dispatchQueueWrapper = nil; - configuration.profilesSamplerDecision = nil; - configuration.timerWrapper = nil; - configuration.waitForChildren = NO; - if (configure) { - configure(&configuration); - } - _configuration = configuration; + _configuration = configuration ?: [[SentryTracerConfiguration alloc] init]; self.transactionContext = transactionContext; _children = [[NSMutableArray alloc] init]; @@ -180,7 +167,8 @@ - (void)dispatchIdleTimeout } [weakSelf finishInternal]; }); - [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout block:_idleTimeoutBlock]; + [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout + block:_idleTimeoutBlock]; } - (BOOL)hasIdleTimeout @@ -205,13 +193,13 @@ - (void)startDeadlineTimer __weak SentryTracer *weakSelf = self; self.deadlineTimer = [_configuration.timerWrapper scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE - repeats:NO - block:^(NSTimer *_Nonnull timer) { - if (weakSelf == nil) { - return; - } - [weakSelf deadlineTimerFired]; - }]; + repeats:NO + block:^(NSTimer *_Nonnull timer) { + if (weakSelf == nil) { + return; + } + [weakSelf deadlineTimerFired]; + }]; } - (void)deadlineTimerFired @@ -456,23 +444,6 @@ - (void)finishInternal } } - if (_configuration.autoCapture) { - [self capture]; - } -} - -- (void)capture { - - if (self.wasCaptured) { - return; - } - @synchronized (self) { - if (self.wasCaptured) { - return; - } - self.wasCaptured = true; - } - SentryTransaction *transaction = [self toTransaction]; // Prewarming can execute code up to viewDidLoad of a UIViewController, and keep the app in the diff --git a/Sources/Sentry/SentryTracerConfiguration.m b/Sources/Sentry/SentryTracerConfiguration.m new file mode 100644 index 00000000000..3d7b173a48d --- /dev/null +++ b/Sources/Sentry/SentryTracerConfiguration.m @@ -0,0 +1,23 @@ +#import "SentryTracerConfiguration.h" + +@implementation SentryTracerConfiguration + ++ (SentryTracerConfiguration *)configurationWithBlock:(void (^)(SentryTracerConfiguration *))block +{ + SentryTracerConfiguration *result = [[SentryTracerConfiguration alloc] init]; + + block(result); + + return result; +} + +- (instancetype)init +{ + if (self = [super init]) { + self.idleTimeout = 0; + self.waitForChildren = NO; + } + return self; +} + +@end diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index 479d252949c..71cce409c44 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -121,14 +121,16 @@ - (void)start && ![span.operation containsString:SentrySpanOperationUIAction]; BOOL bindToScope = !ongoingScreenLoadTransaction && !ongoingManualTransaction; - transaction = - [SentrySDK.currentHub startTransactionWithContext:context - bindToScope:bindToScope - customSamplingContext:@{} - configure:^(SentryTracerConfiguration * _Nonnull configuration) { - configuration->idleTimeout = self.idleTimeout; - configuration->dispatchQueueWrapper = self.dispatchQueueWrapper; - }]; + + transaction = [SentrySDK.currentHub + startTransactionWithContext:context + bindToScope:bindToScope + customSamplingContext:@{} + configuration:[SentryTracerConfiguration configurationWithBlock:^( + SentryTracerConfiguration *config) { + config.idleTimeout = self.idleTimeout; + config.dispatchQueueWrapper = self.dispatchQueueWrapper; + }]]; SENTRY_LOG_DEBUG(@"SentryUIEventTracker automatically started a new transaction " @"with name: %@, bindToScope: %@", diff --git a/Sources/Sentry/include/SentryHub+Private.h b/Sources/Sentry/include/SentryHub+Private.h index 8fc3005a656..9e764f1847a 100644 --- a/Sources/Sentry/include/SentryHub+Private.h +++ b/Sources/Sentry/include/SentryHub+Private.h @@ -37,7 +37,7 @@ SentryHub (Private) - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - configure:(nullable SentryTracerConfigure)configure; + configuration:(nullable SentryTracerConfiguration *)configuration; - (SentryId *)captureEvent:(SentryEvent *)event withScope:(SentryScope *)scope diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 104a5048f5d..52d18e9cea0 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -1,5 +1,6 @@ #import "SentrySpan.h" #import "SentrySpanProtocol.h" +#import "SentryTracerConfiguration.h" #import NS_ASSUME_NONNULL_BEGIN @@ -10,49 +11,6 @@ NS_ASSUME_NONNULL_BEGIN static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; -typedef struct { - /** - * Indicates whether the tracer will be finished only if all children have been finished. - * If this property is YES and the finish function is called before all children are finished - * the tracer will automatically finish when the last child finishes. - * - * Default is NO. - */ - BOOL waitForChildren; - - /** - * A dispatch queue wrapper to intermediate between the tracer and dispatch calls. - */ - SentryDispatchQueueWrapper * _Nullable dispatchQueueWrapper; - - /** - * Whether to sample a profile corresponding to this transaction - */ - SentryProfilesSamplerDecision * _Nullable profilesSamplerDecision; - - /** - * The idle time to wait until to finish the transaction - * - * Default is 0 seconds - */ - NSTimeInterval idleTimeout; - - /** - * A writer around NSTimer, to make it testable - */ - SentryNSTimerWrapper * _Nullable timerWrapper; - - /** - * Indicates whether the tracer should automatically capture the transaction after finishing. - * - * Default is YES. - */ - BOOL autoCapture; - -} SentryTracerConfiguration; - -typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); - @protocol SentryTracerDelegate /** @@ -110,12 +68,13 @@ typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); * * @param transactionContext Transaction context * @param hub A hub to bind this transaction + * @param configuration Configuration on how SentryTracer will behave * * @return SentryTracer */ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - configure:(nullable SentryTracerConfigure)configure; + configuration:(nullable SentryTracerConfiguration *)configuration; - (id)startChildWithParentId:(SentrySpanId *)parentId operation:(NSString *)operation @@ -127,13 +86,6 @@ typedef void (^SentryTracerConfigure)(SentryTracerConfiguration* configuration); */ - (void)spanFinished:(id)finishedSpan; - -/** - * Capture the transaction in case it was not captured yet. - */ -- (void)capture; - - /** * Get the tracer from a span. */ diff --git a/Sources/Sentry/include/SentryTracerConfiguration.h b/Sources/Sentry/include/SentryTracerConfiguration.h new file mode 100644 index 00000000000..9779ff4f1b1 --- /dev/null +++ b/Sources/Sentry/include/SentryTracerConfiguration.h @@ -0,0 +1,45 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SentryNSTimerWrapper, SentryDispatchQueueWrapper, SentryProfilesSamplerDecision; + +@interface SentryTracerConfiguration : NSObject + +/** + * Indicates whether the tracer will be finished only if all children have been finished. + * If this property is YES and the finish function is called before all children are finished + * the tracer will automatically finish when the last child finishes. + * + * Default is NO. + */ +@property (nonatomic) BOOL waitForChildren; + +/** + * A dispatch queue wrapper to intermediate between the tracer and dispatch calls. + */ +@property (nonatomic, strong, nullable) SentryDispatchQueueWrapper *dispatchQueueWrapper; + +/** + * Whether to sample a profile corresponding to this transaction + */ +@property (nonatomic, strong, nullable) SentryProfilesSamplerDecision *profilesSamplerDecision; + +/** + * The idle time to wait until to finish the transaction + * + * Default is 0 seconds + */ +@property (nonatomic) NSTimeInterval idleTimeout; + +/** + * A writer around NSTimer, to make it testable + */ +@property (nonatomic, strong, nullable) SentryNSTimerWrapper *timerWrapper; + ++ (SentryTracerConfiguration *)configurationWithBlock: + (void (^)(SentryTracerConfiguration *configuration))block; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/SentryCrash/Recording/SentryCrash.m b/Sources/SentryCrash/Recording/SentryCrash.m index 644b4719517..9e243e38d07 100644 --- a/Sources/SentryCrash/Recording/SentryCrash.m +++ b/Sources/SentryCrash/Recording/SentryCrash.m @@ -377,7 +377,10 @@ - (void)deleteReportWithID:(NSNumber *)reportID // ============================================================================ #define SYNTHESIZE_CRASH_STATE_PROPERTY(TYPE, NAME) \ - -(TYPE)NAME { return sentrycrashstate_currentState()->NAME; } + -(TYPE)NAME \ + { \ + return sentrycrashstate_currentState()->NAME; \ + } SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, activeDurationSinceLastCrash) SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, backgroundDurationSinceLastCrash) From 178dcb8e2b93306c8db70f007e32bc56501e50d3 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 21 Mar 2023 14:02:51 +0000 Subject: [PATCH 04/12] Format code --- Sources/SentryCrash/Recording/SentryCrash.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/SentryCrash/Recording/SentryCrash.m b/Sources/SentryCrash/Recording/SentryCrash.m index 9e243e38d07..644b4719517 100644 --- a/Sources/SentryCrash/Recording/SentryCrash.m +++ b/Sources/SentryCrash/Recording/SentryCrash.m @@ -377,10 +377,7 @@ - (void)deleteReportWithID:(NSNumber *)reportID // ============================================================================ #define SYNTHESIZE_CRASH_STATE_PROPERTY(TYPE, NAME) \ - -(TYPE)NAME \ - { \ - return sentrycrashstate_currentState()->NAME; \ - } + -(TYPE)NAME { return sentrycrashstate_currentState()->NAME; } SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, activeDurationSinceLastCrash) SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, backgroundDurationSinceLastCrash) From 77df70c6dfcdcdade020d2e6bff50f3b6b8c33df Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 21 Mar 2023 20:25:48 +0100 Subject: [PATCH 05/12] fix tests --- Sources/Sentry/SentryTracer.m | 3 +- Sources/SentryCrash/Recording/SentryCrash.m | 5 ++- .../Network/SentryNetworkTrackerTests.swift | 5 +-- .../SentryPerformanceTrackerTests.swift | 2 +- .../Performance/SentryTracerObjCTests.m | 41 +++++++++++-------- .../Performance/SentryTracerTests.swift | 14 ++++--- .../SentryTests/SentryTests-Bridging-Header.h | 1 + 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 084f2b2f4f3..bdde922f969 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -66,7 +66,6 @@ @implementation SentryTracer { /** Wether the tracer should wait for child spans to finish before finishing itself. */ - BOOL _waitForChildren; SentryTraceContext *_traceContext; SentryAppStartMeasurement *appStartMeasurement; NSMutableDictionary *_measurements; @@ -382,7 +381,7 @@ - (void)canBeFinished - (BOOL)hasUnfinishedChildSpansToWaitFor { - if (!_waitForChildren) { + if (!self.configuration.waitForChildren) { return NO; } diff --git a/Sources/SentryCrash/Recording/SentryCrash.m b/Sources/SentryCrash/Recording/SentryCrash.m index 644b4719517..9e243e38d07 100644 --- a/Sources/SentryCrash/Recording/SentryCrash.m +++ b/Sources/SentryCrash/Recording/SentryCrash.m @@ -377,7 +377,10 @@ - (void)deleteReportWithID:(NSNumber *)reportID // ============================================================================ #define SYNTHESIZE_CRASH_STATE_PROPERTY(TYPE, NAME) \ - -(TYPE)NAME { return sentrycrashstate_currentState()->NAME; } + -(TYPE)NAME \ + { \ + return sentrycrashstate_currentState()->NAME; \ + } SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, activeDurationSinceLastCrash) SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, backgroundDurationSinceLastCrash) diff --git a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift index 8b24de0ada8..7641face2c3 100644 --- a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift @@ -155,7 +155,7 @@ class SentryNetworkTrackerTests: XCTestCase { let tracer = SentryTracer(transactionContext: TransactionContext(name: SentryNetworkTrackerTests.transactionName, operation: SentryNetworkTrackerTests.transactionOperation), hub: nil, - waitForChildren: true) + configuration: SentryTracerConfiguration(block: { $0.waitForChildren = true })) tracer.finish() @@ -172,8 +172,7 @@ class SentryNetworkTrackerTests: XCTestCase { let task = createDataTask() let tracer = SentryTracer(transactionContext: TransactionContext(name: SentryNetworkTrackerTests.transactionName, operation: SentryNetworkTrackerTests.transactionOperation), - hub: nil, - waitForChildren: true) + hub: nil, configuration: SentryTracerConfiguration(block: { $0.waitForChildren = true })) fixture.scope.span = tracer sut.urlSessionTaskResume(task) diff --git a/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackerTests.swift index 386737a1bc2..a0d3bcbd80d 100644 --- a/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/SentryPerformanceTrackerTests.swift @@ -47,7 +47,7 @@ class SentryPerformanceTrackerTests: XCTestCase { let scopeSpan = fixture.scope.span XCTAssert(scopeSpan === transaction) - XCTAssertTrue(transaction.waitForChildren) + XCTAssertTrue(Dynamic(transaction).configuration.waitForChildren.asBool ?? false) XCTAssertEqual(transaction.transactionContext.name, fixture.someTransaction) XCTAssertEqual(transaction.transactionContext.nameSource, .custom) } diff --git a/Tests/SentryTests/Performance/SentryTracerObjCTests.m b/Tests/SentryTests/Performance/SentryTracerObjCTests.m index 495fc004e9c..8378315cfb6 100644 --- a/Tests/SentryTests/Performance/SentryTracerObjCTests.m +++ b/Tests/SentryTests/Performance/SentryTracerObjCTests.m @@ -27,11 +27,14 @@ - (void)testSpanFinishesAfterTracerReleased_NoCrash_TracerIsNil SentryHub *hub = [[SentryHub alloc] initWithClient:nil andScope:nil]; SentryTransactionContext *context = [[SentryTransactionContext alloc] initWithOperation:@""]; - SentryTracer *tracer = [[SentryTracer alloc] initWithTransactionContext:context - hub:hub - profilesSamplerDecision:nil - waitForChildren:YES - timerWrapper:nil]; + SentryTracer *tracer = [[SentryTracer alloc] + initWithTransactionContext:context + hub:hub + configuration:[SentryTracerConfiguration configurationWithBlock:^( + SentryTracerConfiguration *configuration) { + configuration.waitForChildren = YES; + }]]; + [tracer finish]; child = [tracer startChildWithOperation:@"child"]; } @@ -55,17 +58,23 @@ - (void)testConcurrentTracerProfiling [[SentryProfilesSamplerDecision alloc] initWithDecision:kSentrySampleDecisionYes forSampleRate:@1]; - SentryTracer *tracer1 = [[SentryTracer alloc] initWithTransactionContext:context1 - hub:hub - profilesSamplerDecision:decision - waitForChildren:YES - timerWrapper:nil]; - - SentryTracer *tracer2 = [[SentryTracer alloc] initWithTransactionContext:context2 - hub:hub - profilesSamplerDecision:decision - waitForChildren:YES - timerWrapper:nil]; + SentryTracer *tracer1 = [[SentryTracer alloc] + initWithTransactionContext:context1 + hub:hub + configuration:[SentryTracerConfiguration configurationWithBlock:^( + SentryTracerConfiguration *configuration) { + configuration.profilesSamplerDecision = decision; + configuration.waitForChildren = YES; + }]]; + + SentryTracer *tracer2 = [[SentryTracer alloc] + initWithTransactionContext:context2 + hub:hub + configuration:[SentryTracerConfiguration configurationWithBlock:^( + SentryTracerConfiguration *configuration) { + configuration.profilesSamplerDecision = decision; + configuration.waitForChildren = YES; + }]]; // force some samples to be taken by the profiler NSMutableString *string = [NSMutableString string]; diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 6d79b6d136f..47b7d734301 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -83,9 +83,11 @@ class SentryTracerTests: XCTestCase { let tracer = hub.startTransaction( with: transactionContext, bindToScope: false, - waitForChildren: waitForChildren, customSamplingContext: [:], - timerWrapper: timerWrapper) as! SentryTracer + configuration: SentryTracerConfiguration(block: { + $0.waitForChildren = waitForChildren + $0.timerWrapper = self.timerWrapper + })) return tracer } @@ -94,8 +96,10 @@ class SentryTracerTests: XCTestCase { with: transactionContext, bindToScope: false, customSamplingContext: [:], - idleTimeout: idleTimeout, - dispatchQueueWrapper: dispatchQueueWrapper + configuration: SentryTracerConfiguration(block: { + $0.idleTimeout = idleTimeout + $0.dispatchQueueWrapper = dispatchQueueWrapper + }) ) return tracer } @@ -251,7 +255,7 @@ class SentryTracerTests: XCTestCase { } func testFinish_WithoutHub_DoesntCaptureTransaction() { - let sut = SentryTracer(transactionContext: fixture.transactionContext, hub: nil, waitForChildren: false) + let sut = SentryTracer(transactionContext: fixture.transactionContext, hub: nil) sut.finish() diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index c4563ccd8eb..9aae9da1ab2 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -187,6 +187,7 @@ #import "SentryEnvelopeAttachmentHeader.h" #import "SentryNSProcessInfoWrapper.h" #import "SentryPerformanceTracker+Testing.h" +#import "SentryTracerConfiguration.h" #import "TestSentryViewHierarchy.h" #if SENTRY_HAS_UIKIT From 4988e12aa44a9957d160d7a00a18047cf2d00a9c Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 21 Mar 2023 20:39:15 +0100 Subject: [PATCH 06/12] more test fixes --- Sources/Sentry/SentryUIEventTracker.m | 1 + Tests/SentryTests/Performance/SentryTracerTests.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index 71cce409c44..d99bdf06523 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -129,6 +129,7 @@ - (void)start configuration:[SentryTracerConfiguration configurationWithBlock:^( SentryTracerConfiguration *config) { config.idleTimeout = self.idleTimeout; + config.waitForChildren = YES; config.dispatchQueueWrapper = self.dispatchQueueWrapper; }]]; diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 47b7d734301..fde5ad3dc72 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -99,6 +99,7 @@ class SentryTracerTests: XCTestCase { configuration: SentryTracerConfiguration(block: { $0.idleTimeout = idleTimeout $0.dispatchQueueWrapper = dispatchQueueWrapper + $0.waitForChildren = true }) ) return tracer From ef82379f6264d57ba5dc47749c3b60626329ce8b Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 21 Mar 2023 19:40:50 +0000 Subject: [PATCH 07/12] Format code --- Sources/SentryCrash/Recording/SentryCrash.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/SentryCrash/Recording/SentryCrash.m b/Sources/SentryCrash/Recording/SentryCrash.m index 9e243e38d07..644b4719517 100644 --- a/Sources/SentryCrash/Recording/SentryCrash.m +++ b/Sources/SentryCrash/Recording/SentryCrash.m @@ -377,10 +377,7 @@ - (void)deleteReportWithID:(NSNumber *)reportID // ============================================================================ #define SYNTHESIZE_CRASH_STATE_PROPERTY(TYPE, NAME) \ - -(TYPE)NAME \ - { \ - return sentrycrashstate_currentState()->NAME; \ - } + -(TYPE)NAME { return sentrycrashstate_currentState()->NAME; } SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, activeDurationSinceLastCrash) SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, backgroundDurationSinceLastCrash) From 0d93dece2569711e101dd01ac6eb229f7caf36ed Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 23 Mar 2023 09:29:41 +0100 Subject: [PATCH 08/12] defaultConfiguration --- Sources/Sentry/SentryTracer.m | 6 +++--- Sources/Sentry/SentryTracerConfiguration.m | 5 +++++ Sources/Sentry/include/SentryTracer.h | 2 +- Sources/Sentry/include/SentryTracerConfiguration.h | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index bdde922f969..e532baa6144 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -95,18 +95,18 @@ + (void)initialize - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub { - return [self initWithTransactionContext:transactionContext hub:hub configuration:nil]; + return [self initWithTransactionContext:transactionContext hub:hub configuration:SentryTracerConfiguration.defaultConfiguration]; } - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - configuration:(nullable SentryTracerConfiguration *)configuration; + configuration:(SentryTracerConfiguration *)configuration; { if (!(self = [super initWithContext:transactionContext])) { return nil; } - _configuration = configuration ?: [[SentryTracerConfiguration alloc] init]; + _configuration = configuration; self.transactionContext = transactionContext; _children = [[NSMutableArray alloc] init]; diff --git a/Sources/Sentry/SentryTracerConfiguration.m b/Sources/Sentry/SentryTracerConfiguration.m index 3d7b173a48d..f2e2165a814 100644 --- a/Sources/Sentry/SentryTracerConfiguration.m +++ b/Sources/Sentry/SentryTracerConfiguration.m @@ -2,6 +2,11 @@ @implementation SentryTracerConfiguration + ++ (SentryTracerConfiguration *)defaultConfiguration { + return [[SentryTracerConfiguration alloc] init]; +} + + (SentryTracerConfiguration *)configurationWithBlock:(void (^)(SentryTracerConfiguration *))block { SentryTracerConfiguration *result = [[SentryTracerConfiguration alloc] init]; diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 52d18e9cea0..5ee35f75ae9 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -74,7 +74,7 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; */ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub - configuration:(nullable SentryTracerConfiguration *)configuration; + configuration:(SentryTracerConfiguration *)configuration; - (id)startChildWithParentId:(SentrySpanId *)parentId operation:(NSString *)operation diff --git a/Sources/Sentry/include/SentryTracerConfiguration.h b/Sources/Sentry/include/SentryTracerConfiguration.h index 9779ff4f1b1..2e5c2071b93 100644 --- a/Sources/Sentry/include/SentryTracerConfiguration.h +++ b/Sources/Sentry/include/SentryTracerConfiguration.h @@ -6,6 +6,12 @@ NS_ASSUME_NONNULL_BEGIN @interface SentryTracerConfiguration : NSObject + +/** + * Return an instance of SentryTracerConfiguration with default values. + */ +@property (class, readonly) SentryTracerConfiguration * defaultConfiguration; + /** * Indicates whether the tracer will be finished only if all children have been finished. * If this property is YES and the finish function is called before all children are finished From 81fa1222e9d3b19ebf41ea8011c8d56ef9d8a2b0 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 23 Mar 2023 08:30:54 +0000 Subject: [PATCH 09/12] Format code --- Sources/Sentry/SentryTracer.m | 4 +++- Sources/Sentry/SentryTracerConfiguration.m | 4 ++-- Sources/Sentry/include/SentryTracerConfiguration.h | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index e532baa6144..913eb0ec693 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -95,7 +95,9 @@ + (void)initialize - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext hub:(nullable SentryHub *)hub { - return [self initWithTransactionContext:transactionContext hub:hub configuration:SentryTracerConfiguration.defaultConfiguration]; + return [self initWithTransactionContext:transactionContext + hub:hub + configuration:SentryTracerConfiguration.defaultConfiguration]; } - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transactionContext diff --git a/Sources/Sentry/SentryTracerConfiguration.m b/Sources/Sentry/SentryTracerConfiguration.m index f2e2165a814..c14ec504f4b 100644 --- a/Sources/Sentry/SentryTracerConfiguration.m +++ b/Sources/Sentry/SentryTracerConfiguration.m @@ -2,8 +2,8 @@ @implementation SentryTracerConfiguration - -+ (SentryTracerConfiguration *)defaultConfiguration { ++ (SentryTracerConfiguration *)defaultConfiguration +{ return [[SentryTracerConfiguration alloc] init]; } diff --git a/Sources/Sentry/include/SentryTracerConfiguration.h b/Sources/Sentry/include/SentryTracerConfiguration.h index 2e5c2071b93..25070ff20d3 100644 --- a/Sources/Sentry/include/SentryTracerConfiguration.h +++ b/Sources/Sentry/include/SentryTracerConfiguration.h @@ -6,11 +6,10 @@ NS_ASSUME_NONNULL_BEGIN @interface SentryTracerConfiguration : NSObject - /** * Return an instance of SentryTracerConfiguration with default values. */ -@property (class, readonly) SentryTracerConfiguration * defaultConfiguration; +@property (class, readonly) SentryTracerConfiguration *defaultConfiguration; /** * Indicates whether the tracer will be finished only if all children have been finished. From ac2c5f578587d42c6b27f608f6e13a4bbe328b41 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Fri, 24 Mar 2023 12:46:08 +0100 Subject: [PATCH 10/12] Update SentryTracer.m --- Sources/Sentry/SentryTracer.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 3bd4ff4558a..e5d67646198 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -161,15 +161,14 @@ - (void)dispatchIdleTimeout [_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock]; } __weak SentryTracer *weakSelf = self; - _idleTimeoutBlock = [self.dispatchQueueWrapper createDispatchBlock:^{ + _idleTimeoutBlock = [_configuration.dispatchQueueWrapper createDispatchBlock:^{ if (weakSelf == nil) { SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything."); return; } [weakSelf finishInternal]; - }); - }]; + if (_idleTimeoutBlock == NULL) { SENTRY_LOG_WARN(@"Couln't create idle time out block. Can't schedule idle timeout. " @"Finishing transaction"); @@ -177,7 +176,7 @@ - (void)dispatchIdleTimeout [self finishInternal]; } else { [_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout - block:_idleTimeoutBlock]; + block:_idleTimeoutBlock]; } } From 607bc96770150e8db8f754ebf8c26693d12b716f Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Fri, 24 Mar 2023 13:33:59 +0100 Subject: [PATCH 11/12] fixing hub --- Sources/Sentry/SentryHub.m | 4 ++-- Sources/Sentry/include/SentryHub+Private.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index b0c93df7ef3..470ba5e509d 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -368,7 +368,7 @@ - (SentryId *)captureEvent:(SentryEvent *)event return [self startTransactionWithContext:transactionContext bindToScope:bindToScope customSamplingContext:customSamplingContext - configuration:nil]; + configuration:[SentryTracerConfiguration defaultConfiguration]]; } - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)context @@ -388,7 +388,7 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - configuration:(nullable SentryTracerConfiguration *)configuration + configuration:(SentryTracerConfiguration *)configuration { SentrySamplingContext *samplingContext = [[SentrySamplingContext alloc] initWithTransactionContext:transactionContext diff --git a/Sources/Sentry/include/SentryHub+Private.h b/Sources/Sentry/include/SentryHub+Private.h index 9e764f1847a..57f9ecf6b8d 100644 --- a/Sources/Sentry/include/SentryHub+Private.h +++ b/Sources/Sentry/include/SentryHub+Private.h @@ -37,7 +37,7 @@ SentryHub (Private) - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transactionContext bindToScope:(BOOL)bindToScope customSamplingContext:(NSDictionary *)customSamplingContext - configuration:(nullable SentryTracerConfiguration *)configuration; + configuration:(SentryTracerConfiguration *)configuration; - (SentryId *)captureEvent:(SentryEvent *)event withScope:(SentryScope *)scope From 4c23ae08c85fd9233e1e279e9585cfb4be0a326d Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Fri, 31 Mar 2023 08:37:09 +0000 Subject: [PATCH 12/12] Format code --- Tests/SentryTests/SentryTests-Bridging-Header.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index c4b595a38ad..0e585724534 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -187,9 +187,9 @@ #import "SentryEnvelopeAttachmentHeader.h" #import "SentryNSProcessInfoWrapper.h" #import "SentryPerformanceTracker+Testing.h" -#import "SentryTracerConfiguration.h" #import "SentrySpanOperations.h" #import "SentryTimeToDisplayTracker.h" +#import "SentryTracerConfiguration.h" #import "TestSentryViewHierarchy.h" #if SENTRY_HAS_UIKIT # import "MockUIScene.h"