rollbar 2.26.3 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/.cursor/rules/guidelines.mdc +154 -0
  2. package/.github/workflows/ci.yml +32 -12
  3. package/.lgtm.yml +7 -7
  4. package/.prettierignore +18 -0
  5. package/.vscode/settings.json +39 -0
  6. package/CHANGELOG.md +121 -35
  7. package/CLAUDE.md +201 -0
  8. package/Gruntfile.js +101 -48
  9. package/Makefile +3 -3
  10. package/README.md +2 -4
  11. package/SECURITY.md +5 -0
  12. package/babel.config.json +9 -0
  13. package/bower.json +1 -3
  14. package/codex.md +148 -0
  15. package/defaults.js +17 -5
  16. package/dist/plugins/jquery.min.js +1 -1
  17. package/dist/rollbar.js +18748 -5375
  18. package/dist/rollbar.js.map +1 -1
  19. package/dist/rollbar.min.js +2 -1
  20. package/dist/rollbar.min.js.LICENSE.txt +1 -0
  21. package/dist/rollbar.min.js.map +1 -1
  22. package/dist/rollbar.named-amd.js +19368 -6000
  23. package/dist/rollbar.named-amd.js.map +1 -1
  24. package/dist/rollbar.named-amd.min.js +3 -1
  25. package/dist/rollbar.named-amd.min.js.LICENSE.txt +1 -0
  26. package/dist/rollbar.named-amd.min.js.map +1 -1
  27. package/dist/rollbar.noconflict.umd.js +18749 -5380
  28. package/dist/rollbar.noconflict.umd.js.map +1 -1
  29. package/dist/rollbar.noconflict.umd.min.js +3 -1
  30. package/dist/rollbar.noconflict.umd.min.js.LICENSE.txt +1 -0
  31. package/dist/rollbar.noconflict.umd.min.js.map +1 -1
  32. package/dist/rollbar.snippet.js +1 -1
  33. package/dist/rollbar.umd.js +19367 -6000
  34. package/dist/rollbar.umd.js.map +1 -1
  35. package/dist/rollbar.umd.min.js +3 -1
  36. package/dist/rollbar.umd.min.js.LICENSE.txt +1 -0
  37. package/dist/rollbar.umd.min.js.map +1 -1
  38. package/docs/extension-exceptions.md +35 -30
  39. package/docs/migration_v0_to_v1.md +41 -38
  40. package/eslint.config.mjs +33 -0
  41. package/get_versions.js +33 -0
  42. package/index.d.ts +270 -231
  43. package/karma.conf.js +18 -27
  44. package/package.json +21 -21
  45. package/prettier.config.js +7 -0
  46. package/src/api.js +78 -14
  47. package/src/apiUtility.js +14 -11
  48. package/src/browser/core.js +138 -72
  49. package/src/browser/defaults/scrubFields.js +3 -3
  50. package/src/browser/detection.js +7 -8
  51. package/src/browser/domUtility.js +18 -8
  52. package/src/browser/globalSetup.js +12 -6
  53. package/src/browser/logger.js +1 -1
  54. package/src/browser/plugins/jquery.js +35 -35
  55. package/src/browser/predicates.js +1 -1
  56. package/src/browser/replay/defaults.js +71 -0
  57. package/src/browser/replay/recorder.js +193 -0
  58. package/src/browser/replay/replayMap.js +195 -0
  59. package/src/browser/rollbar.js +12 -8
  60. package/src/browser/rollbarWrapper.js +8 -5
  61. package/src/browser/shim.js +43 -19
  62. package/src/browser/snippet_callback.js +6 -4
  63. package/src/browser/telemetry.js +573 -361
  64. package/src/browser/transforms.js +46 -27
  65. package/src/browser/transport/fetch.js +26 -14
  66. package/src/browser/transport/xhr.js +41 -14
  67. package/src/browser/transport.js +93 -33
  68. package/src/browser/url.js +16 -8
  69. package/src/browser/wrapGlobals.js +27 -8
  70. package/src/defaults.js +3 -3
  71. package/src/errorParser.js +14 -11
  72. package/src/merge.js +32 -23
  73. package/src/notifier.js +16 -13
  74. package/src/predicates.js +43 -23
  75. package/src/queue.js +133 -40
  76. package/src/rateLimiter.js +59 -18
  77. package/src/react-native/logger.js +1 -1
  78. package/src/react-native/rollbar.js +59 -55
  79. package/src/react-native/transforms.js +13 -9
  80. package/src/react-native/transport.js +44 -34
  81. package/src/rollbar.js +72 -21
  82. package/src/scrub.js +0 -1
  83. package/src/server/locals.js +69 -39
  84. package/src/server/logger.js +4 -4
  85. package/src/server/parser.js +72 -47
  86. package/src/server/rollbar.js +135 -56
  87. package/src/server/sourceMap/stackTrace.js +33 -18
  88. package/src/server/telemetry/urlHelpers.js +9 -11
  89. package/src/server/telemetry.js +68 -45
  90. package/src/server/transforms.js +37 -21
  91. package/src/server/transport.js +62 -32
  92. package/src/telemetry.js +162 -33
  93. package/src/tracing/context.js +24 -0
  94. package/src/tracing/contextManager.js +37 -0
  95. package/src/tracing/defaults.js +7 -0
  96. package/src/tracing/exporter.js +188 -0
  97. package/src/tracing/hrtime.js +98 -0
  98. package/src/tracing/id.js +24 -0
  99. package/src/tracing/session.js +55 -0
  100. package/src/tracing/span.js +92 -0
  101. package/src/tracing/spanProcessor.js +15 -0
  102. package/src/tracing/tracer.js +46 -0
  103. package/src/tracing/tracing.js +89 -0
  104. package/src/transforms.js +33 -21
  105. package/src/truncation.js +8 -5
  106. package/src/utility/headers.js +43 -43
  107. package/src/utility/replace.js +9 -0
  108. package/src/utility/traverse.js +1 -1
  109. package/src/utility.js +123 -52
  110. package/test/api.test.js +88 -41
  111. package/test/apiUtility.test.js +48 -50
  112. package/test/browser.core.test.js +142 -141
  113. package/test/browser.domUtility.test.js +53 -36
  114. package/test/browser.predicates.test.js +14 -14
  115. package/test/browser.replay.recorder.test.js +416 -0
  116. package/test/browser.rollbar.test.js +655 -515
  117. package/test/browser.telemetry.test.js +46 -39
  118. package/test/browser.transforms.test.js +164 -139
  119. package/test/browser.transport.test.js +59 -50
  120. package/test/browser.url.test.js +13 -12
  121. package/test/fixtures/locals.fixtures.js +245 -126
  122. package/test/fixtures/replay/index.js +20 -0
  123. package/test/fixtures/replay/payloads.fixtures.js +229 -0
  124. package/test/fixtures/replay/rrwebEvents.fixtures.js +251 -0
  125. package/test/fixtures/replay/rrwebSyntheticEvents.fixtures.js +328 -0
  126. package/test/notifier.test.js +91 -79
  127. package/test/predicates.test.js +261 -215
  128. package/test/queue.test.js +231 -215
  129. package/test/rateLimiter.test.js +51 -43
  130. package/test/react-native.rollbar.test.js +150 -116
  131. package/test/react-native.transforms.test.js +23 -25
  132. package/test/react-native.transport.test.js +26 -14
  133. package/test/replay/index.js +2 -0
  134. package/test/replay/integration/api.spans.test.js +136 -0
  135. package/test/replay/integration/e2e.test.js +228 -0
  136. package/test/replay/integration/index.js +9 -0
  137. package/test/replay/integration/queue.replayMap.test.js +332 -0
  138. package/test/replay/integration/replayMap.test.js +163 -0
  139. package/test/replay/integration/sessionRecording.test.js +390 -0
  140. package/test/replay/unit/api.postSpans.test.js +150 -0
  141. package/test/replay/unit/index.js +7 -0
  142. package/test/replay/unit/queue.replayMap.test.js +225 -0
  143. package/test/replay/unit/replayMap.test.js +348 -0
  144. package/test/replay/util/index.js +5 -0
  145. package/test/replay/util/mockRecordFn.js +80 -0
  146. package/test/server.lambda.mocha.test.mjs +172 -0
  147. package/test/server.locals.constructor.mocha.test.mjs +80 -0
  148. package/test/server.locals.error-handling.mocha.test.mjs +387 -0
  149. package/test/server.locals.merge.mocha.test.mjs +267 -0
  150. package/test/server.locals.test-utils.mjs +114 -0
  151. package/test/server.parser.mocha.test.mjs +87 -0
  152. package/test/server.predicates.mocha.test.mjs +63 -0
  153. package/test/server.rollbar.constructor.mocha.test.mjs +199 -0
  154. package/test/server.rollbar.handlers.mocha.test.mjs +253 -0
  155. package/test/server.rollbar.logging.mocha.test.mjs +326 -0
  156. package/test/server.rollbar.misc.mocha.test.mjs +44 -0
  157. package/test/server.rollbar.test-utils.mjs +57 -0
  158. package/test/server.telemetry.mocha.test.mjs +377 -0
  159. package/test/server.transforms.data.mocha.test.mjs +163 -0
  160. package/test/server.transforms.error.mocha.test.mjs +199 -0
  161. package/test/server.transforms.request.mocha.test.mjs +208 -0
  162. package/test/server.transforms.scrub.mocha.test.mjs +140 -0
  163. package/test/server.transforms.sourcemaps.mocha.test.mjs +122 -0
  164. package/test/server.transforms.test-utils.mjs +62 -0
  165. package/test/server.transport.mocha.test.mjs +269 -0
  166. package/test/telemetry.test.js +178 -38
  167. package/test/tracing/contextManager.test.js +28 -0
  168. package/test/tracing/exporter.toPayload.test.js +400 -0
  169. package/test/tracing/id.test.js +24 -0
  170. package/test/tracing/span.test.js +183 -0
  171. package/test/tracing/spanProcessor.test.js +73 -0
  172. package/test/tracing/tracing.test.js +105 -0
  173. package/test/transforms.test.js +70 -68
  174. package/test/truncation.test.js +57 -55
  175. package/test/utility.test.js +310 -228
  176. package/webpack.config.js +36 -70
  177. package/.eslintignore +0 -7
  178. package/.gitmodules +0 -3
  179. package/test/server.lambda.test.js +0 -177
  180. package/test/server.locals.test.js +0 -841
  181. package/test/server.parser.test.js +0 -72
  182. package/test/server.predicates.test.js +0 -89
  183. package/test/server.rollbar.test.js +0 -676
  184. package/test/server.telemetry.test.js +0 -318
  185. package/test/server.transforms.test.js +0 -1099
  186. package/test/server.transport.test.js +0 -201
