Skip to content

Commit 40fed5b

Browse files
author
Robert Bartoszewski
committed
Tracer refactor: span store
1 parent b203816 commit 40fed5b

File tree

13 files changed

+187
-205
lines changed

13 files changed

+187
-205
lines changed

BugsnagPerformance.xcodeproj/project.pbxproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
094FA7472B10EDE700112ED4 /* BugsnagPerformanceSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 094FA7322B10EDE600112ED4 /* BugsnagPerformanceSwift.framework */; };
5353
094FA7482B10EDE700112ED4 /* BugsnagPerformanceSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 094FA7322B10EDE600112ED4 /* BugsnagPerformanceSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5454
094FA7522B10EEB600112ED4 /* BugsnagPerformance.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72E4BB63359EA30E80116E2A /* BugsnagPerformance.framework */; };
55-
09509B752ADFE9A900A358EC /* TracerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 09509B742ADFE9A900A358EC /* TracerTests.mm */; };
5655
096CBC172B1752F700534F0C /* BugsnagPerformanceSwiftUIInstrumentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 096CBC152B1752F100534F0C /* BugsnagPerformanceSwiftUIInstrumentation.swift */; };
5756
09856B9E2B9606A500620907 /* BugsnagPerformanceSwiftUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094FA7422B10EDE700112ED4 /* BugsnagPerformanceSwiftUITests.swift */; };
5857
0986B7C02B287C9D00BD2CA3 /* WeakSpansList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0986B7BF2B287C9D00BD2CA3 /* WeakSpansList.mm */; };
@@ -188,6 +187,9 @@
188187
967949B62E97CC9E005FD87F /* SpanLifecycleHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 967949B52E97CC95005FD87F /* SpanLifecycleHandler.h */; };
189188
967949B82E97CCA9005FD87F /* SpanLifecycleHandlerImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 967949B72E97CCA6005FD87F /* SpanLifecycleHandlerImpl.mm */; };
190189
967949BA2E97D5A5005FD87F /* SpanLifecycleHandlerImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 967949B92E97D59B005FD87F /* SpanLifecycleHandlerImpl.h */; };
190+
967949BD2E99373E005FD87F /* SpanStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 967949BC2E993735005FD87F /* SpanStore.h */; };
191+
967949BF2E993749005FD87F /* SpanStoreImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 967949BE2E993742005FD87F /* SpanStoreImpl.h */; };
192+
967949C12E993750005FD87F /* SpanStoreImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 967949C02E99374E005FD87F /* SpanStoreImpl.mm */; };
191193
967F6F1829C3783B0054EED8 /* BugsnagPerformanceConfiguration+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 967F6F1729C3782D0054EED8 /* BugsnagPerformanceConfiguration+Private.h */; };
192194
968AA5FB2CCA5A9200BA69CF /* BSGPerformanceSharedSessionProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 968AA5FA2CCA5A9200BA69CF /* BSGPerformanceSharedSessionProxy.h */; };
193195
968AA5FD2CCA5AB000BA69CF /* BSGPerformanceSharedSessionProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 968AA5FC2CCA5AB000BA69CF /* BSGPerformanceSharedSessionProxy.mm */; };
@@ -408,7 +410,6 @@
408410
094FA7352B10EDE600112ED4 /* BugsnagPerformanceSwift.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = BugsnagPerformanceSwift.docc; sourceTree = "<group>"; };
409411
094FA73B2B10EDE700112ED4 /* BugsnagPerformanceSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BugsnagPerformanceSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
410412
094FA7422B10EDE700112ED4 /* BugsnagPerformanceSwiftUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BugsnagPerformanceSwiftUITests.swift; sourceTree = "<group>"; };
411-
09509B742ADFE9A900A358EC /* TracerTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TracerTests.mm; sourceTree = "<group>"; };
412413
096CBC152B1752F100534F0C /* BugsnagPerformanceSwiftUIInstrumentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BugsnagPerformanceSwiftUIInstrumentation.swift; sourceTree = "<group>"; };
413414
0986B7BF2B287C9D00BD2CA3 /* WeakSpansList.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WeakSpansList.mm; sourceTree = "<group>"; };
414415
0987F2772C32D4AD00777FD8 /* BugsnagPerformanceSpanContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagPerformanceSpanContext.h; sourceTree = "<group>"; };
@@ -546,6 +547,9 @@
546547
967949B52E97CC95005FD87F /* SpanLifecycleHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpanLifecycleHandler.h; sourceTree = "<group>"; };
547548
967949B72E97CCA6005FD87F /* SpanLifecycleHandlerImpl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SpanLifecycleHandlerImpl.mm; sourceTree = "<group>"; };
548549
967949B92E97D59B005FD87F /* SpanLifecycleHandlerImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpanLifecycleHandlerImpl.h; sourceTree = "<group>"; };
550+
967949BC2E993735005FD87F /* SpanStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpanStore.h; sourceTree = "<group>"; };
551+
967949BE2E993742005FD87F /* SpanStoreImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpanStoreImpl.h; sourceTree = "<group>"; };
552+
967949C02E99374E005FD87F /* SpanStoreImpl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SpanStoreImpl.mm; sourceTree = "<group>"; };
549553
967F6F1729C3782D0054EED8 /* BugsnagPerformanceConfiguration+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagPerformanceConfiguration+Private.h"; sourceTree = "<group>"; };
550554
968AA5FA2CCA5A9200BA69CF /* BSGPerformanceSharedSessionProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BSGPerformanceSharedSessionProxy.h; sourceTree = "<group>"; };
551555
968AA5FC2CCA5AB000BA69CF /* BSGPerformanceSharedSessionProxy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BSGPerformanceSharedSessionProxy.mm; sourceTree = "<group>"; };
@@ -867,6 +871,7 @@
867871
CB7FD935299D330500499E13 /* SpanOptions.h */,
868872
96D55C7D2A1EA5A8006D1F29 /* SpanStackingHandler.h */,
869873
96D55C7F2A1EA5C6006D1F29 /* SpanStackingHandler.mm */,
874+
967949BB2E99372C005FD87F /* SpanStore */,
870875
CBEBE59129F2783C00BF0B4F /* Swizzle.h */,
871876
CBEBE59029F2783C00BF0B4F /* Swizzle.mm */,
872877
098FC8532D37A08D001B627D /* SystemInfoSampler.h */,
@@ -947,7 +952,6 @@
947952
CB2B8A9A2A0924A50054FBBE /* SpanTests.mm */,
948953
098FC87A2D3FD095001B627D /* TestHelpers.h */,
949954
CB747D20299E5458003CA1B4 /* TimeTests.mm */,
950-
09509B742ADFE9A900A358EC /* TracerTests.mm */,
951955
09B473092B2313570024CF11 /* WeakSpansListTests.mm */,
952956
CB0AD75A295F27DD002A3FB6 /* WorkerTests.mm */,
953957
);
@@ -1197,6 +1201,16 @@
11971201
path = SpanLifecycle;
11981202
sourceTree = "<group>";
11991203
};
1204+
967949BB2E99372C005FD87F /* SpanStore */ = {
1205+
isa = PBXGroup;
1206+
children = (
1207+
967949BC2E993735005FD87F /* SpanStore.h */,
1208+
967949BE2E993742005FD87F /* SpanStoreImpl.h */,
1209+
967949C02E99374E005FD87F /* SpanStoreImpl.mm */,
1210+
);
1211+
path = SpanStore;
1212+
sourceTree = "<group>";
1213+
};
12001214
969EE0EE2E7872A600600F63 /* SpanFactory */ = {
12011215
isa = PBXGroup;
12021216
children = (
@@ -1331,6 +1345,7 @@
13311345
0122C24C29019770002D243C /* NetworkInstrumentation.h in Headers */,
13321346
962CE8352E67972300380522 /* NetworkSpanFactoryImpl.h in Headers */,
13331347
962CE7CE2E60766000380522 /* ViewLoadInstrumentationStateRepository.h in Headers */,
1348+
967949BD2E99373E005FD87F /* SpanStore.h in Headers */,
13341349
963726C12DEA4E5700C739E6 /* BugsnagPerformancePriority.h in Headers */,
13351350
962CE7E82E6123E700380522 /* ViewLoadLoadingIndicatorsHandlerImpl.h in Headers */,
13361351
962CE7E92E6123E700380522 /* ViewLoadLoadingIndicatorsHandler.h in Headers */,
@@ -1371,6 +1386,7 @@
13711386
09B473072B23087D0024CF11 /* WeakSpansList.h in Headers */,
13721387
96F1292B2DCCB9B900A6FB2B /* BugsnagPerformanceRemoteSpanContext.h in Headers */,
13731388
962CE8282E67189800380522 /* NetworkEarlyPhaseHandlerImpl.h in Headers */,
1389+
967949BF2E993749005FD87F /* SpanStoreImpl.h in Headers */,
13741390
09F23A8C2CE351ED00F0D769 /* BugsnagSwiftTools.h in Headers */,
13751391
0921F02B2A67CBD600C764EB /* BugsnagPerformanceNetworkRequestInfo.h in Headers */,
13761392
962CE7D52E60967A00380522 /* BugsnagPerformanceLoadingIndicatorView+Private.h in Headers */,
@@ -1736,7 +1752,6 @@
17361752
09E313042BF363020081F219 /* CrossTalkTests.mm in Sources */,
17371753
CB747D21299E5458003CA1B4 /* TimeTests.mm in Sources */,
17381754
0122C27129019CEF002D243C /* OtlpTraceEncodingTests.mm in Sources */,
1739-
09509B752ADFE9A900A358EC /* TracerTests.mm in Sources */,
17401755
098FC8792D3FADFE001B627D /* SpanAttributesTests.mm in Sources */,
17411756
962F80F229DB03A400BE82BC /* PerformanceMicrobenchmarkTests.swift in Sources */,
17421757
CB747D1F299E4984003CA1B4 /* SpanOptionsTests.mm in Sources */,
@@ -1812,6 +1827,7 @@
18121827
09F23A8D2CE351ED00F0D769 /* BugsnagSwiftTools.m in Sources */,
18131828
962CE8302E673A9900380522 /* NetworkLifecycleHandlerImpl.mm in Sources */,
18141829
968AA5FD2CCA5AB000BA69CF /* BSGPerformanceSharedSessionProxy.mm in Sources */,
1830+
967949C12E993750005FD87F /* SpanStoreImpl.mm in Sources */,
18151831
964B78562D4B924C00FF077D /* BugsnagPerformanceSpanCondition.mm in Sources */,
18161832
CBEC51DD2976F1F9009C0CE3 /* RetryQueue.mm in Sources */,
18171833
01A414CE2913C0F0003152A4 /* SpanAttributes.mm in Sources */,

Sources/BugsnagPerformance/Private/BugsnagPerformanceImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#import "SpanFactory/ViewLoad/ViewLoadSpanFactoryImpl.h"
3737
#import "SpanFactory/Network/NetworkSpanFactoryImpl.h"
3838
#import "SpanLifecycle/SpanLifecycleHandlerImpl.h"
39+
#import "SpanStore/SpanStoreImpl.h"
3940

4041
#import <mutex>
4142

@@ -109,6 +110,7 @@ class BugsnagPerformanceImpl: public PhasedStartup {
109110
std::shared_ptr<AppStartupSpanFactoryImpl> appStartupSpanFactory_;
110111
std::shared_ptr<ViewLoadSpanFactoryImpl> viewLoadSpanFactory_;
111112
std::shared_ptr<NetworkSpanFactoryImpl> networkSpanFactory_;
113+
std::shared_ptr<SpanStoreImpl> spanStore_;
112114
std::shared_ptr<SpanLifecycleHandlerImpl> spanLifecycleHandler_;
113115
std::shared_ptr<Tracer> tracer_;
114116
std::unique_ptr<RetryQueue> retryQueue_;

Sources/BugsnagPerformance/Private/BugsnagPerformanceImpl.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
, appStartupSpanFactory_(std::make_shared<AppStartupSpanFactoryImpl>(plainSpanFactory_, spanAttributesProvider_))
5757
, viewLoadSpanFactory_(std::make_shared<ViewLoadSpanFactoryImpl>(plainSpanFactory_, spanAttributesProvider_))
5858
, networkSpanFactory_(std::make_shared<NetworkSpanFactoryImpl>(plainSpanFactory_, spanAttributesProvider_))
59-
, spanLifecycleHandler_(std::make_shared<SpanLifecycleHandlerImpl>(sampler_, spanStackingHandler_, conditionTimeoutExecutor_, plainSpanFactory_, batch_, frameMetricsCollector_, spanStartCallbacks_, spanEndCallbacks_, ^{this->onSpanStarted();}))
60-
, tracer_(std::make_shared<Tracer>(plainSpanFactory_, viewLoadSpanFactory_, networkSpanFactory_, spanLifecycleHandler_, spanStackingHandler_))
59+
, spanStore_(std::make_shared<SpanStoreImpl>(spanStackingHandler_))
60+
, spanLifecycleHandler_(std::make_shared<SpanLifecycleHandlerImpl>(sampler_, spanStore_, conditionTimeoutExecutor_, plainSpanFactory_, batch_, frameMetricsCollector_, spanStartCallbacks_, spanEndCallbacks_, ^{this->onSpanStarted();}))
61+
, tracer_(std::make_shared<Tracer>(plainSpanFactory_, viewLoadSpanFactory_, networkSpanFactory_, spanLifecycleHandler_, spanStore_))
6162
, retryQueue_(std::make_unique<RetryQueue>([persistence_->bugsnagPerformanceDir() stringByAppendingPathComponent:@"retry-queue"]))
6263
, appStateTracker_(appStateTracker)
6364
, viewControllersToSpans_([NSMapTable mapTableWithKeyOptions:NSMapTableWeakMemory | NSMapTableObjectPointerPersonality
@@ -418,7 +419,7 @@
418419

419420
bool BugsnagPerformanceImpl::sweepTracerTask() noexcept {
420421
BSGLogDebug(@"BugsnagPerformanceImpl::sweepTracerTask()");
421-
spanLifecycleHandler_->sweep();
422+
spanStore_->sweep();
422423
// Never auto-repeat this task, even if work was done; it can wait.
423424
return false;
424425
}

Sources/BugsnagPerformance/Private/ConditionTimeoutExecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ConditionTimeoutExecutor {
1919
ConditionTimeoutExecutor() noexcept {};
2020
~ConditionTimeoutExecutor() {};
2121

22-
void sheduleTimeout(BugsnagPerformanceSpanCondition *condition, NSTimeInterval timeout) noexcept {
22+
void scheduleTimeout(BugsnagPerformanceSpanCondition *condition, NSTimeInterval timeout) noexcept {
2323
std::lock_guard<std::mutex> guard(mutex_);
2424
this->conditionIdToTimer_[condition.conditionId] = [NSTimer scheduledTimerWithTimeInterval:timeout repeats:NO block:^(NSTimer *) {
2525
[condition didTimeout];

Sources/BugsnagPerformance/Private/SpanLifecycle/SpanLifecycleHandlerImpl.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "../ConditionTimeoutExecutor.h"
1818
#import "../BSGPrioritizedStore.h"
1919
#import "../WeakSpansList.h"
20+
#import "../SpanStore/SpanStore.h"
2021

2122
#import <mutex>
2223

@@ -25,7 +26,7 @@ namespace bugsnag {
2526
class SpanLifecycleHandlerImpl: public SpanLifecycleHandler {
2627
public:
2728
SpanLifecycleHandlerImpl(std::shared_ptr<Sampler> sampler,
28-
std::shared_ptr<SpanStackingHandler> spanStackingHandler,
29+
std::shared_ptr<SpanStore> store,
2930
std::shared_ptr<ConditionTimeoutExecutor> conditionTimeoutExecutor,
3031
std::shared_ptr<PlainSpanFactoryImpl> plainSpanFactory,
3132
std::shared_ptr<Batch> batch,
@@ -34,16 +35,14 @@ class SpanLifecycleHandlerImpl: public SpanLifecycleHandler {
3435
BSGPrioritizedStore<BugsnagPerformanceSpanEndCallback> *onSpanEndCallbacks,
3536
void (^onSpanStarted)()) noexcept
3637
: sampler_(sampler)
37-
, spanStackingHandler_(spanStackingHandler)
38+
, store_(store)
3839
, conditionTimeoutExecutor_(conditionTimeoutExecutor)
3940
, plainSpanFactory_(plainSpanFactory)
4041
, batch_(batch)
4142
, frameMetricsCollector_(frameMetricsCollector)
4243
, onSpanStartCallbacks_(onSpanStartCallbacks)
4344
, onSpanEndCallbacks_(onSpanEndCallbacks)
44-
, onSpanStarted_(onSpanStarted)
45-
, blockedSpans_([NSMutableArray new])
46-
, potentiallyOpenSpans_(std::make_shared<WeakSpansList>()) {}
45+
, onSpanStarted_(onSpanStarted) {}
4746

4847
void earlyConfigure(BSGEarlyConfiguration *) noexcept {}
4948
void earlySetup() noexcept {}
@@ -62,27 +61,22 @@ class SpanLifecycleHandlerImpl: public SpanLifecycleHandler {
6261
BugsnagPerformanceSpanCondition *onSpanBlocked(BugsnagPerformanceSpan *blocked, NSTimeInterval timeout) noexcept;
6362
void onSpanCancelled(BugsnagPerformanceSpan *span) noexcept;
6463

65-
void sweep() noexcept;
66-
6764
private:
6865

6966
std::shared_ptr<Sampler> sampler_;
70-
std::shared_ptr<SpanStackingHandler> spanStackingHandler_;
7167
std::shared_ptr<ConditionTimeoutExecutor> conditionTimeoutExecutor_;
7268
std::shared_ptr<PlainSpanFactoryImpl> plainSpanFactory_;
69+
std::shared_ptr<SpanStore> store_;
7370
FrameMetricsCollector *frameMetricsCollector_;
7471
bool isStarted_{false};
7572
void (^onSpanStarted_)(){ ^(){} };
7673

7774
std::shared_ptr<Batch> batch_;
78-
std::shared_ptr<WeakSpansList> potentiallyOpenSpans_;
79-
NSMutableArray<BugsnagPerformanceSpan *> *blockedSpans_;
8075
BSGPrioritizedStore<BugsnagPerformanceSpanStartCallback> *onSpanStartCallbacks_;
8176
BSGPrioritizedStore<BugsnagPerformanceSpanEndCallback> *onSpanEndCallbacks_;
8277
BugsnagPerformanceEnabledMetrics *enabledMetrics_{[BugsnagPerformanceEnabledMetrics withAllEnabled]};
8378

8479
void processClosedSpan(BugsnagPerformanceSpan *span) noexcept;
85-
void cancelQueuedSpan(BugsnagPerformanceSpan *span) noexcept;
8680
bool shouldInstrumentRendering(BugsnagPerformanceSpan *span) noexcept;
8781
void processFrameMetrics(BugsnagPerformanceSpan *span) noexcept;
8882
void callOnSpanStartCallbacks(BugsnagPerformanceSpan *span) noexcept;

Sources/BugsnagPerformance/Private/SpanLifecycle/SpanLifecycleHandlerImpl.mm

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
if (shouldInstrumentRendering(span)) {
2323
span.startFramerateSnapshot = [frameMetricsCollector_ currentSnapshot];
2424
}
25-
if (options.makeCurrentContext) {
26-
spanStackingHandler_->push(span);
27-
}
28-
potentiallyOpenSpans_->add(span);
25+
store_->addNewSpan(span, options.makeCurrentContext);
2926
callOnSpanStartCallbacks(span);
3027
onSpanStarted_();
3128
}
@@ -41,10 +38,6 @@
4138
SpanLifecycleHandlerImpl::onSpanClosed(BugsnagPerformanceSpan *span) noexcept {
4239
if (!span.isBlocked) {
4340
processClosedSpan(span);
44-
} else {
45-
@synchronized (this->blockedSpans_) {
46-
[blockedSpans_ addObject:span];
47-
}
4841
}
4942
}
5043

@@ -63,9 +56,8 @@
6356
}
6457
} onUpgradedCallback:^BugsnagPerformanceSpanContext *(BugsnagPerformanceSpanCondition *c) {
6558
__strong BugsnagPerformanceSpan *strongSpan = c.span;
66-
@synchronized (this->blockedSpans_) {
67-
this->conditionTimeoutExecutor_->cancelTimeout(c);
68-
}
59+
this->conditionTimeoutExecutor_->cancelTimeout(c);
60+
6961
@synchronized (c) {
7062
if (c.isActive) {
7163
return strongSpan;
@@ -76,22 +68,24 @@
7668
[condition addOnDeactivatedCallback:^(BugsnagPerformanceSpanCondition *c) {
7769
__strong BugsnagPerformanceSpan *strongSpan = c.span;
7870
if (strongSpan.state == SpanStateEnded && !strongSpan.isBlocked) {
79-
@synchronized (this->blockedSpans_) {
80-
[this->blockedSpans_ removeObject:strongSpan];
81-
this->conditionTimeoutExecutor_->cancelTimeout(c);
82-
}
71+
this->store_->removeSpanFromBlocked(span);
72+
this->conditionTimeoutExecutor_->cancelTimeout(c);
8373
this->onSpanClosed(strongSpan);
8474
}
8575
}];
86-
this->conditionTimeoutExecutor_->sheduleTimeout(condition, timeout);
76+
conditionTimeoutExecutor_->scheduleTimeout(condition, timeout);
77+
store_->addSpanToBlocked(span);
8778
return condition;
8879
}
8980

9081
void
9182
SpanLifecycleHandlerImpl::onSpanCancelled(BugsnagPerformanceSpan *span) noexcept {
92-
if (span) {
93-
batch_->removeSpan(span.traceIdHi, span.traceIdLo, span.spanId);
94-
[blockedSpans_ removeObject:span];
83+
if (!span) {
84+
return;
85+
}
86+
batch_->removeSpan(span.traceIdHi, span.traceIdLo, span.spanId);
87+
if (span.isBlocked) {
88+
store_->removeSpanFromBlocked(span);
9589
}
9690
}
9791

@@ -225,15 +219,9 @@
225219

226220
void
227221
SpanLifecycleHandlerImpl::abortAllOpenSpans() noexcept {
228-
potentiallyOpenSpans_->abortAllOpen();
229-
}
230-
231-
void
232-
SpanLifecycleHandlerImpl::sweep() noexcept {
233-
constexpr unsigned minEntriesBeforeCompacting = 10000;
234-
if (potentiallyOpenSpans_->count() >= minEntriesBeforeCompacting) {
235-
potentiallyOpenSpans_->compact();
236-
}
222+
store_->performActionAndClearOpenSpans(^(BugsnagPerformanceSpan *span) {
223+
[span abortIfOpen];
224+
});
237225
}
238226

239227
void
@@ -244,7 +232,7 @@
244232
}
245233
}
246234

247-
spanStackingHandler_->onSpanClosed(span.spanId);
235+
store_->removeSpan(span);
248236

249237
if(span.state == SpanStateAborted) {
250238
return;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// SpanStore.h
3+
// BugsnagPerformance
4+
//
5+
// Created by Robert Bartoszewski on 10/10/2025.
6+
// Copyright © 2025 Bugsnag. All rights reserved.
7+
//
8+
9+
#import <BugsnagPerformance/BugsnagPerformanceSpan.h>
10+
11+
namespace bugsnag {
12+
13+
/**
14+
* SpanStore keeps track of all open spans. It allows adding and removing spans,
15+
* quering the current stack as well as performing actions on all open spans
16+
* (e.g., when the app goes to background).
17+
*/
18+
class SpanStore {
19+
public:
20+
virtual void addNewSpan(BugsnagPerformanceSpan *span, bool makeCurrentContext) noexcept = 0;
21+
virtual void removeSpan(BugsnagPerformanceSpan *span) noexcept = 0;
22+
virtual void performActionAndClearOpenSpans(void (^action)(BugsnagPerformanceSpan *span)) noexcept = 0;
23+
24+
virtual void addSpanToBlocked(BugsnagPerformanceSpan *span) noexcept = 0;
25+
virtual void removeSpanFromBlocked(BugsnagPerformanceSpan *span) noexcept = 0;
26+
27+
virtual bool hasSpanOnCurrentStack(NSString *attribute, NSString *value) noexcept = 0;
28+
virtual void sweep() noexcept = 0;
29+
30+
virtual ~SpanStore() {}
31+
};
32+
}

0 commit comments

Comments
 (0)