Skip to content

Commit 7d7e906

Browse files
authored
Separate BeaconSendFailure and BeaconSendFailure from SizeLimitExceeded (#2642)
* Separate BeaconSendFailure and BeaconSendFailure from SizeLimitExceeded to make it easier to troubleshoot SizeLimitExceeded errors * PR feedback
1 parent 6ef6d33 commit 7d7e906

8 files changed

Lines changed: 37 additions & 17 deletions

File tree

channels/1ds-post-js/src/DataModels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ export declare const enum EventBatchNotificationReason {
457457
SizeLimitExceeded = 8003, // EventsDiscardedReason.SizeLimitExceeded
458458
KillSwitch = 8004, // EventsDiscardedReason.KillSwitch,
459459
QueueFull = 8005, // EventsDiscardedReason.QueueFull
460+
BeaconSendFailure = 8006, // EventsDiscardedReason.BeaconSendFailure
460461
EventsDroppedMax = 8999,
461462

462463
/**

channels/1ds-post-js/src/HttpManager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const _eventActionMap: any = {
5050
[EventBatchNotificationReason.RequeueEvents]: STR_REQUEUE,
5151
[EventBatchNotificationReason.Complete]: "sent",
5252
[EventBatchNotificationReason.KillSwitch]: STR_DROPPED,
53-
[EventBatchNotificationReason.SizeLimitExceeded]: STR_DROPPED
53+
[EventBatchNotificationReason.SizeLimitExceeded]: STR_DROPPED,
54+
[EventBatchNotificationReason.BeaconSendFailure]: STR_DROPPED
5455
};
5556

5657
const _collectorQsHeaders = { };
@@ -577,7 +578,10 @@ export class HttpManager {
577578
}
578579

579580
if (!persistStorage) {
580-
_sendBatchesNotification(droppedBatches, EventBatchNotificationReason.SizeLimitExceeded, thePayload.sendType, true);
581+
// Events passed Serializer size validation, log BeaconSendFailure
582+
// because it could still be size related but we did not exceed the
583+
// configured limit, and sendBeacon could fail for other reasons
584+
_sendBatchesNotification(droppedBatches, EventBatchNotificationReason.BeaconSendFailure, thePayload.sendType, true);
581585
}
582586
} else {
583587
status = 0;

channels/1ds-post-js/src/PostChannel.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ export class PostChannel extends BaseTelemetryPlugin implements IChannelControls
861861
_queueSize -= droppedCount;
862862
}
863863

864-
_notifyBatchEvents(strEventsDiscarded, [droppedEvents], EventsDiscardedReason.QueueFull);
864+
_notifyBatchEvents(strEventsDiscarded, [droppedEvents], EventsDiscardedReason.QueueFull, undefined);
865865
return true;
866866
}
867867
}
@@ -1120,24 +1120,25 @@ export class PostChannel extends BaseTelemetryPlugin implements IChannelControls
11201120
_scheduleTimer();
11211121
}
11221122

1123-
function _eventsDropped(batches: EventBatch[], reason?: number) {
1123+
function _eventsDropped(batches: EventBatch[], reason?: number, isSyncRequest?: boolean, sendType?: EventSendType) {
11241124
_notifyBatchEvents(
11251125
strEventsDiscarded,
11261126
batches,
11271127
(reason >= EventBatchNotificationReason.EventsDropped && reason <= EventBatchNotificationReason.EventsDroppedMax ?
11281128
reason - EventBatchNotificationReason.EventsDropped :
1129-
EventsDiscardedReason.Unknown));
1129+
EventsDiscardedReason.Unknown),
1130+
sendType);
11301131
}
11311132

1132-
function _eventsResponseFail(batches: EventBatch[]) {
1133-
_notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.NonRetryableStatus);
1133+
function _eventsResponseFail(batches: EventBatch[], reason?: number, isSyncRequest?: boolean, sendType?: EventSendType) {
1134+
_notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.NonRetryableStatus, sendType);
11341135

11351136
// Try and schedule the processing timer if we have events
11361137
_scheduleTimer();
11371138
}
11381139

1139-
function _otherEvent(batches: EventBatch[], reason?: number) {
1140-
_notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.Unknown);
1140+
function _otherEvent(batches: EventBatch[], reason?: number, isSyncRequest?: boolean, sendType?: EventSendType) {
1141+
_notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.Unknown, sendType);
11411142

11421143
// Try and schedule the processing timer if we have events
11431144
_scheduleTimer();

shared/AppInsightsCore/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export const enum eEventsDiscardedReason {
3030
/**
3131
* The event queue is full.
3232
*/
33-
QueueFull = 5
33+
QueueFull = 5,
34+
/**
35+
* The sendBeacon API call failed for reasons other than size limits.
36+
*/
37+
BeaconSendFailure = 6
3438
}
3539

3640
/**
@@ -65,7 +69,12 @@ export const EventsDiscardedReason = (/* @__PURE__ */ createEnumStyle<typeof eEv
6569
/**
6670
* The event queue is full.
6771
*/
68-
QueueFull: eEventsDiscardedReason.QueueFull
72+
QueueFull: eEventsDiscardedReason.QueueFull,
73+
74+
/**
75+
* The sendBeacon API call failed for reasons other than size limits.
76+
*/
77+
BeaconSendFailure: eEventsDiscardedReason.BeaconSendFailure
6978
}));
7079

