@@ -158,22 +158,7 @@ - (SentryId *)captureException:(NSException *)exception
158158- (SentryId *)captureException : (NSException *)exception withScope : (SentryScope *)scope
159159{
160160 SentryEvent *event = [self buildExceptionEvent: exception];
161- return [self sendEvent: event withScope: scope alwaysAttachStacktrace: YES ];
162- }
163-
164- - (SentryId *)captureException : (NSException *)exception
165- withScope : (SentryScope *)scope
166- incrementSessionErrors : (SentrySession * (^)(void ))sessionBlock
167- {
168- SentryEvent *event = [self buildExceptionEvent: exception];
169- event = [self prepareEvent: event withScope: scope alwaysAttachStacktrace: YES ];
170-
171- if (event != nil ) {
172- SentrySession *session = sessionBlock ();
173- return [self sendEvent: event withSession: session withScope: scope];
174- }
175-
176- return SentryId.empty ;
161+ return [self captureEventIncrementingSessionErrorCount: event withScope: scope];
177162}
178163
179164- (SentryEvent *)buildExceptionEvent : (NSException *)exception
@@ -204,22 +189,7 @@ - (SentryId *)captureError:(NSError *)error
204189- (SentryId *)captureError : (NSError *)error withScope : (SentryScope *)scope
205190{
206191 SentryEvent *event = [self buildErrorEvent: error];
207- return [self sendEvent: event withScope: scope alwaysAttachStacktrace: YES ];
208- }
209-
210- - (SentryId *)captureError : (NSError *)error
211- withScope : (SentryScope *)scope
212- incrementSessionErrors : (SentrySession * (^)(void ))sessionBlock
213- {
214- SentryEvent *event = [self buildErrorEvent: error];
215- event = [self prepareEvent: event withScope: scope alwaysAttachStacktrace: YES ];
216-
217- if (event != nil ) {
218- SentrySession *session = sessionBlock ();
219- return [self sendEvent: event withSession: session withScope: scope];
220- }
221-
222- return SentryId.empty ;
192+ return [self captureEventIncrementingSessionErrorCount: event withScope: scope];
223193}
224194
225195- (SentryEvent *)buildErrorEvent : (NSError *)error
@@ -368,6 +338,26 @@ - (SentryId *)captureEvent:(SentryEvent *)event
368338 additionalEnvelopeItems: additionalEnvelopeItems];
369339}
370340
341+ - (SentryId *)captureEventIncrementingSessionErrorCount : (SentryEvent *)event
342+ withScope : (SentryScope *)scope
343+ {
344+ SentryEvent *preparedEvent = [self prepareEvent: event
345+ withScope: scope
346+ alwaysAttachStacktrace: YES ];
347+
348+ if (preparedEvent != nil ) {
349+ SentrySession *session = nil ;
350+ id <SentrySessionDelegate> delegate = self.sessionDelegate ;
351+ if (delegate != nil ) {
352+ session = [delegate incrementSessionErrors ];
353+ }
354+
355+ return [self sendEvent: preparedEvent withSession: session withScope: scope];
356+ }
357+
358+ return SentryId.empty ;
359+ }
360+
371361- (SentryId *)sendEvent : (SentryEvent *)event
372362 withScope : (SentryScope *)scope
373363 alwaysAttachStacktrace : (BOOL )alwaysAttachStacktrace
@@ -445,7 +435,7 @@ - (SentryId *)sendEvent:(SentryEvent *)event
445435}
446436
447437- (SentryId *)sendEvent : (SentryEvent *)event
448- withSession : (SentrySession *)session
438+ withSession : (nullable SentrySession *)session
449439 withScope : (SentryScope *)scope
450440{
451441 if (event == nil ) {
@@ -463,15 +453,22 @@ - (SentryId *)sendEvent:(SentryEvent *)event
463453
464454 SentryTraceContext *traceContext = [self getTraceStateWithEvent: event withScope: scope];
465455
466- if (nil == session.releaseName || [session.releaseName length ] == 0 ) {
456+ if (session == nil ) {
457+ [self .transportAdapter sendEvent: event traceContext: traceContext attachments: attachments];
458+ return event.eventId ;
459+ }
460+
461+ SentrySession *nonnullSession = SENTRY_UNWRAP_NULLABLE (SentrySession, session);
462+
463+ if (nonnullSession.releaseName == nil || [nonnullSession.releaseName length ] == 0 ) {
467464 SENTRY_LOG_DEBUG (DropSessionLogMessage);
468465
469466 [self .transportAdapter sendEvent: event traceContext: traceContext attachments: attachments];
470467 return event.eventId ;
471468 }
472469
473470 [self .transportAdapter sendEvent: event
474- withSession: session
471+ withSession: nonnullSession
475472 traceContext: traceContext
476473 attachments: attachments];
477474
0 commit comments