Skip to content

Commit bd03489

Browse files
committed
Only clear store if breadcrumbs exsist, Inject session in SentryEndpoint
1 parent bd0d9a5 commit bd03489

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

Sources/BreadcrumbStore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public final class BreadcrumbStore: NSObject {
3838
storeUpdated?(self)
3939
}
4040

41-
/// Clears the store for given type or all if none specified
41+
/// Clears the store if crumbs exist
4242
public func clear() {
43+
guard crumbs.count > 0 else { return }
4344
crumbs.removeAll()
4445
storeUpdated?(self)
4546
}

Sources/Request.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ extension SentryClient {
1717
*/
1818
internal func sendEvent(_ event: Event, finished: SentryEndpointRequestFinished? = nil) {
1919
#if swift(>=3.0)
20-
SentryEndpoint.store(event: event).send(dsn: dsn, finished: finished)
20+
SentryEndpoint.store(event: event).send(session: session, dsn: dsn, finished: finished)
2121
#else
22-
SentryEndpoint.store(event: event).send(dsn, finished: finished)
22+
SentryEndpoint.store(event: event).send(session, dsn: dsn, finished: finished)
2323
#endif
2424
}
2525

@@ -30,9 +30,9 @@ extension SentryClient {
3030
*/
3131
internal func sendEvent(_ event: SavedEvent, finished: SentryEndpointRequestFinished? = nil) {
3232
#if swift(>=3.0)
33-
SentryEndpoint.storeSavedEvent(event: event).send(dsn: dsn, finished: finished)
33+
SentryEndpoint.storeSavedEvent(event: event).send(session: session, dsn: dsn, finished: finished)
3434
#else
35-
SentryEndpoint.storeSavedEvent(event: event).send(dsn, finished: finished)
35+
SentryEndpoint.storeSavedEvent(event: event).send(session, dsn: dsn, finished: finished)
3636
#endif
3737
}
3838

@@ -46,12 +46,12 @@ extension SentryClient {
4646
userFeedback.event = lastSuccessfullySentEvent
4747
}
4848
#if swift(>=3.0)
49-
SentryEndpoint.userFeedback(userFeedback: userFeedback).send(dsn: dsn) { [weak self] success in
49+
SentryEndpoint.userFeedback(userFeedback: userFeedback).send(session: session, dsn: dsn) { [weak self] success in
5050
self?.sentUserFeedback()
5151
finished?(success)
5252
}
5353
#else
54-
SentryEndpoint.userFeedback(userFeedback: userFeedback).send(dsn) { [weak self] success in
54+
SentryEndpoint.userFeedback(userFeedback: userFeedback).send(session, dsn: dsn) { [weak self] success in
5555
self?.sentUserFeedback()
5656
finished?(success)
5757
}

Sources/Sentry.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import KSCrash
3939
internal typealias JSONSerialization = NSJSONSerialization
4040
internal typealias Bundle = NSBundle
4141
internal typealias URLQueryItem = NSURLQueryItem
42+
internal typealias URLSession = NSURLSession
4243
#endif
4344

4445
internal enum SentryError: Error {
@@ -79,6 +80,7 @@ internal enum SentryError: Error {
7980
// MARK: - Attributes
8081

8182
internal let dsn: DSN
83+
internal let session: URLSession
8284
internal(set) var crashHandler: CrashHandler? {
8385
didSet {
8486
crashHandler?.startCrashReporting()
@@ -117,7 +119,7 @@ internal enum SentryError: Error {
117119
}
118120
#else
119121
dispatch_async(dispatch_get_main_queue(), {
120-
self.delegate?.userFeedbackReady()
122+
self.delegate?.userFeedbackReady()
121123
})
122124
#endif
123125
}
@@ -149,8 +151,10 @@ internal enum SentryError: Error {
149151

150152
#if swift(>=3.0)
151153
self.releaseVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
154+
self.session = URLSession(configuration: URLSessionConfiguration.ephemeral)
152155
#else
153156
self.releaseVersion = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as? String
157+
self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration())
154158
#endif
155159

156160
super.init()
@@ -208,11 +212,11 @@ internal enum SentryError: Error {
208212
/// Reports given event to Sentry
209213
@objc public func captureEvent(_ event: Event) {
210214
#if swift(>=3.0)
211-
DispatchQueue(label: SentryClient.queueName).sync {
215+
DispatchQueue(label: SentryClient.queueName).async {
212216
self.captureEvent(event, useClientProperties: true)
213217
}
214218
#else
215-
dispatch_sync(dispatch_queue_create(SentryClient.queueName, nil), {
219+
dispatch_async(dispatch_queue_create(SentryClient.queueName, nil), {
216220
self.captureEvent(event, useClientProperties: true)
217221
})
218222
#endif
@@ -309,7 +313,7 @@ internal enum SentryError: Error {
309313
event.extra.unionInPlace(extra)
310314
}
311315
}
312-
316+
313317
if nil == event.breadcrumbsSerialized { // we only want to set the breadcrumbs if there are non in the event
314318
event.breadcrumbsSerialized = breadcrumbs.serialized
315319
}

Sources/SentryEndpoint.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ protocol Endpoint {
2020
var httpMethod: HttpMethod { get }
2121
func route(dsn dsn: DSN) -> NSURL?
2222
var payload: NSData { get }
23-
func send(dsn: DSN, finished: SentryEndpointRequestFinished?)
23+
func send(session: URLSession, dsn: DSN, finished: SentryEndpointRequestFinished?)
2424
}
2525

2626
enum SentryEndpoint: Endpoint {
27-
#if swift(>=3.0)
28-
static let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
29-
#else
30-
static let session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration())
31-
#endif
3227

3328
case store(event: Event)
3429
case storeSavedEvent(event: SavedEvent)
@@ -139,7 +134,7 @@ enum SentryEndpoint: Endpoint {
139134
}
140135
}
141136

142-
func send(dsn: DSN, finished: SentryEndpointRequestFinished? = nil) {
137+
func send(session: URLSession, dsn: DSN, finished: SentryEndpointRequestFinished? = nil) {
143138
guard let url = route(dsn: dsn) else {
144139
SentryLog.Error.log("Cannot find route for \(self)")
145140
finished?(false)
@@ -155,7 +150,7 @@ enum SentryEndpoint: Endpoint {
155150
configureRequest(dsn: dsn, request: request)
156151

157152
#if swift(>=3.0)
158-
SentryEndpoint.session.dataTask(with: request as URLRequest) { data, response, error in
153+
session.dataTask(with: request as URLRequest) { data, response, error in
159154
var success = false
160155

161156
// Returns success if we have data and 200 response code
@@ -174,7 +169,7 @@ enum SentryEndpoint: Endpoint {
174169
finished?(success)
175170
}.resume()
176171
#else
177-
SentryEndpoint.session.dataTaskWithRequest(request) { data, response, error in
172+
session.dataTaskWithRequest(request) { data, response, error in
178173
var success = false
179174

180175
// Returns success if we have data and 200 response code

0 commit comments

Comments
 (0)