diff --git a/Sources/EmbraceCore/Internal/Logs/LogController.swift b/Sources/EmbraceCore/Internal/Logs/LogController.swift index 09b40f50..ffb0a7e2 100644 --- a/Sources/EmbraceCore/Internal/Logs/LogController.swift +++ b/Sources/EmbraceCore/Internal/Logs/LogController.swift @@ -47,7 +47,7 @@ class LogController: LogControllable { extension LogController { func batchFinished(withLogs logs: [LogRecord]) { do { - guard let sessionId = sessionController?.currentSession?.id else { + guard let sessionId = sessionController?.currentSession?.id, logs.count > 0 else { return } let resourcePayload = try createResourcePayload(sessionId: sessionId) diff --git a/Tests/EmbraceCoreTests/Internal/Logs/LogControllerTests.swift b/Tests/EmbraceCoreTests/Internal/Logs/LogControllerTests.swift index 50570775..33cfe478 100644 --- a/Tests/EmbraceCoreTests/Internal/Logs/LogControllerTests.swift +++ b/Tests/EmbraceCoreTests/Internal/Logs/LogControllerTests.swift @@ -126,6 +126,12 @@ class LogControllerTests: XCTestCase { thenDoesntTryToUploadAnything() } + func testHavingSessionButNoLogs_onBatchFinished_wontTryToUploadAnything() { + givenLogController() + whenInvokingBatchFinished(withLogs: []) + thenDoesntTryToUploadAnything() + } + func testHavingLogs_onBatchFinished_fetchesResourcesFromStorage() throws { givenLogController() whenInvokingBatchFinished(withLogs: [randomLogRecord()])