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

feat: error reporting plugin #1601

Merged
merged 47 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d6be68d
feat: error reporting plugin
MoumitaM Jan 30, 2024
1a7757f
chore: size limit updated
MoumitaM Jan 30, 2024
183e15c
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jan 30, 2024
edfcaa8
chore: size limit updated
MoumitaM Jan 30, 2024
3e07d44
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jan 30, 2024
97a6a99
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jan 31, 2024
97c049e
chore: refactor onerror fn and minor changes
MoumitaM Jan 31, 2024
0b2eed8
chore: review comment addressed
MoumitaM Feb 1, 2024
10f7ce8
refactor: instead of bugsnag core pkg used only required part of even…
MoumitaM Feb 7, 2024
35c89e2
chore: code refactoring
MoumitaM Feb 7, 2024
76b4305
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Feb 7, 2024
cb6e0e8
chore: code refactoring
MoumitaM Feb 8, 2024
ebb0bdf
chore: review commit addressed
MoumitaM Feb 9, 2024
95e68b5
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Feb 9, 2024
a05de70
chore: review comment addressed
MoumitaM Feb 9, 2024
7009640
chore: modified isruddersdkerror fn logic to filter integration sdk e…
MoumitaM Feb 11, 2024
650d8e1
chore: fix plugin loading
MoumitaM Feb 12, 2024
5a50cb3
chore: log message updated
MoumitaM Feb 12, 2024
1cdcd12
chore: resolve conflict
MoumitaM Feb 22, 2024
d2f141f
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
bardisg Feb 22, 2024
a9eccd1
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Feb 26, 2024
dea1395
chore: used template literal instead of string concatenation in rollup
MoumitaM Feb 26, 2024
3b48ef4
chore: resolve merge conflicts
MoumitaM Jul 3, 2024
2a6cbd7
fix: unit test cases
MoumitaM Jul 3, 2024
86f74f3
chore: resolve merge conflict
MoumitaM Jul 4, 2024
d3e89ae
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jul 5, 2024
d2683ed
chore: unit test cases
MoumitaM Jul 8, 2024
99b3c68
chore: lock file modified
MoumitaM Jul 8, 2024
668da10
chore: more unit tests
MoumitaM Jul 8, 2024
679a0e8
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jul 8, 2024
1556c0a
chore: ignore coverage for third party code
MoumitaM Jul 8, 2024
bc486f7
chore: ignore coverage for third party code in sonar
MoumitaM Jul 9, 2024
5c3489c
chore: test cases
MoumitaM Jul 9, 2024
8ba6802
chore: ignore coverage for third party code in sonar
MoumitaM Jul 9, 2024
8dfa5f5
chore: remove reference
MoumitaM Jul 10, 2024
f217c93
chore: revert formatting changes
MoumitaM Jul 10, 2024
b29f0d7
chore: address review comments
MoumitaM Jul 11, 2024
7a13456
chore: address review comments
MoumitaM Jul 11, 2024
fd1e424
chore: updated plugin signature for backward compatibility
MoumitaM Jul 15, 2024
55a7a9f
chore: added bugsnag plugin for backward compatibility
MoumitaM Jul 17, 2024
786928c
Merge branch 'develop' into feature/sdk-1096-error-reporting-plugin
MoumitaM Jul 17, 2024
0651b04
chore: size limit updated
MoumitaM Jul 17, 2024
017be47
chore: review comment address
MoumitaM Jul 18, 2024
5ee27fc
chore: update metrics service url
MoumitaM Jul 18, 2024
0b7e6fb
chore: address review comment
MoumitaM Jul 18, 2024
e2e94f3
chore: address review comment
MoumitaM Jul 18, 2024
a1bdc87
chore: address review comment
MoumitaM Jul 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('Error Reporting utilities', () => {
console.log(JSON.stringify(enhancedError));
const expectedOutcome = {
notifier: {
name: 'Rudderstack JavaScript SDK Error Notifier',
name: 'RudderStack JavaScript SDK Error Notifier',
version: '__PACKAGE_VERSION__',
url: 'https://github.com/rudderlabs/rudder-sdk-js',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const APP_STATE_EXCLUDE_KEYS = [
'traits',
];
const REQUEST_TIMEOUT_MS = 10 * 1000; // 10 seconds
const NOTIFIER_NAME = 'Rudderstack JavaScript SDK Error Notifier';
const NOTIFIER_NAME = 'RudderStack JavaScript SDK Error Notifier';
const SDK_GITHUB_URL = 'https://github.com/rudderlabs/rudder-sdk-js';
const SOURCE_NAME = 'js';

Expand Down
3 changes: 2 additions & 1 deletion packages/analytics-js-plugins/src/errorReporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { ErrorState, SDKError } from '@rudderstack/analytics-js-common/types/ErrorHandler';
import { Event } from '@bugsnag/core';
import type { IHttpClient } from '@rudderstack/analytics-js-common/types/HttpClient';
import { clone } from 'ramda';
import {
createNewBreadCrumb,
getConfigForPayloadCreation,
Expand Down Expand Up @@ -51,12 +52,12 @@

// filter errors
if (!isRudderSDKError(errorPayload.errors[0])) {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
return;

Check warning on line 55 in packages/analytics-js-plugins/src/errorReporting/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-plugins/src/errorReporting/index.ts#L55

Added line #L55 was not covered by tests
}

// attach breadcrumbs
if (state.reporting.breadCrumbs.value.length > 0) {
errorPayload.breadcrumbs = state.reporting.breadCrumbs.value;
errorPayload.breadcrumbs = clone(state.reporting.breadCrumbs.value);

Check warning on line 60 in packages/analytics-js-plugins/src/errorReporting/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-plugins/src/errorReporting/index.ts#L60

Added line #L60 was not covered by tests
}

// enrich error payload
Expand All @@ -80,7 +81,7 @@
},
breadcrumb: (message: string, state: ApplicationState, metaData?: BreadCrumbMetaData): void => {
if (!message) {
return;

Check warning on line 84 in packages/analytics-js-plugins/src/errorReporting/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-plugins/src/errorReporting/index.ts#L84

Added line #L84 was not covered by tests
}
state.reporting.breadCrumbs.value = [
...state.reporting.breadCrumbs.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SDKError } from '@rudderstack/analytics-js-common/types/ErrorHandler';
import type { SDKError } from '@rudderstack/analytics-js-common/types/ErrorHandler';
import { defaultHttpClient } from '../../../src/services/HttpClient';
import { defaultLogger } from '../../../src/services/Logger';
import { defaultPluginEngine } from '../../../src/services/PluginEngine';
import { ErrorHandler } from '../../../src/services/ErrorHandler';
import { state } from '../../../src/state';
import { state, resetState } from '../../../src/state';

jest.mock('../../../src/services/Logger', () => {
const originalModule = jest.requireActual('../../../src/services/Logger');
Expand Down Expand Up @@ -43,6 +43,7 @@ describe('ErrorHandler', () => {
let errorHandlerInstance: ErrorHandler;

beforeEach(() => {
resetState();
errorHandlerInstance = new ErrorHandler(defaultLogger, defaultPluginEngine, defaultHttpClient);
});

Expand Down Expand Up @@ -78,6 +79,8 @@ describe('ErrorHandler', () => {
});

it('should log error for Errors with context and custom message if logger exists', () => {
state.reporting.isErrorReportingEnabled.value = true;
state.reporting.isErrorReportingPluginLoaded.value = true;
errorHandlerInstance.onError(new Error('dummy error'), 'Unit test', 'dummy custom message');

expect(defaultPluginEngine.invokeSingle).toHaveBeenCalledTimes(1);
Expand All @@ -101,6 +104,8 @@ describe('ErrorHandler', () => {
});

it('should log error for messages with context and custom message if logger exists', () => {
state.reporting.isErrorReportingEnabled.value = true;
state.reporting.isErrorReportingPluginLoaded.value = true;
errorHandlerInstance.onError('dummy error', 'Unit test', 'dummy custom message');

expect(defaultPluginEngine.invokeSingle).toHaveBeenCalledTimes(1);
Expand All @@ -125,6 +130,8 @@ describe('ErrorHandler', () => {

it('should log and throw for messages with context and custom message if logger exists and shouldAlwaysThrow', () => {
try {
state.reporting.isErrorReportingEnabled.value = true;
state.reporting.isErrorReportingPluginLoaded.value = true;
errorHandlerInstance.onError('dummy error', 'Unit test', 'dummy custom message', true);
} catch (err) {
expect(defaultPluginEngine.invokeSingle).toHaveBeenCalledTimes(1);
Expand Down
28 changes: 15 additions & 13 deletions packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

if (errorToProcess) {
// send it to the plugin
this.notifyError(errorToProcess.error, errorToProcess.errorState);

Check warning on line 47 in packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts#L47

Added line #L47 was not covered by tests
}
}
}
Expand Down Expand Up @@ -101,20 +101,22 @@
});
}

if (
state.reporting.isErrorReportingEnabled.value &&
!state.reporting.isErrorReportingPluginLoaded.value
) {
// buffer the error
this.errorBuffer.enqueue({ error, errorState });
} else {
// send it to plugin
// eslint-disable-next-line no-lonely-if
if (errorType === 'handledException') {
this.notifyError(normalizedError, errorState);
} else {
this.notifyError(error, errorState);
const isErrorReportingEnabled = state.reporting.isErrorReportingEnabled.value;
const isErrorReportingPluginLoaded = state.reporting.isErrorReportingPluginLoaded.value;
try {
if (isErrorReportingEnabled) {
if (!isErrorReportingPluginLoaded) {
// buffer the error
this.errorBuffer.enqueue({

Check warning on line 110 in packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts#L110

Added line #L110 was not covered by tests
error: errorType === 'handledException' ? normalizedError : error,
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
errorState,
});
} else {
this.notifyError(errorType === 'handledException' ? normalizedError : error, errorState);
}
}
} catch (e) {
this.logger?.error(NOTIFY_FAILURE_ERROR(ERROR_HANDLER), e);
}

if (errorType === 'handledException') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
if ((error instanceof Error || error instanceof ErrorEvent) && error.message) {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
return !ERROR_MESSAGES_TO_BE_FILTERED.some(e => error.message.includes(e));
}
if (error instanceof PromiseRejectionEvent && error.reason) {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
return !ERROR_MESSAGES_TO_BE_FILTERED.some(e => error.reason.includes(e));

Check warning on line 59 in packages/analytics-js/src/services/ErrorHandler/processError.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js/src/services/ErrorHandler/processError.ts#L59

Added line #L59 was not covered by tests
}
return true;
};

Expand Down
Loading