@@ -0,0 +1,154 @@
1
+ ---
2
+ description: Rollbar JS SDK Guidelines
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+
7
+ ## About Rollbar.js
8
+
9
+ Rollbar.js is the official JavaScript SDK for the Rollbar error monitoring service. This library is not standalone - it works in tandem with the Rollbar platform to help developers detect, diagnose, and fix errors in real-time. The SDK sends error data to Rollbar's cloud service where errors are processed, grouped, and notifications are triggered.
10
+
11
+ The library works across platforms, supporting both browser and server-side JavaScript including frameworks like React, Angular, Express, and Next.js. Key features include:
12
+
13
+ - Cross-platform error tracking for client and server-side code
14
+ - Telemetry to provide context around errors (breadcrumbs of events)
15
+ - Automatic error grouping to reduce noise
16
+ - Real-time notifications for critical issues
17
+ - Detailed stack traces with source maps support
18
+ - Distributed tracing and session management
19
+ - Session replay capabilities for reproducing user actions
20
+
21
+ ## Project Structure
22
+
23
+ ```
24
+ src/
25
+ ├── browser/ # Browser-specific implementation
26
+ ├── server/ # Node.js-specific implementation
27
+ ├── react-native/ # React Native implementation
28
+ ├── tracing/ # Distributed tracing support
29
+ └── utility/ # Shared utility functions
30
+ ```
31
+
32
+ ## Build & Test Commands
33
+
34
+ - Build: `npm run build` (runs Grunt)
35
+ - Lint: `npm run lint` (ESLint)
36
+ - Test all: `npm run test` (runs both server and browser tests)
37
+ - Test browser only: `npm run test-browser`
38
+ - Test server only: `npm run test-server`
39
+ - Test specific browser test: `grunt test-browser:specificTestName`
40
+ - Example: `grunt test-browser:transforms`
41
+ - Single test: `./node_modules/.bin/karma start --single-run --files={path/to/test}`
42
+
43
+ ## Modern Development Environment
44
+
45
+ As of version 3.0.0, the SDK has been updated to use modern JavaScript features with appropriate transpilation:
46
+
47
+ - **ES Modules**: The codebase supports ES modules (`import/export`) syntax
48
+ - **Target Compatibility**:
49
+ - Source code uses ECMAScript 2021 features
50
+ - Builds target ES5 for broad browser compatibility
51
+ - Lower versions can use the ES5/CommonJS compatible bundles
52
+ - **Build System**:
53
+ - Webpack 5 with Babel for transpilation
54
+ - ESLint for code quality
55
+ - Configurable output formats (UMD, AMD, vanilla)
56
+ - **Minimum Node.js**: Version 18+ for absolute imports
57
+ - **Toolchain Configuration**:
58
+ - `babel.config.json`: Controls transpilation options
59
+ - `eslint.config.mjs`: Modern ESLint flat config format
60
+ - `webpack.config.js`: Manages bundling and output formats
61
+
62
+ ## Code Style Guidelines
63
+
64
+ - Use single quotes for strings
65
+ - Use camelCase for variables (underscore prefix for private)
66
+ - Indentation: 2 spaces
67
+ - Include trailing commas in multiline objects/arrays
68
+ - Max function complexity: 35
69
+ - Unused parameters prefixed with underscore: `function(a, _unused) {}`
70
+ - No whitespace in empty lines
71
+ - Files should end with exactly one newline
72
+ - Control statements (if, for, while, etc.) MUST use braces and newlines, even for single statements
73
+ - Opening braces should be on the same line as the control statement
74
+ - ESLint is used for enforcing code style
75
+ - Prettier for code formatting
76
+
77
+ ## SDK Design Principles
78
+
79
+ - **User Problems Are SDK Improvement Opportunities**: When users encounter integration issues, treat these as SDK design improvements rather than user implementation mistakes.
80
+ - Focus on enhancing the SDK to be more robust, intuitive and resilient
81
+ - Implement automatic environment detection and appropriate behavior selection
82
+ - Design APIs that work correctly across all supported contexts without requiring special user handling
83
+ - Errors should be informative and suggest correct usage patterns
84
+ - The burden of complexity should rest with the SDK, not its users
85
+
86
+ ## Error Handling
87
+
88
+ - Prefer try/catch blocks around risky operations
89
+ - Log errors through Rollbar's own logger system
90
+ - Scrub sensitive fields in error payloads (see package.json defaults)
91
+ - The codebase uses a comprehensive error tracking approach with appropriate levels:
92
+ - Debug level for development info
93
+ - Warning level for non-critical issues
94
+ - Error level for uncaught exceptions
95
+
96
+ ## TypeScript Support
97
+
98
+ - Type definitions in index.d.ts
99
+ - Add JSDoc types to enable intellisense when needed
100
+
101
+ ## Common Patterns
102
+
103
+ When working with this codebase, be aware of these patterns:
104
+
105
+ - Error transformation and normalization before sending
106
+ - Telemetry collection for context
107
+ - Queue-based sending with retry logic
108
+ - Environment and context detection
109
+ - Scrubbing of sensitive data
110
+
111
+ ## Testing Philosophy
112
+
113
+ - **Analyze Test Failures Objectively**: When tests fail, evaluate both possibilities objectively:
114
+
115
+ - The test could be correctly identifying an actual code issue
116
+ - The test itself might contain errors or invalid expectations
117
+
118
+ - **Diagnostic Process**:
119
+
120
+ 1. Examine what the test is expecting vs. what the code actually does
121
+ 2. Consider the intended behavior and design of the system
122
+ 3. If the test is correct and identifying a legitimate bug, fix the code
123
+ 4. If the test contains misconceptions or errors, fix the test
124
+
125
+ - **Default to Code Quality**: When in doubt and both seem potentially valid, prioritize improving code quality over modifying tests to pass
126
+
127
+ ## Tracing & Session Replay
128
+
129
+ The `src/tracing/` directory contains an OpenTelemetry-inspired tracing implementation that powers both distributed tracing and session recording features:
130
+
131
+ ### Components
132
+
133
+ - **Context & ContextManager**: Manages propagation of tracing context through the application
134
+ - **Span**: Represents a unit of work or operation with timing information and attributes
135
+ - **Tracer**: Creates and manages spans for tracking operations
136
+ - **SpanProcessor & SpanExporter**: Processes and exports spans to their destination
137
+ - **Session**: Manages browser session data persistence and creation
138
+
139
+ ### Usage Patterns
140
+
141
+ - **Tracing initialization**: Initialize via the main Tracing class with appropriate configuration
142
+ - **Context propagation**: Use context to pass trace information between components
143
+ - **Span creation**: Create spans to measure operations with `startSpan()`
144
+ - **Attributes and events**: Add metadata to spans with `setAttribute()` and `addEvent()`
145
+ - **Session management**: Automatically manages user sessions via browser sessionStorage
146
+
147
+ ### Integration with Session Replay
148
+
149
+ The Session Replay feature utilizes this tracing infrastructure to:
150
+
151
+ - Track and record user sessions with unique identifiers
152
+ - Associate spans with specific user sessions for complete context
153
+ - Capture timing information for accurate playback
154
+ - Store interaction events as span attributes and events
@@ -2,30 +2,50 @@ name: Rollbar.js CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
6
- tags: [ v* ]
5
+ branches: [master]
6
+ tags: [v*]
7
7
  pull_request:
