Skip to content

Commit

Permalink
[Master][BUG] remove 403 as a “retriable” error code #2296 (#2297)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Mar 12, 2024
1 parent caab0ec commit ecf6d3c
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 408 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| disableIkeyDeprecationMessage | boolean | true | [Optional] Disable instrumentation Key deprecation error message. If true, error message will NOT be sent. **Note: instrumentation key support will end soon**, see aka.ms/IkeyMigrate for more details.
| bufferOverride <br/><sub>since 2.8.12</sub> | IStorageBuffer | undefined | [Optional] Identifies a simple interface to allow you to override the storage mechanism used for tracking unsent and unacknowledged events, when not provided defaults to using SessionStorage interface. You MUST supply both the `getItem` and `setItem` functions when defined.
| storagePrefix (since v2.8.15)| string[] | undefined | [Optional] An optional value that will be added as name prefix for storage name. ([design for system to correctly identifies these telemetry events as "necessary"](https://github.com/microsoft/ApplicationInsights-JS/issues/2094).) |
| 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 2.8.18. |

### ICookieMgrConfig

Expand Down
5 changes: 5 additions & 0 deletions channels/applicationinsights-channel-js/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export interface ISenderConfig {
* (Optional) The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
*/
eventsLimitInMem: () => number;

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

export interface IBackendResponse {
Expand Down
20 changes: 15 additions & 5 deletions channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
import {
BaseTelemetryPlugin, IAppInsightsCore, IConfiguration, IDiagnosticLogger, INotificationManager, IPlugin, IProcessTelemetryContext,
IProcessTelemetryUnloadContext, ITelemetryItem, ITelemetryPluginChain, ITelemetryUnloadState, SendRequestReason, _eInternalMessageId,
_throwInternal, _warnToConsole, arrForEach, createUniqueNamespace, dateNow, dumpObj, eLoggingSeverity, getExceptionName, getIEVersion,
getJSON, getNavigator, getWindow, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace,
objForEachKey, objKeys, useXDomainRequest
_throwInternal, _warnToConsole, arrForEach, arrIndexOf, createUniqueNamespace, dateNow, dumpObj, eLoggingSeverity, getExceptionName,
getIEVersion, getJSON, getNavigator, getWindow, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported,
mergeEvtNamespace, objForEachKey, objKeys, useXDomainRequest
} from "@microsoft/applicationinsights-core-js";
import {
DependencyEnvelopeCreator, EventEnvelopeCreator, ExceptionEnvelopeCreator, MetricEnvelopeCreator, PageViewEnvelopeCreator,
Expand Down Expand Up @@ -63,7 +63,8 @@ function _getDefaultAppInsightsChannelConfig(): ISenderConfig {
samplingPercentage: () => 100,
customHeaders: () => defaultCustomHeaders,
convertUndefined: () => defaultValue,
eventsLimitInMem: () => 10000
eventsLimitInMem: () => 10000,
retryCodes: () => null
}
}

Expand Down Expand Up @@ -140,6 +141,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
let _syncUnloadSender: SenderFunction; // The identified sender to use for the synchronous unload stage
let _offlineListener: IOfflineListener;
let _evtNamespace: string | string[];
let _retryCodes: number[];

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

Expand Down Expand Up @@ -232,6 +234,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
}
});

_retryCodes = _self._senderConfig.retryCodes();

if (config.storagePrefix){
utlSetStoragePrefix(config.storagePrefix);
}
Expand Down Expand Up @@ -946,8 +950,14 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
* @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

0 comments on commit ecf6d3c

Please sign in to comment.