@@ -220,17 +220,22 @@ private CompletableResultCode internalSend(
220220 error , endpointUrl .toString (), friendlyExceptionThrown , logger );
221221 operationLogger .recordFailure (
222222 "Error sending telemetry items: " + error .getMessage (), error );
223- if (networkStatsbeat != null ) {
223+
224+ // networkStatsbeat is null when it's sending a Statsbeat request.
225+ // instrumentationKey is null when sending persisted file's raw bytes.
226+ if (networkStatsbeat != null && instrumentationKey != null ) {
224227 networkStatsbeat .incrementRequestFailureCount (instrumentationKey );
225228 }
226- // sending raw bytes won't have any instrumentation key
229+ // instrumentationKey is null when sending persisted file's raw bytes.
227230 if (instrumentationKey != null ) {
228231 writeToDiskOnFailure (byteBuffers );
229232 }
230233 result .fail ();
231234 },
232235 () -> {
233- if (networkStatsbeat != null ) {
236+ // networkStatsbeat is null when it's sending a Statsbeat request.
237+ // instrumentationKey is null when sending persisted file's raw bytes.
238+ if (networkStatsbeat != null && instrumentationKey != null ) {
234239 networkStatsbeat .incrementRequestSuccessCount (
235240 System .currentTimeMillis () - startTime , instrumentationKey );
236241 }
@@ -268,7 +273,9 @@ private void parseResponseCode(
268273 case 439 : // Breeze-specific: THROTTLED OVER EXTENDED TIME
269274 // TODO handle throttling
270275 // TODO (heya) track throttling count via Statsbeat
271- if (networkStatsbeat != null ) {
276+ // networkStatsbeat is null when it's sending a Statsbeat request.
277+ // instrumentationKey is null when sending persisted file's raw bytes.
278+ if (networkStatsbeat != null && instrumentationKey != null ) {
272279 networkStatsbeat .incrementThrottlingCount (instrumentationKey );
273280 }
274281 break ;
@@ -281,7 +288,9 @@ private void parseResponseCode(
281288 case 0 : // client-side exception
282289 // TODO exponential backoff and retry to a limit
283290 // TODO (heya) track failure count via Statsbeat
284- if (networkStatsbeat != null ) {
291+ // networkStatsbeat is null when it's sending a Statsbeat request.
292+ // instrumentationKey is null when sending persisted file's raw bytes.
293+ if (networkStatsbeat != null && instrumentationKey != null ) {
285294 networkStatsbeat .incrementRetryCount (instrumentationKey );
286295 }
287296 break ;
0 commit comments