@backtrace/sdk-core
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -88,9 +88,11 @@ import { BacktraceAttachment, BacktraceBreadcrumbs, BacktraceConfiguration, FileSystem, SessionFiles } from '.'; | ||
* @param attachments Report attachments | ||
* @param abortSignal Signal to abort sending | ||
*/ | ||
send(error: Error | string, attributes?: Record<string, unknown>, attachments?: BacktraceAttachment[]): Promise<void>; | ||
send(error: Error | string, attributes?: Record<string, unknown>, attachments?: BacktraceAttachment[], abortSignal?: AbortSignal): Promise<void>; | ||
/** | ||
* Asynchronously sends error data to Backtrace | ||
* @param report Backtrace Report | ||
* @param abortSignal Signal to abort sending | ||
*/ | ||
send(report: BacktraceReport): Promise<void>; | ||
send(report: BacktraceReport, abortSignal?: AbortSignal): Promise<void>; | ||
/** | ||
@@ -97,0 +99,0 @@ * Disposes the client and all client callbacks |
@@ -163,3 +163,3 @@ "use strict"; | ||
// This function CANNOT be an async function due to possible async state machine stack frame inclusion, which breaks the skip stacks | ||
send(data, reportAttributes = {}, reportAttachments = []) { | ||
send(data, reportAttributesOrAbortSignal, reportAttachments = [], abortSignal) { | ||
if (!this._enabled) { | ||
@@ -171,2 +171,8 @@ return Promise.resolve(); | ||
} | ||
// If data is BacktraceReport, we know that the second argument should be only AbortSignal | ||
const reportAttributes = !this.isReport(data) | ||
? reportAttributesOrAbortSignal | ||
: undefined; | ||
// If data is BacktraceReport, we know that the second argument should be only AbortSignal | ||
abortSignal = !this.isReport(data) ? abortSignal : reportAttributesOrAbortSignal; | ||
const report = this.isReport(data) | ||
@@ -187,3 +193,5 @@ ? data | ||
this.reportEvents.emit('before-send', report, backtraceData, submissionAttachments); | ||
return this._reportSubmission.send(backtraceData, submissionAttachments).then((submissionResult) => { | ||
return this._reportSubmission | ||
.send(backtraceData, submissionAttachments, abortSignal) | ||
.then((submissionResult) => { | ||
this.reportEvents.emit('after-send', report, backtraceData, submissionAttachments, submissionResult); | ||
@@ -190,0 +198,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Delay = void 0; | ||
const AbortError_1 = require("./AbortError"); | ||
class Delay { | ||
@@ -12,7 +13,14 @@ /** | ||
return new Promise((resolve, reject) => { | ||
// intervalId has to be defined here, | ||
// as abortCallback can execute before setTimeout is executed | ||
// eslint-disable-next-line prefer-const | ||
let intervalId; | ||
function abortCallback() { | ||
clearTimeout(intervalId); | ||
reject(new Error('Operation cancelled.')); | ||
reject(new AbortError_1.AbortError()); | ||
} | ||
const intervalId = setTimeout(() => { | ||
if (signal === null || signal === void 0 ? void 0 : signal.aborted) { | ||
return abortCallback(); | ||
} | ||
intervalId = setTimeout(() => { | ||
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abortCallback); | ||
@@ -19,0 +27,0 @@ resolve(); |
@@ -5,2 +5,3 @@ export * from './BacktraceCoreClient'; | ||
export * from './builder/SdkOptions'; | ||
export { anySignal } from './common/AbortController'; | ||
export * from './common/IdGenerator'; | ||
@@ -7,0 +8,0 @@ export * from './common/TimeHelper'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.anySignal = void 0; | ||
__exportStar(require("./BacktraceCoreClient"), exports); | ||
@@ -22,2 +23,4 @@ __exportStar(require("./builder/BacktraceCoreClientBuilder"), exports); | ||
__exportStar(require("./builder/SdkOptions"), exports); | ||
var AbortController_1 = require("./common/AbortController"); | ||
Object.defineProperty(exports, "anySignal", { enumerable: true, get: function () { return AbortController_1.anySignal; } }); | ||
__exportStar(require("./common/IdGenerator"), exports); | ||
@@ -24,0 +27,0 @@ __exportStar(require("./common/TimeHelper"), exports); |
@@ -8,3 +8,3 @@ import { BacktraceAttachment } from '../attachment'; | ||
export interface BacktraceReportSubmission { | ||
send(data: BacktraceData, attachments: BacktraceAttachment[]): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
send(data: BacktraceData, attachments: BacktraceAttachment[], abortSignal?: AbortSignal): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
} | ||
@@ -15,3 +15,3 @@ export declare class RequestBacktraceReportSubmission { | ||
constructor(options: BacktraceConfiguration, _requestHandler: BacktraceRequestHandler); | ||
send(data: BacktraceData, attachments: BacktraceAttachment[]): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
send(data: BacktraceData, attachments: BacktraceAttachment[], abortSignal?: AbortSignal): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
} |
@@ -11,5 +11,5 @@ "use strict"; | ||
} | ||
send(data, attachments) { | ||
send(data, attachments, abortSignal) { | ||
const json = JSON.stringify(data, (0, jsonEscaper_1.jsonEscaper)()); | ||
return this._requestHandler.postError(this._submissionUrl, json, attachments); | ||
return this._requestHandler.postError(this._submissionUrl, json, attachments, abortSignal); | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -11,5 +11,6 @@ import { BacktraceAttachment } from '../attachment'; | ||
* @param attachments Report attachments | ||
* @param abortSignal Signal to abort sending | ||
* @returns Submission result | ||
*/ | ||
postError(submissionUrl: string, dataJson: string, attachments: BacktraceAttachment[]): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
postError(submissionUrl: string, dataJson: string, attachments: BacktraceAttachment[], abortSignal?: AbortSignal): Promise<BacktraceReportSubmissionResult<BacktraceSubmissionResponse>>; | ||
/** | ||
@@ -19,4 +20,5 @@ * Post data to Backtrace API | ||
* @param payload request payload | ||
* @param abortSignal Signal to abort sending | ||
*/ | ||
post<T>(submissionUrl: string, payload: string): Promise<BacktraceReportSubmissionResult<T>>; | ||
post<T>(submissionUrl: string, payload: string, abortSignal?: AbortSignal): Promise<BacktraceReportSubmissionResult<T>>; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { BacktraceBreadcrumbs, BreadcrumbLogLevel, BreadcrumbType, BreadcrumbsSetup, BreadcrumbsStorage } from '.'; | ||
import { BacktraceBreadcrumbs, BreadcrumbLogLevel, BreadcrumbsSetup, BreadcrumbsStorage, BreadcrumbType } from '.'; | ||
import { BacktraceBreadcrumbsSettings } from '../../model/configuration/BacktraceConfiguration'; | ||
@@ -37,2 +37,10 @@ import { AttributeType } from '../../model/data/BacktraceData'; | ||
addBreadcrumb(message: string, level: BreadcrumbLogLevel, type: BreadcrumbType, attributes?: Record<string, AttributeType> | undefined): boolean; | ||
/** | ||
* The expectation is, message should always be defined and passed as string. | ||
* However, logger can pass as a message an object or any other unknown type. | ||
* To be sure the code won't break, this method ensures the message is always a string | ||
* no matter what the logger gives us. | ||
* @param message breadcrumb message | ||
*/ | ||
private prepareBreadcrumbMessage; | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
const _1 = require("."); | ||
const jsonEscaper_1 = require("../../common/jsonEscaper"); | ||
const ConsoleEventSubscriber_1 = require("./events/ConsoleEventSubscriber"); | ||
@@ -85,3 +86,3 @@ const InMemoryBreadcrumbsStorage_1 = require("./storage/InMemoryBreadcrumbsStorage"); | ||
let rawBreadcrumb = { | ||
message, | ||
message: this.prepareBreadcrumbMessage(message), | ||
level, | ||
@@ -107,4 +108,28 @@ type, | ||
} | ||
/** | ||
* The expectation is, message should always be defined and passed as string. | ||
* However, logger can pass as a message an object or any other unknown type. | ||
* To be sure the code won't break, this method ensures the message is always a string | ||
* no matter what the logger gives us. | ||
* @param message breadcrumb message | ||
*/ | ||
prepareBreadcrumbMessage(message) { | ||
if (message == null) { | ||
return ''; | ||
} | ||
const messageType = typeof message; | ||
switch (messageType) { | ||
case 'string': { | ||
return message; | ||
} | ||
case 'object': { | ||
return JSON.stringify(message, (0, jsonEscaper_1.jsonEscaper)()); | ||
} | ||
default: { | ||
return message.toString(); | ||
} | ||
} | ||
} | ||
} | ||
exports.BreadcrumbsManager = BreadcrumbsManager; | ||
//# sourceMappingURL=BreadcrumbsManager.js.map |
@@ -5,3 +5,5 @@ import { BacktraceStackFrame } from '../../model/data/BacktraceStackTrace'; | ||
export declare class V8StackTraceConverter implements BacktraceStackTraceConverter { | ||
readonly addressSeparator: string; | ||
get engine(): JavaScriptEngine; | ||
constructor(addressSeparator?: string); | ||
convert(stackTrace: string, message: string): BacktraceStackFrame[]; | ||
@@ -8,0 +10,0 @@ private parseFrame; |
@@ -9,2 +9,5 @@ "use strict"; | ||
} | ||
constructor(addressSeparator = '') { | ||
this.addressSeparator = addressSeparator; | ||
} | ||
convert(stackTrace, message) { | ||
@@ -52,2 +55,5 @@ const result = []; | ||
} | ||
if (this.addressSeparator && sourceCodeInformation.startsWith(this.addressSeparator)) { | ||
sourceCodeInformation = sourceCodeInformation.substring(this.addressSeparator.length).trimStart(); | ||
} | ||
const sourceCodeParts = sourceCodeInformation.split(':'); | ||
@@ -54,0 +60,0 @@ const column = parseInt(sourceCodeParts[sourceCodeParts.length - 1]); |
@@ -27,2 +27,3 @@ import { BacktraceMetricsOptions } from '../../model/configuration/BacktraceConfiguration'; | ||
private _updateIntervalId?; | ||
private readonly _abortController; | ||
constructor(_options: BacktraceMetricsOptions, _sessionProvider: BacktraceSessionProvider, _attributeManager: AttributeManager, _summedEventsSubmissionQueue: MetricsQueue<SummedEvent>, _uniqueEventsSubmissionQueue: MetricsQueue<UniqueEvent>); | ||
@@ -46,3 +47,3 @@ /** | ||
*/ | ||
send(): boolean; | ||
send(abortSignal?: AbortSignal): Promise<boolean>; | ||
/** | ||
@@ -58,2 +59,3 @@ * Cleans up metrics interface. | ||
private convertAttributes; | ||
private handleAbort; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BacktraceMetrics = void 0; | ||
const AbortController_1 = require("../../common/AbortController"); | ||
const AbortError_1 = require("../../common/AbortError"); | ||
const TimeHelper_1 = require("../../common/TimeHelper"); | ||
@@ -29,2 +40,3 @@ const ReportDataBuilder_1 = require("../attribute/ReportDataBuilder"); | ||
this._updateInterval = (_b = this._options.autoSendInterval) !== null && _b !== void 0 ? _b : this.DEFAULT_UPDATE_INTERVAL; | ||
this._abortController = (0, AbortController_1.createAbortController)(); | ||
} | ||
@@ -39,3 +51,3 @@ /** | ||
this.addSummedEvent('Application Launches'); | ||
this.send(); | ||
this.handleAbort(() => this.send(this._abortController.signal)); | ||
if (this._updateInterval === 0) { | ||
@@ -45,3 +57,3 @@ return; | ||
this._updateIntervalId = setInterval(() => { | ||
this.send(); | ||
this.handleAbort(() => this.send(this._abortController.signal)); | ||
}, this._updateInterval); | ||
@@ -72,10 +84,11 @@ } | ||
*/ | ||
send() { | ||
if (!this._sessionProvider.shouldSend()) { | ||
return false; | ||
} | ||
this.sendUniqueEvent(); | ||
this._summedEventsSubmissionQueue.send(); | ||
this._sessionProvider.afterMetricsSubmission(); | ||
return true; | ||
send(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this._sessionProvider.shouldSend()) { | ||
return false; | ||
} | ||
yield Promise.all([this.sendUniqueEvent(abortSignal), this._summedEventsSubmissionQueue.send(abortSignal)]); | ||
this._sessionProvider.afterMetricsSubmission(); | ||
return true; | ||
}); | ||
} | ||
@@ -86,11 +99,16 @@ /** | ||
dispose() { | ||
this._abortController.abort(); | ||
if (this._updateIntervalId) { | ||
clearInterval(this._updateIntervalId); | ||
} | ||
this._uniqueEventsSubmissionQueue.dispose && this._uniqueEventsSubmissionQueue.dispose(); | ||
this._summedEventsSubmissionQueue.dispose && this._summedEventsSubmissionQueue.dispose(); | ||
} | ||
sendUniqueEvent() { | ||
// always add the same unique event before send. | ||
const { attributes } = this._attributeManager.get(); | ||
this._uniqueEventsSubmissionQueue.add(new UniqueEvent_1.UniqueEvent(this.convertAttributes(attributes))); | ||
this._uniqueEventsSubmissionQueue.send(); | ||
sendUniqueEvent(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// always add the same unique event before send. | ||
const { attributes } = this._attributeManager.get(); | ||
this._uniqueEventsSubmissionQueue.add(new UniqueEvent_1.UniqueEvent(this.convertAttributes(attributes))); | ||
yield this._uniqueEventsSubmissionQueue.send(abortSignal); | ||
}); | ||
} | ||
@@ -110,4 +128,18 @@ /** | ||
} | ||
handleAbort(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield fn(); | ||
return true; | ||
} | ||
catch (err) { | ||
if (err instanceof AbortError_1.AbortError) { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
}); | ||
} | ||
} | ||
exports.BacktraceMetrics = BacktraceMetrics; | ||
//# sourceMappingURL=BacktraceMetrics.js.map |
@@ -6,3 +6,4 @@ export interface MetricsQueue<T> { | ||
add(event: T): void; | ||
send(): Promise<void>; | ||
send(abortSignal?: AbortSignal): Promise<void>; | ||
dispose?(): void; | ||
} |
@@ -15,6 +15,8 @@ import { BacktraceRequestHandler } from '../../model/http'; | ||
private _numberOfDroppedRequests; | ||
private readonly _abortController; | ||
private readonly MAXIMUM_NUMBER_OF_ATTEMPTS; | ||
constructor(_submissionUrl: string, _eventName: string, _requestHandler: BacktraceRequestHandler, _metricMetadata: Record<string, unknown>, maximumEvents?: number); | ||
add(event: T): void; | ||
send(): Promise<void>; | ||
send(abortSignal?: AbortSignal): Promise<void>; | ||
dispose(): void; | ||
private submit; | ||
@@ -21,0 +23,0 @@ private returnEventsIfPossible; |
@@ -13,5 +13,6 @@ "use strict"; | ||
exports.MetricsSubmissionQueue = void 0; | ||
const AbortController_1 = require("../../common/AbortController"); | ||
const DelayHelper_1 = require("../../common/DelayHelper"); | ||
const TimeHelper_1 = require("../../common/TimeHelper"); | ||
const jsonEscaper_1 = require("../../common/jsonEscaper"); | ||
const TimeHelper_1 = require("../../common/TimeHelper"); | ||
class MetricsSubmissionQueue { | ||
@@ -34,2 +35,3 @@ get total() { | ||
this.MAXIMUM_NUMBER_OF_ATTEMPTS = 3; | ||
this._abortController = (0, AbortController_1.createAbortController)(); | ||
} | ||
@@ -42,9 +44,12 @@ add(event) { | ||
} | ||
send() { | ||
send(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const eventsToProcess = this._events.splice(0); | ||
return yield this.submit(eventsToProcess); | ||
return yield this.submit(eventsToProcess, (0, AbortController_1.anySignal)(abortSignal, this._abortController.signal)); | ||
}); | ||
} | ||
submit(events) { | ||
dispose() { | ||
this._abortController.abort(); | ||
} | ||
submit(events, abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -54,3 +59,3 @@ for (let attempts = 0; attempts < this.MAXIMUM_NUMBER_OF_ATTEMPTS; attempts++) { | ||
dropped_events: this._numberOfDroppedRequests, | ||
} }), (0, jsonEscaper_1.jsonEscaper)())); | ||
} }), (0, jsonEscaper_1.jsonEscaper)()), abortSignal); | ||
if (response.status === 'Ok') { | ||
@@ -61,3 +66,3 @@ this._numberOfDroppedRequests = 0; | ||
this._numberOfDroppedRequests++; | ||
yield DelayHelper_1.Delay.wait(Math.pow(2, attempts) * this.DELAY_BETWEEN_REQUESTS); | ||
yield DelayHelper_1.Delay.wait(Math.pow(2, attempts) * this.DELAY_BETWEEN_REQUESTS, abortSignal); | ||
} | ||
@@ -64,0 +69,0 @@ // if the code reached this line, it means, we couldn't send data to server |
{ | ||
"name": "@backtrace/sdk-core", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Backtrace-JavaScript SDK core library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
291752
279
4714
1