8
- branches: [ master ]
8
+ branches: [master]
9
9
 
10
10
  jobs:
11
11
  build:
12
- runs-on: ubuntu-20.04
12
+ runs-on: ubuntu-22.04
13
+
13
14
  strategy:
14
15
  matrix:
15
- node-version: [10, 12, 14, 16]
16
+ include:
17
+ - node: 18
18
+ npm: ^9
19
+ - node: 20
20
+ npm: ^10
21
+ - node: 22
22
+ npm: ^10
23
+ - node: latest
24
+ npm: latest
16
25
 
17
26
  steps:
18
- - uses: actions/checkout@v2
19
- with:
20
- submodules: recursive
27
+ - name: Checkout
28
+ uses: actions/checkout@v4
21
29
 
22
- - name: Install node.js
23
- uses: actions/setup-node@v2-beta
30
+ - name: Set up node ${{ matrix.node }}
31
+ uses: actions/setup-node@v4
24
32
  with:
25
- node-version: ${{ matrix.node-version }}
33
+ node-version: ${{ matrix.node }}
34
+
35
+ - name: Update npm
36
+ run: npm install -g npm@${{ matrix.npm }}
26
37
 
27
38
  - name: npm install
28
39
  run: npm install
29
40
 
41
+ - name: Lint
42
+ uses: wearerequired/lint-action@v2
43
+ with:
44
+ github_token: ${{ secrets.GITHUB_TOKEN }}
45
+ prettier: true
46
+ eslint: true
47
+ eslint_args: '--max-warnings 0'
48
+ eslint_extensions: js
49
+
30
50
  - name: Run tests
