Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ee2130b
Add a 0.1 second delay when sending the next cached envelop
kevinrenskers Oct 5, 2022
29ea096
"Once the device is back online, read events preciously cached (as op…
kevinrenskers Oct 5, 2022
24320b5
Changelog
kevinrenskers Oct 5, 2022
f00a755
Fix the test - TestSentryDispatchQueueWrapper didn't actually execute…
kevinrenskers Oct 6, 2022
6e1f95b
Don't break the other tests
kevinrenskers Oct 6, 2022
841155e
SentryReachability doesn't work on WatchOS
kevinrenskers Oct 6, 2022
f025557
SentryReachability doesn't work on WatchOS
kevinrenskers Oct 6, 2022
91b6b37
Fix
kevinrenskers Oct 6, 2022
919beca
Add more tests
kevinrenskers Oct 6, 2022
9c6f33a
Solve duplicate symbol problem
kevinrenskers Oct 6, 2022
6328bdd
Some renamings, and added a constant
kevinrenskers Oct 11, 2022
bad0243
Silence wrong analyzer warning
kevinrenskers Oct 11, 2022
4771248
New version of SentryReachability
kevinrenskers Oct 11, 2022
940a1bb
No need for this logic, SentryReachability already does this internally
kevinrenskers Oct 11, 2022
1fd8fb5
Update Sources/Sentry/SentryReachability.m
kevinrenskers Oct 11, 2022
5145e67
Update Sources/Sentry/Public/SentryDefines.h
kevinrenskers Oct 11, 2022
596e8aa
Use name cachedEnvelopeSendDelay
kevinrenskers Oct 11, 2022
e20150f
Merge branch 'master' into feat/1671-offline-cache-improvements
kevinrenskers Oct 13, 2022
d9a88e0
Fix for watchOS
kevinrenskers Oct 13, 2022
70e46ab
Use an array of reachability callbacks, one for each class instance
kevinrenskers Oct 14, 2022
c2da56f
Added testUniqueKeyForInstances test
kevinrenskers Oct 14, 2022
1a00f47
testSendsWhenNetworkComesBack
kevinrenskers Oct 14, 2022
25f8821
Merge branch 'master' into feat/1671-offline-cache-improvements
kevinrenskers Oct 19, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Offline caching improvements (#2263)
- Report usage of stitchAsyncCode (#2281)

## 7.28.0
Expand Down
16 changes: 16 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@
0A6EEADD28A657970076B469 /* UIViewRecursiveDescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6EEADC28A657970076B469 /* UIViewRecursiveDescriptionTests.swift */; };
0A8F0A392886CC70000B15F6 /* SentryPermissionsObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 0AABE2EE288592750057ED69 /* SentryPermissionsObserver.h */; };
0A94158228F6C4C2006A5DD1 /* SentryAppStateManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A94158128F6C4C2006A5DD1 /* SentryAppStateManagerTests.swift */; };
0A9415BA28F96CAC006A5DD1 /* TestSentryReachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9415B928F96CAC006A5DD1 /* TestSentryReachability.swift */; };
0A9BF4E228A114940068D266 /* SentryViewHierarchyIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A9BF4E128A114940068D266 /* SentryViewHierarchyIntegration.m */; };
0A9BF4E428A114B50068D266 /* SentryViewHierarchyIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A9BF4E328A114B50068D266 /* SentryViewHierarchyIntegration.h */; };
0A9BF4E928A125390068D266 /* TestSentryViewHierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9BF4E628A123270068D266 /* TestSentryViewHierarchy.swift */; };
0A9BF4EB28A127120068D266 /* SentryViewHierarchyIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9BF4EA28A127120068D266 /* SentryViewHierarchyIntegrationTests.swift */; };
0A9E917128DC7E7000FB4182 /* SentryInternalDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A9E917028DC7E7000FB4182 /* SentryInternalDefines.h */; };
0AABE2ED2885924A0057ED69 /* SentryPermissionsObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AABE2EC2885924A0057ED69 /* SentryPermissionsObserver.m */; };
0AAE201E28ED9B9400D0CD80 /* SentryReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AAE201D28ED9B9400D0CD80 /* SentryReachability.m */; };
0AAE202128ED9BCC00D0CD80 /* SentryReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 0AAE202028ED9BCC00D0CD80 /* SentryReachability.h */; };
0ACBA10128A6406400D711F7 /* UIView+Sentry.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ACBA10028A6406400D711F7 /* UIView+Sentry.m */; };
0ACBA10328A6407200D711F7 /* UIView+Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 0ACBA10228A6407200D711F7 /* UIView+Sentry.h */; };
0ADC33EC28D9BB780078D980 /* SentryUIDeviceWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC33EB28D9BB780078D980 /* SentryUIDeviceWrapper.m */; };
0ADC33EE28D9BB890078D980 /* SentryUIDeviceWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 0ADC33ED28D9BB890078D980 /* SentryUIDeviceWrapper.h */; };
0ADC33F128D9BE940078D980 /* TestSentryUIDeviceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */; };
0AE455AD28F584D2006680E5 /* SentryReachabilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AE455AC28F584D2006680E5 /* SentryReachabilityTests.m */; };
15360CCF2432777500112302 /* SentrySessionTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CCE2432777400112302 /* SentrySessionTracker.m */; };
15360CD2243277A000112302 /* SentrySessionTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 15360CD12432779F00112302 /* SentrySessionTracker.h */; };
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */; };
Expand Down Expand Up @@ -766,6 +770,7 @@
0A56DA5E28ABA01B00C400D5 /* SentryTransactionContext+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryTransactionContext+Private.h"; path = "include/SentryTransactionContext+Private.h"; sourceTree = "<group>"; };
0A6EEADC28A657970076B469 /* UIViewRecursiveDescriptionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewRecursiveDescriptionTests.swift; sourceTree = "<group>"; };
0A94158128F6C4C2006A5DD1 /* SentryAppStateManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryAppStateManagerTests.swift; sourceTree = "<group>"; };
0A9415B928F96CAC006A5DD1 /* TestSentryReachability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryReachability.swift; sourceTree = "<group>"; };
0A9BF4E128A114940068D266 /* SentryViewHierarchyIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryViewHierarchyIntegration.m; sourceTree = "<group>"; };
0A9BF4E328A114B50068D266 /* SentryViewHierarchyIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryViewHierarchyIntegration.h; path = include/SentryViewHierarchyIntegration.h; sourceTree = "<group>"; };
0A9BF4E628A123270068D266 /* TestSentryViewHierarchy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryViewHierarchy.swift; sourceTree = "<group>"; };
Expand All @@ -774,11 +779,14 @@
0AABE2EC2885924A0057ED69 /* SentryPermissionsObserver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryPermissionsObserver.m; sourceTree = "<group>"; };
0AABE2EE288592750057ED69 /* SentryPermissionsObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryPermissionsObserver.h; path = include/SentryPermissionsObserver.h; sourceTree = "<group>"; };
0AABE2EF2885C2120057ED69 /* TestSentryPermissionsObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryPermissionsObserver.swift; sourceTree = "<group>"; };
0AAE201D28ED9B9400D0CD80 /* SentryReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryReachability.m; sourceTree = "<group>"; };
0AAE202028ED9BCC00D0CD80 /* SentryReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryReachability.h; path = include/SentryReachability.h; sourceTree = "<group>"; };
0ACBA10028A6406400D711F7 /* UIView+Sentry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIView+Sentry.m"; sourceTree = "<group>"; };
0ACBA10228A6407200D711F7 /* UIView+Sentry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIView+Sentry.h"; path = "include/UIView+Sentry.h"; sourceTree = "<group>"; };
0ADC33EB28D9BB780078D980 /* SentryUIDeviceWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUIDeviceWrapper.m; sourceTree = "<group>"; };
0ADC33ED28D9BB890078D980 /* SentryUIDeviceWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUIDeviceWrapper.h; path = include/SentryUIDeviceWrapper.h; sourceTree = "<group>"; };
0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryUIDeviceWrapper.swift; sourceTree = "<group>"; };
0AE455AC28F584D2006680E5 /* SentryReachabilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryReachabilityTests.m; sourceTree = "<group>"; };
15360CCE2432777400112302 /* SentrySessionTracker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySessionTracker.m; sourceTree = "<group>"; };
15360CD12432779F00112302 /* SentrySessionTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySessionTracker.h; path = include/SentrySessionTracker.h; sourceTree = "<group>"; };
15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryAutoSessionTrackingIntegration.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1575,6 +1583,8 @@
638DC99F1EBC6B6400A66E41 /* SentryRequestOperation.m */,
7BDB03B6251364F800BAE198 /* SentryDispatchQueueWrapper.h */,
7BDB03BA2513652900BAE198 /* SentryDispatchQueueWrapper.m */,
0AAE202028ED9BCC00D0CD80 /* SentryReachability.h */,
0AAE201D28ED9B9400D0CD80 /* SentryReachability.m */,
);
name = Networking;
sourceTree = "<group>";
Expand Down Expand Up @@ -2385,6 +2395,8 @@
7B01CE3C271993AB00B5AF31 /* SentryTransportFactoryTests.swift */,
7B5CAF7C27F5AD0600ED0DB6 /* TestNSURLRequestBuilder.h */,
7B5CAF7D27F5AD3500ED0DB6 /* TestNSURLRequestBuilder.m */,
0AE455AC28F584D2006680E5 /* SentryReachabilityTests.m */,
0A9415B928F96CAC006A5DD1 /* TestSentryReachability.swift */,
);
path = Networking;
sourceTree = "<group>";
Expand Down Expand Up @@ -2963,6 +2975,7 @@
63295AF51EF3C7DB002D4490 /* NSDictionary+SentrySanitize.h in Headers */,
8E4A037825F6F52100000D77 /* SentrySampleDecision.h in Headers */,
63FE717920DA4C1100CDBAE8 /* SentryCrashReportStore.h in Headers */,
0AAE202128ED9BCC00D0CD80 /* SentryReachability.h in Headers */,
A839D89824864B80003B7AFD /* SentrySystemEventBreadcrumbs.h in Headers */,
7B14089624878F090035403D /* SentryCrashStackEntryMapper.h in Headers */,
63FE714920DA4C1100CDBAE8 /* SentryCrashStackCursor_Backtrace.h in Headers */,
Expand Down Expand Up @@ -3365,6 +3378,7 @@
63FE715F20DA4C1100CDBAE8 /* SentryCrashID.c in Sources */,
7DB3A687238EA75E00A2D442 /* SentryHttpTransport.m in Sources */,
63FE70D520DA4C1000CDBAE8 /* SentryCrashMonitor_NSException.m in Sources */,
0AAE201E28ED9B9400D0CD80 /* SentryReachability.m in Sources */,
7B0A54282521C22C00A71716 /* SentryFrameRemover.m in Sources */,
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapper.m in Sources */,
7B6C5EDC264E8DA80010D138 /* SentryFramesTrackingIntegration.m in Sources */,
Expand Down Expand Up @@ -3612,6 +3626,7 @@
7B4260342630315C00B36EDD /* SampleError.swift in Sources */,
D855B3E827D652AF00BCED76 /* SentryCoreDataTrackingIntegrationTest.swift in Sources */,
D855AD62286ED6A4002573E1 /* SentryCrashTests.m in Sources */,
0A9415BA28F96CAC006A5DD1 /* TestSentryReachability.swift in Sources */,
D880E3A728573E87008A90DB /* SentryBaggageTests.swift in Sources */,
7B16FD022654F86B008177D3 /* SentrySysctlTests.swift in Sources */,
7BAF3DB5243C743E008A5414 /* SentryClientTests.swift in Sources */,
Expand Down Expand Up @@ -3671,6 +3686,7 @@
8ED2D28026A6581C00CA8329 /* NSURLProtocolSwizzle.m in Sources */,
D808FB92281BF6EC009A2A33 /* SentryUIEventTrackingIntegrationTests.swift in Sources */,
7BC6EC04255C235F0059822A /* SentryFrameTests.swift in Sources */,
0AE455AD28F584D2006680E5 /* SentryReachabilityTests.m in Sources */,
63FE720420DA66EC00CDBAE8 /* SentryCrashString_Tests.m in Sources */,
7B944FB22469C01E00A10721 /* TestClient.swift in Sources */,
7BC6EC0C255C3DF80059822A /* SentryThreadTests.swift in Sources */,
Expand Down
45 changes: 35 additions & 10 deletions Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#import "SentryNSURLRequest.h"
#import "SentryNSURLRequestBuilder.h"
#import "SentryOptions.h"
#import "SentryReachability.h"
#import "SentrySerialization.h"

