@@ -73,21 +73,23 @@ internal class DataUploadWorker: DataUploadWorkerType {
7373 let context = contextProvider. read ( )
7474 let blockersForUpload = uploadConditions. blockersForUpload ( with: context)
7575 let isSystemReady = blockersForUpload. isEmpty
76- let files = isSystemReady ? fileReader. readFiles ( limit: maxBatchesPerUpload) : nil
77- if let files = files, !files. isEmpty {
76+ let files = fileReader. readFiles ( limit: maxBatchesPerUpload)
77+
78+ if !files. isEmpty && isSystemReady {
7879 DD . logger. debug ( " ⏳ ( \( self . featureName) ) Uploading batches... " )
7980 self . backgroundTaskCoordinator? . beginBackgroundTask ( )
8081 self . uploadFile ( from: files. reversed ( ) , context: context)
8182 sendUploadCycleMetric ( )
8283 } else {
83- let batchLabel = files? . isEmpty == false ? " YES " : ( isSystemReady ? " NO " : " NOT CHECKED " )
84+ let batchLabel = files. isEmpty ? " NO " : " YES "
8485 DD . logger. debug ( " 💡 ( \( self . featureName) ) No upload. Batch to upload: \( batchLabel) , System conditions: \( blockersForUpload. description) " )
8586 self . delay. increase ( )
8687 self . backgroundTaskCoordinator? . endBackgroundTask ( )
8788 self . scheduleNextCycle ( )
88- sendBatchBlockedMetric ( blockers: blockersForUpload)
89+ sendBatchBlockedMetric ( blockers: blockersForUpload, batchCount : files . count )
8990 }
9091 }
92+
9193 self . readWork = readWorkItem
9294
9395 // Start sending batches immediately after initialization:
@@ -127,6 +129,7 @@ internal class DataUploadWorker: DataUploadWorkerType {
127129 DD . logger. debug ( " → ( \( self . featureName) ) not delivered, will be retransmitted: \( uploadStatus. userDebugDescription) " )
128130 self . delay. increase ( )
129131 self . scheduleNextCycle ( )
132+ sendBatchBlockedMetric ( status: uploadStatus, batchCount: files. count)
130133 return
131134 }
132135
@@ -143,7 +146,6 @@ internal class DataUploadWorker: DataUploadWorkerType {
143146 previousUploadStatus = nil
144147
145148 if let error = uploadStatus. error {
146- sendBatchBlockedMetric ( error: error)
147149 throw error // Throw to report the request error accordingly
148150 }
149151 } catch DataUploadError . httpError( statusCode: . unauthorized) , DataUploadError. httpError( statusCode: . forbidden) {
@@ -237,7 +239,7 @@ internal class DataUploadWorker: DataUploadWorkerType {
237239 )
238240 }
239241
240- private func sendBatchBlockedMetric( blockers: [ DataUploadConditions . Blocker ] ) {
242+ private func sendBatchBlockedMetric( blockers: [ DataUploadConditions . Blocker ] , batchCount : Int ) {
241243 guard !blockers. isEmpty else {
242244 return
243245 }
@@ -248,6 +250,7 @@ internal class DataUploadWorker: DataUploadWorkerType {
248250 SDKMetricFields . typeKey: BatchBlockedMetric . typeValue,
249251 BatchMetric . trackKey: featureName,
250252 BatchBlockedMetric . uploaderDelayKey: delay. current,
253+ BatchBlockedMetric . batchCount: batchCount,
251254 BatchBlockedMetric . blockers: blockers. map {
252255 switch $0 {
253256 case . battery: return " low_battery "
@@ -260,13 +263,18 @@ internal class DataUploadWorker: DataUploadWorkerType {
260263 )
261264 }
262265
263- private func sendBatchBlockedMetric( error: DataUploadError ) {
266+ private func sendBatchBlockedMetric( status: DataUploadStatus , batchCount: Int ) {
267+ guard let error = status. error else {
268+ return
269+ }
270+
264271 telemetry. metric (
265272 name: BatchBlockedMetric . name,
266273 attributes: [
267274 SDKMetricFields . typeKey: BatchBlockedMetric . typeValue,
268275 BatchMetric . trackKey: featureName,
269276 BatchBlockedMetric . uploaderDelayKey: delay. current,
277+ BatchBlockedMetric . batchCount: batchCount,
270278 BatchBlockedMetric . failure: {
271279 switch error {
272280 case let . httpError( code) : return " intake-code- \( code. rawValue) "
0 commit comments