Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@
7BD4BD4127EB0F0D0071F4FF /* SentryDiscardReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD4BD4027EB0F0C0071F4FF /* SentryDiscardReason.h */; };
7BD4BD4B27EB2DC20071F4FF /* SentryDiscardedEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4BD4A27EB2DC20071F4FF /* SentryDiscardedEventTests.swift */; };
7BD4BD4D27EB31820071F4FF /* SentryClientReportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4BD4C27EB31820071F4FF /* SentryClientReportTests.swift */; };
7BD4E8E627FD84480086C410 /* TestFileManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4E8E527FD84480086C410 /* TestFileManagerDelegate.swift */; };
7BD4E8E827FD95900086C410 /* SentryMigrateSessionInitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4E8E727FD95900086C410 /* SentryMigrateSessionInitTests.m */; };
7BD729962463E83300EA3610 /* SentryDateUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD729952463E83300EA3610 /* SentryDateUtil.h */; };
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD729972463E93500EA3610 /* SentryDateUtil.m */; };
Expand Down Expand Up @@ -1813,7 +1812,6 @@
7BD4BD4027EB0F0C0071F4FF /* SentryDiscardReason.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDiscardReason.h; path = include/SentryDiscardReason.h; sourceTree = "<group>"; };
7BD4BD4A27EB2DC20071F4FF /* SentryDiscardedEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDiscardedEventTests.swift; sourceTree = "<group>"; };
7BD4BD4C27EB31820071F4FF /* SentryClientReportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryClientReportTests.swift; sourceTree = "<group>"; };
7BD4E8E527FD84480086C410 /* TestFileManagerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestFileManagerDelegate.swift; sourceTree = "<group>"; };
7BD4E8E727FD95900086C410 /* SentryMigrateSessionInitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMigrateSessionInitTests.m; sourceTree = "<group>"; };
7BD729952463E83300EA3610 /* SentryDateUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDateUtil.h; path = include/SentryDateUtil.h; sourceTree = "<group>"; };
7BD729972463E93500EA3610 /* SentryDateUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDateUtil.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3587,7 +3585,6 @@
7BBD18BA24530D2600427C76 /* SentryFileManagerTests.swift */,
FA21A2E92E60E9C700E7EADB /* EnvelopeComparison.swift */,
7BD4E8E727FD95900086C410 /* SentryMigrateSessionInitTests.m */,
7BD4E8E527FD84480086C410 /* TestFileManagerDelegate.swift */,
631501BA1EE6F30B00512C5B /* SentrySwizzleTests.m */,
7B34721628086A9D0041F047 /* SentrySwizzleWrapperTests.swift */,
D808FB89281BCE46009A2A33 /* TestSentrySwizzleWrapper.swift */,
Expand Down Expand Up @@ -6019,7 +6016,6 @@
631501BB1EE6F30B00512C5B /* SentrySwizzleTests.m in Sources */,
15D0AC882459EE4D006541C2 /* SentryNSURLRequestTests.swift in Sources */,
7BE3C78724472E9800A38442 /* TestRequestManager.swift in Sources */,
7BD4E8E627FD84480086C410 /* TestFileManagerDelegate.swift in Sources */,
63FE722220DA66EC00CDBAE8 /* SentryCrashJSONCodec_Tests.m in Sources */,
7B0A5452252311CE00A71716 /* SentryBreadcrumbTests.swift in Sources */,
7BE3C7752445C82300A38442 /* SentryCurrentDateTests.swift in Sources */,
Expand Down
12 changes: 8 additions & 4 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ @interface SentryFileManager ()
@property (nonatomic, copy) NSString *appHangEventFilePath;
@property (nonatomic, assign) NSUInteger currentFileCounter;
@property (nonatomic, assign) NSUInteger maxEnvelopes;
@property (nonatomic, weak) id<SentryFileManagerDelegate> delegate;
@property (nonatomic, copy, nullable) void (^envelopeDeletedCallback)
(SentryEnvelopeItem *, SentryDataCategory);

@end

Expand Down Expand Up @@ -200,9 +201,10 @@ - (void)createPathsWithOptions:(SentryOptions *)options
self.envelopesPath = [self.sentryPath stringByAppendingPathComponent:EnvelopesPathComponent];
}

- (void)setDelegate:(id<SentryFileManagerDelegate>)delegate
- (void)setEnvelopeDeletedCallback:(void (^)(
SentryEnvelopeItem *_Nonnull, SentryDataCategory))callback
{
_delegate = delegate;
_envelopeDeletedCallback = callback;
}

#pragma mark - Convenience Accessors
Expand Down Expand Up @@ -1089,7 +1091,9 @@ - (void)handleEnvelopesLimit
continue;
}

[_delegate envelopeItemDeleted:item withCategory:rateLimitCategory];
if (self.envelopeDeletedCallback) {
self.envelopeDeletedCallback(item, rateLimitCategory);
}
}

[self removeFileAtPath:envelopeFilePath];
Expand Down
9 changes: 5 additions & 4 deletions Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ - (id)initWithDsn:(SentryDsn *)dsn
self.discardedEvents = [NSMutableDictionary new];
self.notStoredEnvelopes = [NSMutableArray new];
[self.envelopeRateLimit setDelegate:self];
[self.fileManager setDelegate:self];
typeof(self) __weak weakSelf = self;
[self.fileManager
setEnvelopeDeletedCallback:^(SentryEnvelopeItem *item, SentryDataCategory category) {
[weakSelf envelopeItemDeleted:item withCategory:category];
}];

[self sendAllCachedEnvelopes];

Expand Down Expand Up @@ -260,9 +264,6 @@ - (void)envelopeItemDropped:(SentryEnvelopeItem *)envelopeItem
[self recordLostSpans:envelopeItem reason:kSentryDiscardReasonRateLimitBackoff];
}

/**
* SentryFileManagerDelegate.
*/
- (void)envelopeItemDeleted:(SentryEnvelopeItem *)envelopeItem
withCategory:(SentryDataCategory)dataCategory
{
Expand Down
10 changes: 1 addition & 9 deletions Sources/Sentry/include/SentryFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

NS_ASSUME_NONNULL_BEGIN

@protocol SentryFileManagerDelegate;

@class SentryAppState;
@class SentryDispatchQueueWrapper;
@class SentryEvent;
Expand All @@ -16,12 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
@class SentrySession;

@protocol SentryCurrentDateProvider;
@protocol SentryFileManagerDelegate <NSObject>

- (void)envelopeItemDeleted:(SentryEnvelopeItem *)envelopeItem
withCategory:(SentryDataCategory)dataCategory;

@end

NS_SWIFT_NAME(SentryFileManager)
@interface SentryFileManager : NSObject
Expand All @@ -40,7 +32,7 @@ SENTRY_NO_INIT
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
error:(NSError **)error NS_DESIGNATED_INITIALIZER;

- (void)setDelegate:(id<SentryFileManagerDelegate>)delegate;
- (void)setEnvelopeDeletedCallback:(void (^)(SentryEnvelopeItem *, SentryDataCategory))callback;

#pragma mark - Envelope

Expand Down
3 changes: 1 addition & 2 deletions Sources/Sentry/include/SentryHttpTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface SentryHttpTransport
: NSObject <SentryTransport, SentryEnvelopeRateLimitDelegate, SentryFileManagerDelegate>
@interface SentryHttpTransport : NSObject <SentryTransport, SentryEnvelopeRateLimitDelegate>
SENTRY_NO_INIT

- (id)initWithDsn:(SentryDsn *)dsn
Expand Down
24 changes: 11 additions & 13 deletions Tests/SentryTests/Helper/SentryFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ class SentryFileManagerTests: XCTestCase {
let session = SentrySession(releaseName: "1.0.0", distinctId: "some-id")
let sessionEnvelope: SentryEnvelope

var envelopeItemsDeleted = Invocations<SentryDataCategory>()

let sessionUpdate: SentrySession
let sessionUpdateEnvelope: SentryEnvelope

let expectedSessionUpdate: SentrySession

// swiftlint:disable weak_delegate
// Swiftlint automatically changes this to a weak reference,
// but we need a strong reference to make the test work.
var delegate: TestFileManagerDelegate!
// swiftlint:enable weak_delegate

@available(*, deprecated, message: "This is only marked as deprecated because enableAppLaunchProfiling is marked as deprecated. Once that is removed this can be removed.")
init() throws {
currentDateProvider = TestCurrentDateProvider()
Expand All @@ -56,8 +52,6 @@ class SentryFileManagerTests: XCTestCase {
expectedSessionUpdate = SentrySession(jsonObject: sessionUpdateCopy.serialize())!
// We can only set the init flag after serialize, because the duration is not set if the init flag is set
expectedSessionUpdate.setFlagInit()

delegate = TestFileManagerDelegate()
}

func getSut() -> SentryFileManager {
Expand All @@ -66,7 +60,9 @@ class SentryFileManagerTests: XCTestCase {
dateProvider: currentDateProvider,
dispatchQueueWrapper: dispatchQueueWrapper
)
sut.setDelegate(delegate)
sut.setEnvelopeDeletedCallback { [weak self] _, category in
self?.envelopeItemsDeleted.record(category)
}
return sut
}

Expand All @@ -77,7 +73,9 @@ class SentryFileManagerTests: XCTestCase {
dateProvider: currentDateProvider,
dispatchQueueWrapper: dispatchQueueWrapper
)
sut.setDelegate(delegate)
sut.setEnvelopeDeletedCallback { [weak self] _, category in
self?.envelopeItemsDeleted.record(category)
}
return sut
}

Expand Down Expand Up @@ -359,9 +357,9 @@ class SentryFileManagerTests: XCTestCase {
sut.store(TestConstants.envelope)
}

XCTAssertEqual(4, fixture.delegate.envelopeItemsDeleted.count)
XCTAssertEqual(4, fixture.envelopeItemsDeleted.count)
let expected: [SentryDataCategory] = [.error, .attachment, .session, .error]
XCTAssertEqual(expected, fixture.delegate.envelopeItemsDeleted.invocations)
XCTAssertEqual(expected, fixture.envelopeItemsDeleted.invocations)
}

@available(*, deprecated, message: "This is only marked as deprecated because enableAppLaunchProfiling is marked as deprecated. Once that is removed this can be removed.")
Expand Down Expand Up @@ -499,7 +497,7 @@ class SentryFileManagerTests: XCTestCase {
sut.store(TestConstants.envelope)
}

XCTAssertEqual(0, fixture.delegate.envelopeItemsDeleted.count)
XCTAssertEqual(0, fixture.envelopeItemsDeleted.count)
}

@available(*, deprecated, message: "This is only marked as deprecated because enableAppLaunchProfiling is marked as deprecated. Once that is removed this can be removed.")
Expand Down
10 changes: 0 additions & 10 deletions Tests/SentryTests/Helper/TestFileManagerDelegate.swift

This file was deleted.

Loading