7180
export type EventsDiscardedReason = number | eEventsDiscardedReason;

shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/INotificationListener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export interface INotificationListener {
2222
* @param events - The array of events that have been discarded.
2323
* @param reason - The reason for discarding the events. The EventsDiscardedReason
2424
* constant should be used to check the different values.
25+
* @param sendType - [Optional] The send type used when the events were discarded.
2526
*/
26-
eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
27+
eventsDiscarded?: (events: ITelemetryItem[], reason: number, sendType?: number) => void;
2728

2829
/**
2930
* [Optional] A function called when the events have been requested to be sent to the sever.

shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/INotificationManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export interface INotificationManager {
3535
* @param events - The array of events that have been discarded by the SDK.
3636
* @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
3737
* constant should be used to check the different values.
38+
* @param sendType - [Optional] The send type used when the events were discarded.
3839
*/
39-
eventsDiscarded(events: ITelemetryItem[], reason: number): void;
40+
eventsDiscarded(events: ITelemetryItem[], reason: number, sendType?: number): void;
4041

4142
/**
4243
* [Optional] A function called when the events have been requested to be sent to the sever.

shared/AppInsightsCore/src/JavaScriptSDK/NotificationManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ export class NotificationManager implements INotificationManager {
111111
* @param events - The array of events that have been discarded by the SDK.
112112
* @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
113113
* constant should be used to check the different values.
114+
* @param sendType - [Optional] The send type used when the events were discarded.
114115
*/
115-
_self.eventsDiscarded = (events: ITelemetryItem[], reason: number): void => {
116+
_self.eventsDiscarded = (events: ITelemetryItem[], reason: number, sendType?: number): void => {
116117
_runListeners(_listeners, STR_EVENTS_DISCARDED, _asyncNotifications, (listener) => {
117-
listener.eventsDiscarded(events, reason);
118+
listener.eventsDiscarded(events, reason, sendType);
118119
});
119120
};
120121

tools/chrome-debug-extension/src/pageHelper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ let _notificationListener: INotificationListener = {
7979
* @param events - The array of events that have been discarded.
8080
* @param reason - The reason for discarding the events. The EventsDiscardedReason
8181
* constant should be used to check the different values.
82+
* @param sendType - [Optional] The send type used when the events were discarded.
8283
*/
83-
eventsDiscarded: (events: ITelemetryItem[], reason: number) => {
84+
eventsDiscarded: (events: ITelemetryItem[], reason: number, sendType?: number) => {
8485
_sendMessage(MessageType.Notification, MessageSource.EventsDiscardedNotification, "Notification:eventsDiscarded", {
8586
reason,
86-
events
87+
events,
88+
sendType
8789
});
8890
},
8991

0 commit comments

Comments
 (0)