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: move error reporting functionality to the core module #1984

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
02d2f5d
feat: move error reporting functionality to the core module
saikumarrs Dec 31, 2024
b93cb5a
chore: remove unnecessary console statement in test suite
saikumarrs Jan 2, 2025
3026f5f
chore: delete duplicate constants file
saikumarrs Jan 2, 2025
9b0f514
chore: restore error messages filtering logic
saikumarrs Jan 2, 2025
3fd7a5a
refactor: move code around to the right places
saikumarrs Jan 2, 2025
65e3190
chore: remove unnecessary test suites
saikumarrs Jan 2, 2025
9a8df29
fix: error filtering and logging
saikumarrs Jan 2, 2025
c34b0a2
chore: fix test target
saikumarrs Jan 2, 2025
d40d8cf
test: add tests for errorhandler
saikumarrs Jan 2, 2025
702aeb6
test: add more test cases for coverage
saikumarrs Jan 2, 2025
d5d6dff
refactor: remove the need to create new http client
saikumarrs Jan 2, 2025
d1b9ac4
test: refactor browser test suite
saikumarrs Jan 2, 2025
a30f526
chore: adjust size limits
saikumarrs Jan 2, 2025
d2e051e
test: improve browser test suite
saikumarrs Jan 2, 2025
059388a
test: improve code coverage
saikumarrs Jan 2, 2025
a3d8561
chore: use sonarqube scan
saikumarrs Jan 3, 2025
69ac89b
chore: minor improvements
saikumarrs Jan 3, 2025
cb0f336
chore: minor improvements 2
saikumarrs Jan 3, 2025
115ab6a
fix: error handling
saikumarrs Jan 3, 2025
733387f
refactor: address ai bot review comments
saikumarrs Jan 3, 2025
f51cb95
test: add missing unit test for source configuration data
saikumarrs Jan 3, 2025
c852699
chore: address ai bot review comments
saikumarrs Jan 3, 2025
cb8e1d8
fix: user and context details in the error payload
saikumarrs Jan 3, 2025
5c1fbe4
chore: remove invalid test case
saikumarrs Jan 3, 2025
a590ed8
test: fix failing tests
saikumarrs Jan 3, 2025
75f05c6
fix: restore user name in the payload type
saikumarrs Jan 3, 2025
7e0d815
chore: replace deprecated jest apis
saikumarrs Jan 3, 2025
a749734
Merge remote-tracking branch 'origin/develop' into feat.move-error-re…
saikumarrs Jan 7, 2025
4606387
chore: avoid fixing paths in reports
saikumarrs Jan 7, 2025
6e6dba8
chore: fix reports paths to relative
saikumarrs Jan 7, 2025
10bf1a8
chore: fix report paths
saikumarrs Jan 7, 2025
dcf0c70
Merge remote-tracking branch 'origin/develop' into feat.move-error-re…
saikumarrs Jan 7, 2025
8cf04e3
Merge remote-tracking branch 'origin/develop' into feat.move-error-re…
saikumarrs Jan 8, 2025
073c1c6
fix: error message prefix
saikumarrs Jan 9, 2025
96c79cc
fix: allow errors with simple stack trace
saikumarrs Jan 9, 2025
cd9b9e9
fix: add custom message separator
saikumarrs Jan 9, 2025
f623d4b
fix: filter only unhandled errors
saikumarrs Jan 9, 2025
56afb07
fix: callback invocations
saikumarrs Jan 9, 2025
85f5ac0
fix: remove unwanted error handling logic
saikumarrs Jan 9, 2025
7fd54ba
test: add more test cases for coverage
saikumarrs Jan 9, 2025
1b0b0db
test: add more test cases for coverage
saikumarrs Jan 9, 2025
e67f70e
test: add more test cases for improving coverage of error handler
saikumarrs Jan 9, 2025
7a74983
fix: add missing event properties
saikumarrs Jan 10, 2025
a59a002
test: add more test cases for improving coverage of error handler
saikumarrs Jan 10, 2025
c9c6453
test: add more test cases for improving coverage in multiple modules
saikumarrs Jan 10, 2025
ef841ae
test: add more test cases for improving coverage in config manager
saikumarrs Jan 10, 2025
0ecb545
test: add more test cases for improving coverage in plugin engine
saikumarrs Jan 10, 2025
8451e77
test: address ai bot review comments
saikumarrs Jan 10, 2025
f27ad1c
Merge remote-tracking branch 'origin/develop' into feat.move-error-re…
saikumarrs Jan 12, 2025
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
9 changes: 3 additions & 6 deletions packages/analytics-js-common/__mocks__/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { IErrorHandler, PreLoadErrorData } from '../src/types/ErrorHandler';
import { BufferQueue } from './BufferQueue';
import type { IErrorHandler } from '../src/types/ErrorHandler';
import { defaultHttpClient } from './HttpClient';

