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

Conversation

MoumitaM
Copy link
Contributor

@MoumitaM MoumitaM commented Jan 30, 2024

PR Description

Error reporting Plugin:

  • Load this only if error reporting is enabled in the source config response
  • Implement the extension points:
    • Initialize
    • notify
      • build the error payload from the error
      • Filter errors that are not generated from the SDK
      • Enhance error with metadata and breadcrumb
      • send the error data to the metrics service
    • breadcrumb
      • create a new breadcrumb and store it in memory

Linear task (optional)

https://linear.app/rudderstack/issue/SDK-1096/error-reporting-plugin

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • New Features

    • Introduced breadcrumb functionality for enhanced error reporting.
    • Added structured error categorization through an ErrorType enumeration.
  • Bug Fixes

    • Enhanced error reporting with new parameters and logic for better error handling.
  • Refactor

    • Updated error handling logic and reporting functionality, including new utility functions and error types.
    • Streamlined error reporting process by removing legacy code related to error buffering.
  • Chores

    • Removed deprecated constants and mappings related to error reporting.
    • Updated configuration endpoint management.

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: Patch coverage is 87.03704% with 21 lines in your changes missing coverage. Please review.

Project coverage is 56.61%. Comparing base (5d750cf) to head (a1bdc87).

Files Patch % Lines
...s/analytics-js-plugins/src/errorReporting/utils.ts 91.80% 0 Missing and 5 partials ⚠️
...ages/analytics-js-common/src/types/ErrorHandler.ts 0.00% 4 Missing ⚠️
...s/analytics-js-plugins/src/errorReporting/index.ts 78.94% 4 Missing ⚠️
...ytics-js/src/services/ErrorHandler/ErrorHandler.ts 89.28% 3 Missing ⚠️
...kages/analytics-js-common/src/constants/metrics.ts 0.00% 2 Missing ⚠️
...ytics-js/src/services/ErrorHandler/processError.ts 90.00% 2 Missing ⚠️
packages/analytics-js/src/constants/logMessages.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1601      +/-   ##
===========================================
+ Coverage    56.44%   56.61%   +0.16%     
===========================================
  Files          467      471       +4     
  Lines        15967    16079     +112     
  Branches      3189     3209      +20     