31
- run: npm run test_ci
51
+ run: npm run test-ci
package/.lgtm.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  path_classifiers:
2
- generated:
3
- - release
4
- - dist
5
- docs:
6
- - examples
7
- test:
8
- - test
2
+ generated:
3
+ - release
4
+ - dist
5
+ docs:
6
+ - examples
7
+ test:
8
+ - test
@@ -0,0 +1,18 @@
1
+ .github
2
+ .next
3
+ .yalc
4
+ build
5
+ bundles
6
+ coverage
7
+ dist
8
+ lib
9
+ node_modules
10
+ out
11
+ public
12
+ release
13
+ vendor
14
+
15
+ # ignore prettifying examples for now due to
16
+ # 1. there being minified snippets all over the place and
17
+ # 2. some tests fail cause they depend on some sources being exactly as they are
18
+ examples
@@ -0,0 +1,39 @@
1
+ {
2
+ "[github-actions-workflow]": {
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
4
+ "editor.formatOnSave": true
5
+ },
6
+ "[javascript]": {
7
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
8
+ "editor.formatOnSave": true
9
+ },
10
+ "[javascriptreact]": {
11
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
12
+ "editor.formatOnSave": true
13
+ },
14
+ "[json5]": {
15
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
16
+ "editor.formatOnSave": true
17
+ },
18
+ "[jsonc]": {
19
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
20
+ "editor.formatOnSave": true
21
+ },
22
+ "[typescript]": {
23
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
24
+ "editor.formatOnSave": true
25
+ },
26
+ "[typescriptreact]": {
27
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
28
+ "editor.formatOnSave": true
29
+ },
30
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
31
+ "editor.formatOnSave": true,
32
+ "editor.formatOnSaveMode": "file",
33
+ "editor.tabSize": 2,
34
+ "editor.codeActionsOnSave": {
35
+ "source.fixAll.eslint": "explicit"
36
+ },
37
+ "files.trimTrailingWhitespace": true,
38
+ "prettier.useEditorConfig": false
39
+ }