Skip to content

Commit

Permalink
Merge 95a3f67 into bbe81cb
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrenskers authored Nov 23, 2022
2 parents bbe81cb + 95a3f67 commit acdef76
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This version adds a dependency on Swift.

- Properly demangle Swift class name (#2162)

### Fixes

- Errors shortly after SentrySDK.init now affect the session (#2430)

### Breaking Changes

- Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "SentrySamplingContext.h"
#import "SentryScope.h"
#import "SentrySerialization.h"
#import "SentrySession+Private.h"
#import "SentryTracer.h"
#import "SentryTracesSampler.h"
#import "SentryTransaction.h"
Expand All @@ -33,6 +34,7 @@
@property (nonatomic, strong) id<SentryCurrentDateProvider> currentDateProvider;
@property (nonatomic, strong) NSMutableArray<id<SentryIntegrationProtocol>> *installedIntegrations;
@property (nonatomic, strong) NSMutableSet<NSString *> *installedIntegrationNames;
@property (nonatomic) NSUInteger errorsBeforeSession;

@end

Expand All @@ -53,6 +55,7 @@ - (instancetype)initWithClient:(nullable SentryClient *)client
_installedIntegrationNames = [[NSMutableSet alloc] init];
_crashWrapper = [SentryCrashWrapper sharedInstance];
_tracesSampler = [[SentryTracesSampler alloc] initWithOptions:client.options];
_errorsBeforeSession = 0;
#if SENTRY_TARGET_PROFILING_SUPPORTED
if (client.options.isProfilingEnabled) {
_profilesSampler = [[SentryProfilesSampler alloc] initWithOptions:client.options];
Expand Down Expand Up @@ -93,6 +96,11 @@ - (void)startSession
}
_session = [[SentrySession alloc] initWithReleaseName:options.releaseName];

if (_errorsBeforeSession > 0) {
_session.errors = _errorsBeforeSession;
_errorsBeforeSession = 0;
}

NSString *environment = options.environment;
if (nil != environment) {
_session.environment = environment;
Expand Down Expand Up @@ -447,6 +455,7 @@ - (SentryId *)captureError:(NSError *)error withScope:(SentryScope *)scope
withScope:scope
incrementSessionErrors:^(void) { return [self incrementSessionErrors]; }];
} else {
_errorsBeforeSession++;
return [client captureError:error withScope:scope];
}
}
Expand All @@ -468,6 +477,7 @@ - (SentryId *)captureException:(NSException *)exception withScope:(SentryScope *
withScope:scope
incrementSessionErrors:^(void) { return [self incrementSessionErrors]; }];
} else {
_errorsBeforeSession++;
return [client captureException:exception withScope:scope];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentrySession.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "SentrySession.h"
#import "NSDate+SentryExtras.h"
#import "SentryCurrentDate.h"
#import "SentryInstallation.h"
#import "SentryLog.h"
#import "SentrySession+Private.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/include/SentrySession+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ NS_ASSUME_NONNULL_BEGIN
NSString *nameForSentrySessionStatus(SentrySessionStatus status);

@interface
SentrySession (Private)
SentrySession ()

@property (nonatomic) NSUInteger errors;

- (void)setFlagInit;

Expand Down
13 changes: 13 additions & 0 deletions Tests/SentryTests/SentryHubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ class SentryHubTests: XCTestCase {
XCTAssertEqual(1, fixture.client.captureSessionInvocations.count)
}

func testCaptureErrorBeforeSession() {
let sut = fixture.getSut()
sut.capture(error: fixture.error, scope: fixture.scope).assertIsNotEmpty()
sut.startSession()

XCTAssertEqual(fixture.client.captureErrorWithScopeInvocations.count, 1)
XCTAssertEqual(fixture.client.captureSessionInvocations.count, 1)

if let session = fixture.client.captureSessionInvocations.first {
XCTAssertEqual(session.errors, 1)
}
}

func testCaptureWithoutIncreasingErrorCount() {
let sut = fixture.getSut()
sut.startSession()
Expand Down

0 comments on commit acdef76

Please sign in to comment.