Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release-3.0][BUG] remove 403 as a “retriable” error code #2296 #2303

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| storagePrefix | string[] | undefined | [Optional] An optional value that will be added as name prefix for storage name. |
| featureOptIn <br/><sub>since 3.0.3</sub> | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg <br/><sub>since 3.0.3</sub> | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |
### ICookieMgrConfig
Expand Down
6 changes: 6 additions & 0 deletions channels/applicationinsights-channel-js/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export interface ISenderConfig {
* @since 3.0.6
*/
disableSendBeaconSplit?: boolean;

/**
* (Optional) The specific error codes that will cause a retry of sending data to the backend.
* @since 3.1.1
*/
retryCodes?: number[];
}

export interface IBackendResponse {
Expand Down
23 changes: 16 additions & 7 deletions channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
BaseTelemetryPlugin, IAppInsightsCore, IChannelControls, IConfigDefaults, IConfiguration, IDiagnosticLogger, INotificationManager,
IPayloadData, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryItem, ITelemetryPluginChain,
ITelemetryUnloadState, IXHROverride, OnCompleteCallback, SendPOSTFunction, SendRequestReason, TransportType, _eInternalMessageId,
_throwInternal, _warnToConsole, arrForEach, cfgDfBoolean, cfgDfValidate, createProcessTelemetryContext, createUniqueNamespace, dateNow,
dumpObj, eLoggingSeverity, getExceptionName, getIEVersion, getJSON, getNavigator, getWindow, isArray, isBeaconsSupported,
isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace, objExtend, objKeys, onConfigChange, runTargetUnload,
useXDomainRequest
_throwInternal, _warnToConsole, arrForEach, arrIndexOf, cfgDfBoolean, cfgDfValidate, createProcessTelemetryContext,
createUniqueNamespace, dateNow, dumpObj, eLoggingSeverity, getExceptionName, getIEVersion, getJSON, getNavigator, getWindow, isArray,
isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace, objExtend, objKeys, onConfigChange,
runTargetUnload, useXDomainRequest
} from "@microsoft/applicationinsights-core-js";
import { IPromise, createPromise, doAwaitResponse } from "@nevware21/ts-async";
import { ITimerHandler, isTruthy, objDeepFreeze, objDefine, scheduleTimeout } from "@nevware21/ts-utils";
Expand Down Expand Up @@ -75,7 +75,8 @@ const defaultAppInsightsChannelConfig: IConfigDefaults<ISenderConfig> = objDeepF
eventsLimitInMem: 10000,
bufferOverride: false,
httpXHROverride: { isVal: isOverrideFn, v:UNDEFINED_VALUE },
alwaysUseXhrOverride: cfgDfBoolean()
alwaysUseXhrOverride: cfgDfBoolean(),
retryCodes: UNDEFINED_VALUE
});

function _chkSampling(value: number) {
Expand Down Expand Up @@ -176,6 +177,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
let _xhrSend: SenderFunction;
let _fallbackSend: SenderFunction;
let _disableBeaconSplit: boolean;
let _retryCodes: number[];

dynamicProto(Sender, this, (_self, _base) => {

Expand Down Expand Up @@ -286,6 +288,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
_beaconSupported = (senderConfig.onunloadDisableBeacon === false || senderConfig.isBeaconApiDisabled === false) && isBeaconsSupported();
_alwaysUseCustomSend = senderConfig.alwaysUseXhrOverride;
_disableXhr = !!senderConfig.disableXhr;
_retryCodes = senderConfig.retryCodes;

let bufferOverride = senderConfig.bufferOverride;
let canUseSessionStorage = !!senderConfig.enableSessionStorageBuffer &&
Expand Down Expand Up @@ -1066,7 +1069,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
let response = result.value;

/**
* The Promise returned from fetch() wont reject on HTTP error status even if the response is an HTTP 404 or 500.
* The Promise returned from fetch() won't reject on HTTP error status even if the response is an HTTP 404 or 500.
* Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure
* or if anything prevented the request from completing.
*/
Expand Down Expand Up @@ -1205,8 +1208,14 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
* @param statusCode
*/
function _isRetriable(statusCode: number): boolean {
// retryCodes = [] means should not retry
if (!isNullOrUndefined(_retryCodes)) {
return _retryCodes.length && arrIndexOf(_retryCodes, statusCode) > -1;
}

return statusCode === 401 // Unauthorized
|| statusCode === 403 // Forbidden
// Removing as private links can return a 403 which causes excessive retries and session storage usage
// || statusCode === 403 // Forbidden
|| statusCode === 408 // Timeout
|| statusCode === 429 // Too many requests.
|| statusCode === 500 // Internal server error.
Expand Down
Loading
Loading