@amplitude/analytics-core
Advanced tools
Comparing version 2.1.0 to 2.2.0-featadddiagnostics.0
@@ -1,3 +0,4 @@ | ||
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types'; | ||
import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types'; | ||
import { Logger } from './logger'; | ||
import { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export declare const getDefaultConfig: () => { | ||
@@ -14,2 +15,3 @@ flushMaxRetries: number; | ||
useBatch: boolean; | ||
diagnosticProvider: BaseDiagnostic; | ||
}; | ||
@@ -32,2 +34,3 @@ export declare class Config implements IConfig { | ||
useBatch: boolean; | ||
diagnosticProvider: Diagnostic; | ||
protected _optOut: boolean; | ||
@@ -34,0 +37,0 @@ get optOut(): boolean; |
@@ -6,2 +6,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var logger_1 = require("./logger"); | ||
var diagnostic_1 = require("./diagnostics/diagnostic"); | ||
var getDefaultConfig = function () { return ({ | ||
@@ -18,2 +19,3 @@ flushMaxRetries: 12, | ||
useBatch: false, | ||
diagnosticProvider: new diagnostic_1.BaseDiagnostic(), | ||
}); }; | ||
@@ -23,3 +25,3 @@ exports.getDefaultConfig = getDefaultConfig; | ||
function Config(options) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
this._optOut = false; | ||
@@ -43,2 +45,6 @@ var defaultConfig = (0, exports.getDefaultConfig)(); | ||
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch; | ||
this.diagnosticProvider = (_e = options.diagnosticProvider) !== null && _e !== void 0 ? _e : defaultConfig.diagnosticProvider; | ||
if (!this.diagnosticProvider.apiKey) { | ||
this.diagnosticProvider.apiKey = this.apiKey; | ||
} | ||
this.loggerProvider.enable(this.logLevel); | ||
@@ -45,0 +51,0 @@ var serverConfig = (0, exports.createServerConfig)(options.serverUrl, options.serverZone, options.useBatch); |
@@ -5,2 +5,4 @@ export { AmplitudeCore } from './core-client'; | ||
export { Destination } from './plugins/destination'; | ||
export { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants'; | ||
export { Config } from './config'; | ||
@@ -15,2 +17,3 @@ export { Logger } from './logger'; | ||
export { createIdentifyEvent } from './utils/event-builder'; | ||
export { buildResult } from './utils/result-builder'; | ||
//# sourceMappingURL=index.d.ts.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0; | ||
exports.buildResult = exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.STORAGE_PREFIX = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.DIAGNOSTIC_ENDPOINT = exports.DIAGNOSTIC_METADATA_TYPE = exports.DIAGNOSTIC_MESSAGES = exports.BaseDiagnostic = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0; | ||
var core_client_1 = require("./core-client"); | ||
@@ -11,2 +11,8 @@ Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } }); | ||
Object.defineProperty(exports, "Destination", { enumerable: true, get: function () { return destination_1.Destination; } }); | ||
var diagnostic_1 = require("./diagnostics/diagnostic"); | ||
Object.defineProperty(exports, "BaseDiagnostic", { enumerable: true, get: function () { return diagnostic_1.BaseDiagnostic; } }); | ||
var constants_1 = require("./diagnostics/constants"); | ||
Object.defineProperty(exports, "DIAGNOSTIC_MESSAGES", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_MESSAGES; } }); | ||
Object.defineProperty(exports, "DIAGNOSTIC_METADATA_TYPE", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_METADATA_TYPE; } }); | ||
Object.defineProperty(exports, "DIAGNOSTIC_ENDPOINT", { enumerable: true, get: function () { return constants_1.DIAGNOSTIC_ENDPOINT; } }); | ||
var config_1 = require("./config"); | ||
@@ -16,5 +22,5 @@ Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } }); | ||
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } }); | ||
var constants_1 = require("./constants"); | ||
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_1.AMPLITUDE_PREFIX; } }); | ||
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return constants_1.STORAGE_PREFIX; } }); | ||
var constants_2 = require("./constants"); | ||
Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_2.AMPLITUDE_PREFIX; } }); | ||
Object.defineProperty(exports, "STORAGE_PREFIX", { enumerable: true, get: function () { return constants_2.STORAGE_PREFIX; } }); | ||
var return_wrapper_1 = require("./utils/return-wrapper"); | ||
@@ -34,2 +40,4 @@ Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } }); | ||
Object.defineProperty(exports, "createIdentifyEvent", { enumerable: true, get: function () { return event_builder_1.createIdentifyEvent; } }); | ||
var result_builder_1 = require("./utils/result-builder"); | ||
Object.defineProperty(exports, "buildResult", { enumerable: true, get: function () { return result_builder_1.buildResult; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -18,2 +18,3 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types'; | ||
send(list: Context[], useRetry?: boolean): Promise<void>; | ||
processResponseDiagnostics(res: Response, list: Context[]): void; | ||
handleResponse(res: Response, list: Context[]): void; | ||
@@ -20,0 +21,0 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void; |
@@ -10,2 +10,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var config_1 = require("../config"); | ||
var constants_2 = require("../diagnostics/constants"); | ||
function getErrorMessage(error) { | ||
@@ -85,2 +86,3 @@ if (error instanceof Error) | ||
void _this.fulfillRequest([context], 500, messages_1.MAX_RETRIES_EXCEEDED_MESSAGE); | ||
_this.config.diagnosticProvider.track(list.length, 500, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY); | ||
return false; | ||
@@ -168,2 +170,3 @@ }); | ||
if (res === null) { | ||
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
this.fulfillRequest(list, 0, messages_1.UNEXPECTED_ERROR_MESSAGE); | ||
@@ -179,2 +182,3 @@ return [2 /*return*/]; | ||
} | ||
this.processResponseDiagnostics(res, list); | ||
return [2 /*return*/]; | ||
@@ -189,2 +193,3 @@ } | ||
this.fulfillRequest(list, 0, errorMessage); | ||
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
return [3 /*break*/, 4]; | ||
@@ -196,2 +201,28 @@ case 4: return [2 /*return*/]; | ||
}; | ||
Destination.prototype.processResponseDiagnostics = function (res, list) { | ||
var status = res.status; | ||
switch (status) { | ||
case analytics_types_1.Status.Invalid: { | ||
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) { | ||
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS); | ||
} | ||
else { | ||
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR); | ||
} | ||
break; | ||
} | ||
case analytics_types_1.Status.PayloadTooLarge: { | ||
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE); | ||
break; | ||
} | ||
case analytics_types_1.Status.RateLimit: { | ||
this.config.diagnosticProvider.track(list.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA); | ||
break; | ||
} | ||
default: { | ||
this.config.diagnosticProvider.track(list.length, 0, constants_2.DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
break; | ||
} | ||
} | ||
}; | ||
Destination.prototype.handleResponse = function (res, list) { | ||
@@ -229,2 +260,5 @@ var status = res.status; | ||
var _this = this; | ||
if (res.body.missingField && !res.body.error.startsWith(messages_1.INVALID_API_KEY)) { | ||
this.config.diagnosticProvider.track(list.length, 400, constants_2.DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS); | ||
} | ||
if (res.body.missingField || res.body.error.startsWith(messages_1.INVALID_API_KEY)) { | ||
@@ -236,2 +270,5 @@ this.fulfillRequest(list, res.statusCode, res.body.error); | ||
var dropIndexSet = new Set(dropIndex); | ||
if (dropIndexSet.size) { | ||
this.config.diagnosticProvider.track(dropIndexSet.size, 400, constants_2.DIAGNOSTIC_MESSAGES.EVENT_ERROR); | ||
} | ||
var retry = list.filter(function (context, index) { | ||
@@ -252,2 +289,3 @@ if (dropIndexSet.has(index)) { | ||
if (list.length === 1) { | ||
this.config.diagnosticProvider.track(list.length, 413, constants_2.DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE); | ||
this.fulfillRequest(list, res.statusCode, res.body.error); | ||
@@ -269,2 +307,3 @@ return; | ||
var throttledIndexSet = new Set(throttledIndex); | ||
var dropList = []; | ||
var retry = list.filter(function (context, index) { | ||
@@ -274,2 +313,3 @@ if ((context.event.user_id && dropUserIdsSet.has(context.event.user_id)) || | ||
_this.fulfillRequest([context], res.statusCode, res.body.error); | ||
dropList.push(context); | ||
return; | ||
@@ -282,2 +322,5 @@ } | ||
}); | ||
if (dropList.length > 0) { | ||
this.config.diagnosticProvider.track(dropList.length, 429, constants_2.DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA); | ||
} | ||
if (retry.length > 0) { | ||
@@ -284,0 +327,0 @@ // log intermediate event status before retry |
@@ -1,3 +0,4 @@ | ||
import { Event, Config as IConfig, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types'; | ||
import { Event, Config as IConfig, Diagnostic, Logger as ILogger, LogLevel, Storage, Transport, Plan, IngestionMetadata, Options, ServerZoneType } from '@amplitude/analytics-types'; | ||
import { Logger } from './logger'; | ||
import { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export declare const getDefaultConfig: () => { | ||
@@ -14,2 +15,3 @@ flushMaxRetries: number; | ||
useBatch: boolean; | ||
diagnosticProvider: BaseDiagnostic; | ||
}; | ||
@@ -32,2 +34,3 @@ export declare class Config implements IConfig { | ||
useBatch: boolean; | ||
diagnosticProvider: Diagnostic; | ||
protected _optOut: boolean; | ||
@@ -34,0 +37,0 @@ get optOut(): boolean; |
import { LogLevel, } from '@amplitude/analytics-types'; | ||
import { AMPLITUDE_SERVER_URL, AMPLITUDE_BATCH_SERVER_URL, EU_AMPLITUDE_SERVER_URL, EU_AMPLITUDE_BATCH_SERVER_URL, } from './constants'; | ||
import { Logger } from './logger'; | ||
import { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export var getDefaultConfig = function () { return ({ | ||
@@ -15,6 +16,7 @@ flushMaxRetries: 12, | ||
useBatch: false, | ||
diagnosticProvider: new BaseDiagnostic(), | ||
}); }; | ||
var Config = /** @class */ (function () { | ||
function Config(options) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
this._optOut = false; | ||
@@ -38,2 +40,6 @@ var defaultConfig = getDefaultConfig(); | ||
this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch; | ||
this.diagnosticProvider = (_e = options.diagnosticProvider) !== null && _e !== void 0 ? _e : defaultConfig.diagnosticProvider; | ||
if (!this.diagnosticProvider.apiKey) { | ||
this.diagnosticProvider.apiKey = this.apiKey; | ||
} | ||
this.loggerProvider.enable(this.logLevel); | ||
@@ -40,0 +46,0 @@ var serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch); |
@@ -5,2 +5,4 @@ export { AmplitudeCore } from './core-client'; | ||
export { Destination } from './plugins/destination'; | ||
export { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants'; | ||
export { Config } from './config'; | ||
@@ -15,2 +17,3 @@ export { Logger } from './logger'; | ||
export { createIdentifyEvent } from './utils/event-builder'; | ||
export { buildResult } from './utils/result-builder'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,2 +5,4 @@ export { AmplitudeCore } from './core-client'; | ||
export { Destination } from './plugins/destination'; | ||
export { BaseDiagnostic } from './diagnostics/diagnostic'; | ||
export { DIAGNOSTIC_MESSAGES, DIAGNOSTIC_METADATA_TYPE, DIAGNOSTIC_ENDPOINT } from './diagnostics/constants'; | ||
export { Config } from './config'; | ||
@@ -15,2 +17,3 @@ export { Logger } from './logger'; | ||
export { createIdentifyEvent } from './utils/event-builder'; | ||
export { buildResult } from './utils/result-builder'; | ||
//# sourceMappingURL=index.js.map |
@@ -18,2 +18,3 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, InvalidResponse, PayloadTooLargeResponse, RateLimitResponse, Response, Result, SuccessResponse } from '@amplitude/analytics-types'; | ||
send(list: Context[], useRetry?: boolean): Promise<void>; | ||
processResponseDiagnostics(res: Response, list: Context[]): void; | ||
handleResponse(res: Response, list: Context[]): void; | ||
@@ -20,0 +21,0 @@ handleSuccessResponse(res: SuccessResponse, list: Context[]): void; |
@@ -8,2 +8,3 @@ import { __awaiter, __generator, __read, __rest, __spreadArray } from "tslib"; | ||
import { createServerConfig } from '../config'; | ||
import { DIAGNOSTIC_MESSAGES } from '../diagnostics/constants'; | ||
function getErrorMessage(error) { | ||
@@ -82,2 +83,3 @@ if (error instanceof Error) | ||
void _this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE); | ||
_this.config.diagnosticProvider.track(list.length, 500, DIAGNOSTIC_MESSAGES.EXCEEDED_MAX_RETRY); | ||
return false; | ||
@@ -165,2 +167,3 @@ }); | ||
if (res === null) { | ||
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE); | ||
@@ -176,2 +179,3 @@ return [2 /*return*/]; | ||
} | ||
this.processResponseDiagnostics(res, list); | ||
return [2 /*return*/]; | ||
@@ -186,2 +190,3 @@ } | ||
this.fulfillRequest(list, 0, errorMessage); | ||
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
return [3 /*break*/, 4]; | ||
@@ -193,2 +198,28 @@ case 4: return [2 /*return*/]; | ||
}; | ||
Destination.prototype.processResponseDiagnostics = function (res, list) { | ||
var status = res.status; | ||
switch (status) { | ||
case Status.Invalid: { | ||
if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) { | ||
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS); | ||
} | ||
else { | ||
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR); | ||
} | ||
break; | ||
} | ||
case Status.PayloadTooLarge: { | ||
this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE); | ||
break; | ||
} | ||
case Status.RateLimit: { | ||
this.config.diagnosticProvider.track(list.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA); | ||
break; | ||
} | ||
default: { | ||
this.config.diagnosticProvider.track(list.length, 0, DIAGNOSTIC_MESSAGES.UNEXPECTED_ERROR); | ||
break; | ||
} | ||
} | ||
}; | ||
Destination.prototype.handleResponse = function (res, list) { | ||
@@ -226,2 +257,5 @@ var status = res.status; | ||
var _this = this; | ||
if (res.body.missingField && !res.body.error.startsWith(INVALID_API_KEY)) { | ||
this.config.diagnosticProvider.track(list.length, 400, DIAGNOSTIC_MESSAGES.INVALID_OR_MISSING_FIELDS); | ||
} | ||
if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) { | ||
@@ -233,2 +267,5 @@ this.fulfillRequest(list, res.statusCode, res.body.error); | ||
var dropIndexSet = new Set(dropIndex); | ||
if (dropIndexSet.size) { | ||
this.config.diagnosticProvider.track(dropIndexSet.size, 400, DIAGNOSTIC_MESSAGES.EVENT_ERROR); | ||
} | ||
var retry = list.filter(function (context, index) { | ||
@@ -249,2 +286,3 @@ if (dropIndexSet.has(index)) { | ||
if (list.length === 1) { | ||
this.config.diagnosticProvider.track(list.length, 413, DIAGNOSTIC_MESSAGES.PAYLOAD_TOO_LARGE); | ||
this.fulfillRequest(list, res.statusCode, res.body.error); | ||
@@ -266,2 +304,3 @@ return; | ||
var throttledIndexSet = new Set(throttledIndex); | ||
var dropList = []; | ||
var retry = list.filter(function (context, index) { | ||
@@ -271,2 +310,3 @@ if ((context.event.user_id && dropUserIdsSet.has(context.event.user_id)) || | ||
_this.fulfillRequest([context], res.statusCode, res.body.error); | ||
dropList.push(context); | ||
return; | ||
@@ -279,2 +319,5 @@ } | ||
}); | ||
if (dropList.length > 0) { | ||
this.config.diagnosticProvider.track(dropList.length, 429, DIAGNOSTIC_MESSAGES.EXCEEDED_DAILY_QUOTA); | ||
} | ||
if (retry.length > 0) { | ||
@@ -281,0 +324,0 @@ // log intermediate event status before retry |
{ | ||
"name": "@amplitude/analytics-core", | ||
"version": "2.1.0", | ||
"version": "2.2.0-featadddiagnostics.0", | ||
"description": "", | ||
@@ -38,3 +38,3 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-types": "^2.3.0", | ||
"@amplitude/analytics-types": "^2.4.0-featadddiagnostics.0", | ||
"tslib": "^2.4.1" | ||
@@ -45,3 +45,3 @@ }, | ||
], | ||
"gitHead": "81c39c33031554f58d1f02e374517b0ee2901c37" | ||
"gitHead": "62aaa6f7715b2f084474ad5834bc41423cae338e" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
408145
211
3938
1