Skip to content

Commit

Permalink
ref: Use SentryTracerConfiguration to initialize SentryTracer (#2821)
Browse files Browse the repository at this point in the history
Instead of having multiple functions to initialize SentryTracer with different configurations we should we one complex object that contains all the configurations.
  • Loading branch information
brustolin committed Apr 5, 2023
1 parent bcd991b commit 33b2f51
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 236 deletions.
8 changes: 8 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,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 */; };
Expand Down Expand Up @@ -1678,6 +1680,8 @@
D8ACE3CA2762187D00F5A213 /* SentryNSDataSwizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryNSDataSwizzling.h; path = include/SentryNSDataSwizzling.h; sourceTree = "<group>"; };
D8ACE3CB2762187D00F5A213 /* SentryNSDataTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryNSDataTracker.h; path = include/SentryNSDataTracker.h; sourceTree = "<group>"; };
D8ACE3CC2762187D00F5A213 /* SentryFileIOTrackingIntegration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryFileIOTrackingIntegration.h; path = include/SentryFileIOTrackingIntegration.h; sourceTree = "<group>"; };
D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = "<group>"; };
D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = "<group>"; };
D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshotIntegrationTests.swift; sourceTree = "<group>"; };
D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryScreenShot.swift; sourceTree = "<group>"; };
D8BBD32628FD9FBF0011F850 /* SentrySwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySwift.h; path = include/SentrySwift.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3140,6 +3144,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 */,
Expand Down Expand Up @@ -3490,6 +3496,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 */,
Expand Down Expand Up @@ -3843,6 +3850,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 */,
Expand Down
43 changes: 6 additions & 37 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,8 @@ - (SentryId *)captureEvent:(SentryEvent *)event
{
return [self startTransactionWithContext:transactionContext
bindToScope:bindToScope
waitForChildren:NO
customSamplingContext:customSamplingContext
timerWrapper:nil];
configuration:[SentryTracerConfiguration defaultConfiguration]];
}

- (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)context
Expand All @@ -388,41 +387,10 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con
parentSampled:context.parentSampled];
}

- (id<SentrySpan>)startTransactionWithContext:(SentryTransactionContext *)transactionContext
bindToScope:(BOOL)bindToScope
waitForChildren:(BOOL)waitForChildren
customSamplingContext:(NSDictionary<NSString *, id> *)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<SentrySpan> 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<NSString *, id> *)customSamplingContext
idleTimeout:(NSTimeInterval)idleTimeout
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
configuration:(SentryTracerConfiguration *)configuration
{
SentrySamplingContext *samplingContext =
[[SentrySamplingContext alloc] initWithTransactionContext:transactionContext
Expand All @@ -436,11 +404,12 @@ - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transa
SentryProfilesSamplerDecision *profilesSamplerDecision =
[_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision];

configuration.profilesSamplerDecision = profilesSamplerDecision;

SentryTracer *tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext
hub:self
profilesSamplerDecision:profilesSamplerDecision
idleTimeout:idleTimeout
dispatchQueueWrapper:dispatchQueueWrapper];
configuration:configuration];

if (bindToScope)
self.scope.span = tracer;

Expand Down
14 changes: 9 additions & 5 deletions Sources/Sentry/SentryPerformanceTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ - (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];

newSpan = [SentrySDK.currentHub
startTransactionWithContext:context
bindToScope:bindToScope
customSamplingContext:@{}
configuration:[SentryTracerConfiguration configurationWithBlock:^(
SentryTracerConfiguration *configuration) {
configuration.waitForChildren = YES;
}]];

[(SentryTracer *)newSpan setDelegate:self];
}];
Expand Down

0 comments on commit 33b2f51

Please sign in to comment.