// Mock all the methods of the ErrorHandler class
class ErrorHandler implements IErrorHandler {
onError = jest.fn();
leaveBreadcrumb = jest.fn();
notifyError = jest.fn();
init = jest.fn();
attachErrorListeners = jest.fn();
errorBuffer = new BufferQueue<PreLoadErrorData>();
httpClient = defaultHttpClient;
}

const defaultErrorHandler = new ErrorHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HttpClient implements IHttpClient {
getAsyncData = jest.fn();
setAuthHeader = jest.fn();
resetAuthHeader = jest.fn();
init = jest.fn();
}

const defaultHttpClient = new HttpClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ErrorState } from '../../types/ErrorHandler';
import type { ErrorState, IErrorHandler } from '../../types/ErrorHandler';
import type { ILogger } from '../../types/Logger';

export interface IExternalSourceLoadConfig {
Expand All @@ -11,16 +11,7 @@ export interface IExternalSourceLoadConfig {
}

export interface IExternalSrcLoader {
errorHandler?: {
onError(
error: unknown,
context?: string,
customMessage?: string,
shouldAlwaysThrow?: boolean,
): void;
leaveBreadcrumb(breadcrumb: string): void;
notifyError(error: Error, errorState: ErrorState): void;
};
errorHandler?: IErrorHandler;
logger?: ILogger;
timeout: number;
loadJSFile(config: IExternalSourceLoadConfig): void;
Expand Down
17 changes: 2 additions & 15 deletions packages/analytics-js-common/src/types/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import type { IPluginEngine } from './PluginEngine';
import type { ILogger } from './Logger';
import type { BufferQueue } from '../services/BufferQueue/BufferQueue';
import type { IHttpClient } from './HttpClient';
import type { IExternalSrcLoader } from '../services/ExternalSrcLoader/types';

export type SDKError = unknown | Error | ErrorEvent | Event | PromiseRejectionEvent;

export interface IErrorHandler {
httpClient: IHttpClient;
logger?: ILogger;
pluginEngine?: IPluginEngine;
errorBuffer: BufferQueue<PreLoadErrorData>;
init(httpClient: IHttpClient, externalSrcLoader: IExternalSrcLoader): void;
onError(
error: SDKError,
context?: string,
customMessage?: string,
shouldAlwaysThrow?: boolean,
errorType?: string,
): void;
onError(error: SDKError, context?: string, customMessage?: string, errorType?: string): void;
leaveBreadcrumb(breadcrumb: string): void;
notifyError(error: Error, errorState: ErrorState): void;
attachErrorListeners(): void;
}

export type ErrorState = {
Expand Down
1 change: 1 addition & 0 deletions packages/analytics-js-common/src/types/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export interface IHttpClient {
getAsyncData<T = any>(config: IAsyncRequestConfig<T>): void;
setAuthHeader(value: string, noBto?: boolean): void;
resetAuthHeader(): void;
init(errorHandler: IErrorHandler): void;
}
22 changes: 12 additions & 10 deletions packages/analytics-js-common/src/types/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ export type MetricServicePayload = {
};

export type ErrorEventPayload = {
payloadVersion: string;
notifier: {
name: string;
version: string;
url: string;
};
events: ErrorEventType[];
events: ErrorEvent[];
};

export type ErrorEventType = {
payloadVersion: string;
export type ErrorEvent = {
exceptions: Exception[];
severity: string;
unhandled: boolean;
severityReason: { type: string };
app: {
version: string;
releaseStage: string;
type: string;
};
device: {
locale?: string;
Expand All @@ -41,25 +42,19 @@ export type ErrorEventType = {
clientIp: string;
};
breadcrumbs: Breadcrumb[] | [];
context: string;
metaData: {
[index: string]: any;
};
user: {
id: string;
name: string;
};
};

export type GeneratedEventType = {
errors: Exception[];
};

export interface Exception {
message: string;
errorClass: string;
type: string;
stacktrace: Stackframe[];
}
export interface Stackframe {
file: string;
method?: string;
Expand All @@ -68,3 +63,10 @@ export interface Stackframe {
code?: Record<string, string>;
inProject?: boolean;
}

export interface Exception {
message: string;
errorClass: string;
type: string;
stacktrace: Stackframe[];
}
2 changes: 0 additions & 2 deletions packages/analytics-js-common/src/types/PluginsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ export interface IPluginsManager {

export type PluginName =
| 'BeaconQueue'
| 'Bugsnag'
| 'CustomConsentManager'
| 'DeviceModeDestinations'
| 'DeviceModeTransformation'
| 'ErrorReporting'
| 'ExternalAnonymousId'
| 'GoogleLinker'
| 'IubendaConsentManager'
Expand Down
1 change: 1 addition & 0 deletions packages/analytics-js-common/src/types/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export type SourceConfig = {
export type Source = {
id: string;
config?: SourceConfig;
name: string;
workspaceId: string;
};
1 change: 0 additions & 1 deletion packages/analytics-js-plugins/__mocks__/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const defaultStateValues: ApplicationState = {
reporting: {
isErrorReportingEnabled: signal(false),
isMetricsReportingEnabled: signal(false),
isErrorReportingPluginLoaded: signal(false),
breadcrumbs: signal([]),
},
session: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defaultErrorHandler } from '@rudderstack/analytics-js-common/__mocks__/
import { defaultLogger } from '@rudderstack/analytics-js-common/__mocks__/Logger';
import { defaultStoreManager } from '@rudderstack/analytics-js-common/__mocks__/StoreManager';
import type { ExtensionPoint } from '@rudderstack/analytics-js-common/types/PluginEngine';
import { defaultHttpClient } from '@rudderstack/analytics-js-common/__mocks__/HttpClient';
import * as utils from '../../src/deviceModeTransformation/utilities';
import { DeviceModeTransformation } from '../../src/deviceModeTransformation';
import {
Expand All @@ -15,7 +16,6 @@ import {
} from '../../__fixtures__/fixtures';
import { server } from '../../__fixtures__/msw.server';
import { resetState, state } from '../../__mocks__/state';
import { defaultHttpClient } from '../../__mocks__/HttpClient';
import { defaultPluginsManager } from '../../__mocks__/PluginsManager';
import type { RetryQueue } from '../../src/utilities/retryQueue/RetryQueue';
import type { QueueItem, QueueItemData } from '../../src/types/plugins';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type { RudderEvent } from '@rudderstack/analytics-js-common/types/Event';
import { defaultLogger } from '@rudderstack/analytics-js-common/__mocks__/Logger';
import { defaultErrorHandler } from '@rudderstack/analytics-js-common/__mocks__/ErrorHandler';
import type { ExtensionPoint } from '@rudderstack/analytics-js-common/types/PluginEngine';
import { defaultHttpClient } from '@rudderstack/analytics-js-common/__mocks__/HttpClient';
import type { RetryQueue } from '../../src/utilities/retryQueue/RetryQueue';
import type { QueueItem, QueueItemData } from '../../src/types/plugins';
import { resetState, state } from '../../__mocks__/state';
import { XhrQueue } from '../../src/xhrQueue';
import { Schedule } from '../../src/utilities/retryQueue/Schedule';
import { defaultHttpClient } from '../../__mocks__/HttpClient';

jest.mock('@rudderstack/analytics-js-common/utilities/timestamp', () => ({
...jest.requireActual('@rudderstack/analytics-js-common/utilities/timestamp'),
Expand Down
2 changes: 0 additions & 2 deletions packages/analytics-js-plugins/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ const isNpmPackageBuild = moduleType === 'npm';
const isCDNPackageBuild = moduleType === 'cdn';
const pluginsMap = {
'./BeaconQueue': './src/beaconQueue/index.ts',
'./Bugsnag': './src/bugsnag/index.ts',
'./CustomConsentManager': './src/customConsentManager/index.ts',
'./DeviceModeDestinations': './src/deviceModeDestinations/index.ts',
'./DeviceModeTransformation': './src/deviceModeTransformation/index.ts',
'./ErrorReporting': './src/errorReporting/index.ts',
'./ExternalAnonymousId': './src/externalAnonymousId/index.ts',
'./GoogleLinker': './src/googleLinker/index.ts',
'./IubendaConsentManager': './src/iubendaConsentManager/index.ts',
Expand Down
53 changes: 0 additions & 53 deletions packages/analytics-js-plugins/src/bugsnag/constants.ts

This file was deleted.

63 changes: 0 additions & 63 deletions packages/analytics-js-plugins/src/bugsnag/index.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/analytics-js-plugins/src/bugsnag/logMessages.ts

This file was deleted.

Loading
Loading