===========================================
+ Hits          9013     9103      +90     
- Misses        5727     5761      +34     
+ Partials      1227     1215      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jan 30, 2024

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.53 KB 1.53 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins - Legacy - CDN 13.26 KB 15.74 KB (+18.73% ▲) 16 KB
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Modern - CDN 5.7 KB 7.19 KB (+26.13% ▲) 7.5 KB
Common - No bundling 15.83 KB 15.87 KB (+0.28% ▲) 16.5 KB
Service Worker - Legacy - NPM (ESM) 29.41 KB 29.41 KB (0%) 30 KB
Service Worker - Legacy - NPM (CJS) 29.66 KB 29.66 KB (0%) 30 KB
Service Worker - Legacy - NPM (UMD) 29.42 KB 29.42 KB (0%) 30 KB
Service Worker - Modern - NPM (ESM) 24.6 KB 24.6 KB (0%) 25 KB
Service Worker - Modern - NPM (CJS) 24.87 KB 24.87 KB (0%) 25 KB
Service Worker - Modern - NPM (UMD) 24.68 KB 24.68 KB (0%) 25 KB
Core (v1.1) - NPM (ESM) 29.75 KB 29.75 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 29.85 KB 29.85 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 29.82 KB 29.82 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.28 KB 29.28 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (CJS) 29.51 KB 29.51 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (UMD) 29.32 KB 29.32 KB (0%) 30 KB
Core - Legacy - CDN 44.54 KB 47.47 KB (+6.59% ▲) 47.5 KB
Core - Modern - CDN 24.02 KB 24.12 KB (+0.42% ▲) 24.5 KB
Load Snippet 734 B 734 B (0%) 1 KB
Core - Legacy - NPM (ESM) 44.47 KB 47.34 KB (+6.45% ▲) 47.5 KB
Core - Legacy - NPM (CJS) 44.7 KB 47.62 KB (+6.52% ▲) 48 KB
Core - Legacy - NPM (UMD) 44.46 KB 47.41 KB (+6.64% ▲) 47.5 KB
Core - Modern - NPM (ESM) 23.8 KB 23.93 KB (+0.56% ▲) 24.5 KB
Core - Modern - NPM (CJS) 23.99 KB 24.15 KB (+0.66% ▲) 24.5 KB
Core - Modern - NPM (UMD) 23.82 KB 23.88 KB (+0.28% ▲) 24.5 KB
Core (Bundled) - Legacy - NPM (ESM) 44.47 KB 47.34 KB (+6.45% ▲) 47.5 KB
Core (Bundled) - Legacy - NPM (CJS) 44.76 KB 47.65 KB (+6.47% ▲) 48 KB
Core (Bundled) - Legacy - NPM (UMD) 44.46 KB 47.41 KB (+6.64% ▲) 47.5 KB
Core (Bundled) - Modern - NPM (ESM) 35.97 KB 38.7 KB (+7.59% ▲) 39 KB
Core (Bundled) - Modern - NPM (CJS) 36.22 KB 38.95 KB (+7.54% ▲) 39 KB
Core (Bundled) - Modern - NPM (UMD) 35.95 KB 38.68 KB (+7.6% ▲) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 43.79 KB 46.88 KB (+7.04% ▲) 47 KB
Core (Content Script) - Legacy - NPM (CJS) 43.96 KB 47.07 KB (+7.07% ▲) 47.5 KB
Core (Content Script) - Legacy - NPM (UMD) 43.78 KB 46.82 KB (+6.94% ▲) 47 KB
Core (Content Script) - Modern - NPM (ESM) 35.3 KB 38.11 KB (+7.96% ▲) 38.5 KB
Core (Content Script) - Modern - NPM (CJS) 35.49 KB 38.4 KB (+8.19% ▲) 38.5 KB
Core (Content Script) - Modern - NPM (UMD) 35.25 KB 38.13 KB (+8.2% ▲) 38.5 KB
All Integrations - Legacy - CDN 92.46 KB 92.46 KB (0%) 93 KB
All Integrations - Modern - CDN 87.9 KB 87.9 KB (0%) 88 KB

@MoumitaM MoumitaM requested a review from saikumarrs February 7, 2024 15:43
packages/analytics-js-common/src/constants/metrics.ts Outdated Show resolved Hide resolved
packages/analytics-js-common/src/types/ApplicationState.ts Outdated Show resolved Hide resolved
packages/analytics-js-plugins/src/errorReporting/index.ts Outdated Show resolved Hide resolved
packages/analytics-js-plugins/src/errorReporting/utils.ts Outdated Show resolved Hide resolved
packages/analytics-js-plugins/src/errorReporting/utils.ts Outdated Show resolved Hide resolved
packages/analytics-js-plugins/src/errorReporting/utils.ts Outdated Show resolved Hide resolved
packages/analytics-js/.size-limit.js Outdated Show resolved Hide resolved
@MoumitaM
Copy link
Contributor Author

MoumitaM commented Feb 9, 2024

@saikumarrs all your comments are addressed

saikumarrs
saikumarrs previously approved these changes Feb 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 55a7a9f and 786928c.

Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • package.json is excluded by !**/*.json
  • packages/analytics-js-plugins/package.json is excluded by !**/*.json