static NSTimeInterval const cachedEnvelopeSendDelay = 0.1;

@interface
SentryHttpTransport ()

Expand All @@ -30,6 +33,7 @@
@property (nonatomic, strong) SentryEnvelopeRateLimit *envelopeRateLimit;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;
@property (nonatomic, strong) dispatch_group_t dispatchGroup;
@property (nonatomic, strong) SentryReachability *reachability;

/**
* Relay expects the discarded events split by data category and reason; see
Expand Down Expand Up @@ -59,6 +63,7 @@ - (id)initWithOptions:(SentryOptions *)options
rateLimits:(id<SentryRateLimits>)rateLimits
envelopeRateLimit:(SentryEnvelopeRateLimit *)envelopeRateLimit
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
reachability:(SentryReachability *)reachability
{
if (self = [super init]) {
self.options = options;
Expand All @@ -74,18 +79,39 @@ - (id)initWithOptions:(SentryOptions *)options
self.discardedEvents = [NSMutableDictionary new];
[self.envelopeRateLimit setDelegate:self];
[self.fileManager setDelegate:self];
self.reachability = reachability;

[self sendAllCachedEnvelopes];

#if !TARGET_OS_WATCH
[self.reachability
monitorURL:[NSURL URLWithString:@"https://sentry.io"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: do you think the URL used here matters? Would it be helpful to monitor the DSN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter, it's not going to check if the host is up, once in a while, or something like that. So no, it's not helpful to monitor the DSN.

usingCallback:^(BOOL connected, NSString *_Nonnull typeDescription) {
if (connected) {
SENTRY_LOG_DEBUG(@"SentryHttpTransport: Internet connection is back.");
[self sendAllCachedEnvelopes];
} else {
SENTRY_LOG_DEBUG(@"SentryHttpTransport: Lost internet connection.");
}
}];
#endif
}
return self;
}

- (void)dealloc
{
#if !TARGET_OS_WATCH
[self.reachability stopMonitoring];
#endif
}

- (void)sendEnvelope:(SentryEnvelope *)envelope
{
envelope = [self.envelopeRateLimit removeRateLimitedItems:envelope];

if (envelope.items.count == 0) {
SENTRY_LOG_DEBUG(@"RateLimit is active for all envelope items.");
SENTRY_LOG_DEBUG(@"SentryHttpTransport: RateLimit is active for all envelope items.");
return;
}

Expand Down Expand Up @@ -213,19 +239,19 @@ - (SentryEnvelope *)addClientReportTo:(SentryEnvelope *)envelope

- (void)sendAllCachedEnvelopes
{
SENTRY_LOG_DEBUG(@"SentryHttpTransport: sendAllCachedEnvelopes start.");

@synchronized(self) {
if (self.isSending || ![self.requestManager isReady]) {
[SentryLog logWithMessage:@"SentryHttpTransport: Already sending."
andLevel:kSentryLevelDebug];
SENTRY_LOG_DEBUG(@"SentryHttpTransport: Already sending.");
return;
}
self.isSending = YES;
}

SentryFileContents *envelopeFileContents = [self.fileManager getOldestEnvelope];
if (nil == envelopeFileContents) {
[SentryLog logWithMessage:@"SentryHttpTransport: No envelopes left to send."
andLevel:kSentryLevelDebug];
SENTRY_LOG_DEBUG(@"SentryHttpTransport: No envelopes left to send.");
[self finishedSending];
return;
}
Expand Down Expand Up @@ -260,11 +286,11 @@ - (void)sendAllCachedEnvelopes

- (void)deleteEnvelopeAndSendNext:(NSString *)envelopePath
{
[SentryLog logWithMessage:@"SentryHttpTransport: Deleting envelope and sending next."
andLevel:kSentryLevelDebug];
SENTRY_LOG_DEBUG(@"SentryHttpTransport: Deleting envelope and sending next.");
[self.fileManager removeFileAtPath:envelopePath];
self.isSending = NO;
[self sendAllCachedEnvelopes];
[self.dispatchQueue dispatchAfter:cachedEnvelopeSendDelay
block:^{ [self sendAllCachedEnvelopes]; }];
}

- (void)sendEnvelope:(SentryEnvelope *)envelope
Expand All @@ -284,8 +310,7 @@ - (void)sendEnvelope:(SentryEnvelope *)envelope
[_self.rateLimits update:response];
[_self deleteEnvelopeAndSendNext:envelopePath];
} else {
[SentryLog logWithMessage:@"SentryHttpTransport: No internet connection."
andLevel:kSentryLevelDebug];
SENTRY_LOG_DEBUG(@"SentryHttpTransport: No internet connection.");
[_self finishedSending];
}
}];
Expand Down
Loading