Files selected for processing (5)
  • packages/analytics-js-plugins/.size-limit.mjs (1 hunks)
  • packages/analytics-js-plugins/rollup.config.mjs (4 hunks)
  • packages/analytics-js/.size-limit.mjs (1 hunks)
  • packages/analytics-js/rollup.config.mjs (9 hunks)
  • sonar-project.properties (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/analytics-js-plugins/.size-limit.mjs
  • packages/analytics-js-plugins/rollup.config.mjs
  • packages/analytics-js/.size-limit.mjs
  • packages/analytics-js/rollup.config.mjs
  • sonar-project.properties

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 786928c and 0651b04.

Files selected for processing (3)
  • packages/analytics-js-plugins/.size-limit.mjs (2 hunks)
  • packages/analytics-js-plugins/rollup.config.mjs (5 hunks)
  • packages/analytics-js/.size-limit.mjs (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/analytics-js-plugins/.size-limit.mjs
  • packages/analytics-js-plugins/rollup.config.mjs
  • packages/analytics-js/.size-limit.mjs

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0651b04 and 017be47.

Files selected for processing (3)
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts (5 hunks)
  • packages/analytics-js-plugins/src/errorReporting/index.ts (3 hunks)
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (8 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts
  • packages/analytics-js-plugins/src/errorReporting/index.ts
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 18, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 017be47 and 5ee27fc.

Files selected for processing (2)
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts (5 hunks)
  • packages/analytics-js-plugins/src/errorReporting/index.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts
  • packages/analytics-js-plugins/src/errorReporting/index.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 18, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ee27fc and e2e94f3.

Files selected for processing (8)
  • packages/analytics-js-common/src/types/ApplicationState.ts (2 hunks)
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts (5 hunks)
  • packages/analytics-js-plugins/src/errorReporting/index.ts (3 hunks)
  • packages/analytics-js/tests/services/ErrorHandler/ErrorHandler.test.ts (10 hunks)
  • packages/analytics-js/src/components/configManager/ConfigManager.ts (3 hunks)
  • packages/analytics-js/src/components/configManager/constants.ts (3 hunks)
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (8 hunks)
  • packages/analytics-js/src/state/slices/metrics.ts (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • packages/analytics-js-common/src/types/ApplicationState.ts
  • packages/analytics-js-plugins/tests/errorReporting/index.test.ts
  • packages/analytics-js-plugins/src/errorReporting/index.ts
  • packages/analytics-js/tests/services/ErrorHandler/ErrorHandler.test.ts
  • packages/analytics-js/src/components/configManager/constants.ts
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts
Additional comments not posted (4)
packages/analytics-js/src/state/slices/metrics.ts (1)

10-10: LGTM! Ensure the correct usage of metricsServiceUrl.

The addition of metricsServiceUrl looks good.

Verify its usage across the codebase to ensure it is utilized correctly.

Verification successful

Verified: Proper usage of metricsServiceUrl

The addition and usage of metricsServiceUrl across the codebase have been verified and are consistent with its intended purpose.

  • metrics.ts: Initialized with undefined.
  • ConfigManager.ts: Assigned a URL.
  • ApplicationState.ts: Type definition.
  • index.ts and index.test.ts: Used in error reporting and testing.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `metricsServiceUrl` in the codebase.

# Test: Search for the usage of `metricsServiceUrl`. Expect: Proper usage across the codebase.
rg --type python -A 5 $'metricsServiceUrl'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the usage of `metricsServiceUrl` in the codebase.

# Test: Search for the usage of `metricsServiceUrl`. Expect: Proper usage across the codebase.
rg --type ts -A 5 'metricsServiceUrl'

Length of output: 2599

packages/analytics-js/src/components/configManager/ConfigManager.ts (3)

33-33: LGTM!

The import of METRICS_SERVICE_ENDPOINT looks good.


112-112: LGTM! Ensure the correct definitions of activeDataplaneUrl and METRICS_SERVICE_ENDPOINT.

The assignment of metricsServiceUrl looks good.

Verify the definitions of activeDataplaneUrl and METRICS_SERVICE_ENDPOINT to ensure they are correctly defined and used.

Verification successful

LGTM! Ensure the correct definitions of activeDataplaneUrl and METRICS_SERVICE_ENDPOINT.

The assignment of metricsServiceUrl looks good. The definitions and usage of activeDataplaneUrl and METRICS_SERVICE_ENDPOINT are correct.

  • activeDataplaneUrl is defined as a Signal<string | undefined> and is used consistently across the codebase.
  • METRICS_SERVICE_ENDPOINT is defined as 'rsaMetrics' in constants.ts and is imported correctly in ConfigManager.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT`.

# Test: Search for the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT`. Expect: Proper definitions and usage.
rg --type python -A 5 $'activeDataplaneUrl'
rg --type python -A 5 $'METRICS_SERVICE_ENDPOINT'

Length of output: 153


Script:

#!/bin/bash
# Description: Verify the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT`.

# Test: Search for the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT` in TypeScript files. Expect: Proper definitions and usage.
rg --type typescript -A 5 'activeDataplaneUrl'
rg --type typescript -A 5 'METRICS_SERVICE_ENDPOINT'

Length of output: 169


Script:

#!/bin/bash
# Description: Verify the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT`.

# Test: Search for the definitions of `activeDataplaneUrl` and `METRICS_SERVICE_ENDPOINT` in TypeScript files. Expect: Proper definitions and usage.
rg --type ts -A 5 'activeDataplaneUrl'
rg --type ts -A 5 'METRICS_SERVICE_ENDPOINT'

Length of output: 8860


165-165: LGTM! Ensure the updateReportingState function no longer requires the logger parameter.

The removal of this.logger from the updateReportingState function call looks good.

Verify the updateReportingState function to ensure it no longer requires the logger parameter.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 18, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e2e94f3 and a1bdc87.

Files selected for processing (1)
  • packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (8 hunks)
Additional comments not posted (17)
packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts (17)

4-9: Imports Review

The new imports for ErrorType, ErrorState, IHttpClient, and error processing functions are appropriate and necessary for the changes made in the file.

Also applies to: 15-15, 24-28


36-36: Initialization of httpClient

The httpClient property is correctly initialized in the constructor.


55-55: Call to notifyError with errorState

The call to notifyError with the new errorState parameter is correct and aligns with the new error handling logic.


64-64: Call to onError with errorType

The calls to onError with the new errorType parameter are correct and align with the new error type system.

Also applies to: 70-70


78-79: Initialization of httpClient in init

The httpClient property is correctly initialized in the init method.


94-94: Ensure proper error handling

The init method correctly handles the initialization of the error reporting plugin and catches any errors that occur during the process.


115-115: Addition of errorType parameter

The addition of the errorType parameter to the onError method is correct and aligns with the new error type system.


119-119: Use of processError

The use of processError to handle handled exceptions is correct and ensures that errors are properly processed.

Also applies to: 120-121


127-136: Normalization of error message

The normalization of the error message using removeDoubleSpaces and the creation of a new Error object with the normalized message are correct.


138-138: Use of getNormalizedErrorForUnhandledError

The use of getNormalizedErrorForUnhandledError to handle unhandled exceptions is correct and ensures that errors are properly normalized.


141-141: Check for error reporting enabled

The check for whether error reporting is enabled is correct and ensures that errors are only reported when error reporting is enabled.


151-157: Buffering of errors

The buffering of errors when the error reporting plugin is not loaded is correct and ensures that errors are not lost.


158-159: Call to notifyError

The call to notifyError when the error reporting plugin is loaded is correct and ensures that errors are reported immediately.


162-162: Error handling in onError

The error handling in the onError method ensures that any errors that occur during error reporting are logged.


165-165: Logging of handled exceptions

The logging of handled exceptions is correct and ensures that handled exceptions are logged appropriately.


189-193: Call to invokeSingle with new parameters

The call to invokeSingle with the new parameters in the leaveBreadcrumb method is correct and aligns with the new error reporting logic.


206-217: Implementation of notifyError

The notifyError method is correctly implemented and ensures that errors are notified to the error reporting plugin.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
87.5% Coverage on New Code (required ≥ 90%)

See analysis details on SonarCloud

@MoumitaM MoumitaM merged commit 1f2629e into develop Jul 19, 2024
9 of 10 checks passed
@MoumitaM MoumitaM deleted the feature/sdk-1096-error-reporting-plugin branch July 19, 2024 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants