rollbar 2.26.4 → 3.0.0-alpha.2

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 (140) hide show
  1. package/.claude/settings.local.json +3 -0
  2. package/.cursor/rules/guidelines.mdc +154 -0
  3. package/.github/workflows/ci.yml +4 -6
  4. package/CLAUDE.local.md +297 -0
  5. package/CLAUDE.md +201 -0
  6. package/CLAUDE.testrunner.md +470 -0
  7. package/Gruntfile.js +59 -16
  8. package/Makefile +3 -3
  9. package/SECURITY.md +5 -0
  10. package/babel.config.json +9 -0
  11. package/codex.md +148 -0
  12. package/dist/plugins/jquery.min.js +1 -1
  13. package/dist/rollbar.js +19332 -6596
  14. package/dist/rollbar.js.map +1 -1
  15. package/dist/rollbar.min.js +2 -1
  16. package/dist/rollbar.min.js.LICENSE.txt +1 -0
  17. package/dist/rollbar.min.js.map +1 -1
  18. package/dist/rollbar.named-amd.js +19332 -6596
  19. package/dist/rollbar.named-amd.js.map +1 -1
  20. package/dist/rollbar.named-amd.min.js +2 -1
  21. package/dist/rollbar.named-amd.min.js.LICENSE.txt +1 -0
  22. package/dist/rollbar.named-amd.min.js.map +1 -1
  23. package/dist/rollbar.noconflict.umd.js +19319 -6581
  24. package/dist/rollbar.noconflict.umd.js.map +1 -1
  25. package/dist/rollbar.noconflict.umd.min.js +2 -1
  26. package/dist/rollbar.noconflict.umd.min.js.LICENSE.txt +1 -0
  27. package/dist/rollbar.noconflict.umd.min.js.map +1 -1
  28. package/dist/rollbar.snippet.js +1 -1
  29. package/dist/rollbar.umd.js +19333 -6597
  30. package/dist/rollbar.umd.js.map +1 -1
  31. package/dist/rollbar.umd.min.js +2 -1
  32. package/dist/rollbar.umd.min.js.LICENSE.txt +1 -0
  33. package/dist/rollbar.umd.min.js.map +1 -1
  34. package/eslint.config.mjs +33 -0
  35. package/karma.conf.js +5 -14
  36. package/package.json +19 -20
  37. package/src/api.js +57 -4
  38. package/src/apiUtility.js +2 -3
  39. package/src/browser/core.js +37 -9
  40. package/src/browser/replay/defaults.js +70 -0
  41. package/src/browser/replay/recorder.js +194 -0
  42. package/src/browser/replay/replayMap.js +195 -0
  43. package/src/browser/rollbar.js +11 -7
  44. package/src/browser/telemetry.js +3 -3
  45. package/src/browser/transport/fetch.js +17 -4
  46. package/src/browser/transport/xhr.js +17 -1
  47. package/src/browser/transport.js +11 -8
  48. package/src/defaults.js +1 -1
  49. package/src/queue.js +65 -4
  50. package/src/react-native/rollbar.js +1 -1
  51. package/src/rollbar.js +52 -10
  52. package/src/server/rollbar.js +3 -2
  53. package/src/telemetry.js +76 -11
  54. package/src/tracing/context.js +24 -0
  55. package/src/tracing/contextManager.js +37 -0
  56. package/src/tracing/defaults.js +7 -0
  57. package/src/tracing/exporter.js +188 -0
  58. package/src/tracing/hrtime.js +98 -0
  59. package/src/tracing/id.js +24 -0
  60. package/src/tracing/session.js +55 -0
  61. package/src/tracing/span.js +92 -0
  62. package/src/tracing/spanProcessor.js +15 -0
  63. package/src/tracing/tracer.js +46 -0
  64. package/src/tracing/tracing.js +89 -0
  65. package/src/utility.js +34 -0
  66. package/test/api.test.js +57 -12
  67. package/test/apiUtility.test.js +5 -6
  68. package/test/browser.core.test.js +1 -10
  69. package/test/browser.domUtility.test.js +1 -1
  70. package/test/browser.predicates.test.js +1 -1
  71. package/test/browser.replay.recorder.test.js +430 -0
  72. package/test/browser.rollbar.test.js +58 -12
  73. package/test/browser.telemetry.test.js +1 -1
  74. package/test/browser.transforms.test.js +20 -13
  75. package/test/browser.transport.test.js +5 -4
  76. package/test/browser.url.test.js +1 -1
  77. package/test/fixtures/replay/index.js +20 -0
  78. package/test/fixtures/replay/payloads.fixtures.js +229 -0
  79. package/test/fixtures/replay/rrwebEvents.fixtures.js +251 -0
  80. package/test/fixtures/replay/rrwebSyntheticEvents.fixtures.js +328 -0
  81. package/test/notifier.test.js +1 -1
  82. package/test/predicates.test.js +1 -1
  83. package/test/queue.test.js +1 -1
  84. package/test/rateLimiter.test.js +1 -1
  85. package/test/react-native.rollbar.test.js +1 -1
  86. package/test/react-native.transforms.test.js +2 -2
  87. package/test/react-native.transport.test.js +3 -3
  88. package/test/replay/index.js +2 -0
  89. package/test/replay/integration/api.spans.test.js +136 -0
  90. package/test/replay/integration/e2e.test.js +228 -0
  91. package/test/replay/integration/index.js +9 -0
  92. package/test/replay/integration/queue.replayMap.test.js +332 -0
  93. package/test/replay/integration/replayMap.test.js +163 -0
  94. package/test/replay/integration/sessionRecording.test.js +390 -0
  95. package/test/replay/unit/api.postSpans.test.js +150 -0
  96. package/test/replay/unit/index.js +7 -0
  97. package/test/replay/unit/queue.replayMap.test.js +225 -0
  98. package/test/replay/unit/replayMap.test.js +348 -0
  99. package/test/replay/util/index.js +5 -0
  100. package/test/replay/util/mockRecordFn.js +80 -0
  101. package/test/server.lambda.mocha.test.mjs +172 -0
  102. package/test/server.locals.constructor.mocha.test.mjs +80 -0
  103. package/test/server.locals.error-handling.mocha.test.mjs +387 -0
  104. package/test/server.locals.merge.mocha.test.mjs +267 -0
  105. package/test/server.locals.test-utils.mjs +114 -0
  106. package/test/server.parser.mocha.test.mjs +87 -0
  107. package/test/server.predicates.mocha.test.mjs +63 -0
  108. package/test/server.rollbar.constructor.mocha.test.mjs +199 -0
  109. package/test/server.rollbar.handlers.mocha.test.mjs +253 -0
  110. package/test/server.rollbar.logging.mocha.test.mjs +326 -0
  111. package/test/server.rollbar.misc.mocha.test.mjs +44 -0
  112. package/test/server.rollbar.test-utils.mjs +57 -0
  113. package/test/server.telemetry.mocha.test.mjs +377 -0
  114. package/test/server.transforms.data.mocha.test.mjs +163 -0
  115. package/test/server.transforms.error.mocha.test.mjs +199 -0
  116. package/test/server.transforms.request.mocha.test.mjs +208 -0
  117. package/test/server.transforms.scrub.mocha.test.mjs +140 -0
  118. package/test/server.transforms.sourcemaps.mocha.test.mjs +122 -0
  119. package/test/server.transforms.test-utils.mjs +62 -0
  120. package/test/server.transport.mocha.test.mjs +269 -0
  121. package/test/telemetry.test.js +132 -1
  122. package/test/tracing/contextManager.test.js +28 -0
  123. package/test/tracing/exporter.toPayload.test.js +400 -0
  124. package/test/tracing/id.test.js +24 -0
  125. package/test/tracing/span.test.js +183 -0
  126. package/test/tracing/spanProcessor.test.js +73 -0
  127. package/test/tracing/tracing.test.js +105 -0
  128. package/test/transforms.test.js +2 -2
  129. package/test/truncation.test.js +2 -2
  130. package/test/utility.test.js +44 -6
  131. package/webpack.config.js +6 -44
  132. package/.eslintignore +0 -7
  133. package/test/server.lambda.test.js +0 -194
  134. package/test/server.locals.test.js +0 -1068
  135. package/test/server.parser.test.js +0 -78
  136. package/test/server.predicates.test.js +0 -91
  137. package/test/server.rollbar.test.js +0 -728
  138. package/test/server.telemetry.test.js +0 -443
  139. package/test/server.transforms.test.js +0 -1193
  140. package/test/server.transport.test.js +0 -269
@@ -0,0 +1,3 @@
1
+ {
2
+ "enableAllProjectMcpServers": false
3
+ }
@@ -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
@@ -9,19 +9,17 @@ on:
9
9
 
10
10
  jobs:
11
11
  build:
12
- runs-on: ubuntu-20.04
12
+ runs-on: ubuntu-22.04
13
13
 
14
14
  strategy:
15
15
  matrix:
16
16
  include:
17
- - node: 14
18
- npm: ^8
19
- - node: 16
20
- npm: ^8
21
17
  - node: 18
22
18
  npm: ^9
23
19
  - node: 20
24
20
  npm: ^10
21
+ - node: 22
22
+ npm: ^10
25
23
  - node: latest
26
24
  npm: latest
27
25
 
@@ -50,4 +48,4 @@ jobs:
50
48
  eslint_extensions: js
51
49
 
52
50
  - name: Run tests
53
- run: npm run test_ci
51
+ run: npm run test-ci
@@ -0,0 +1,297 @@
1
+ # CLAUDE.local.md - Modernization Project
2
+
3
+ ## Problem Statement
4
+
5
+ 1. **Testing Infrastructure**: Karma is deprecated and unmaintained, and Vows.js (last commit 5 years ago) is abandoned with incompatible modern dependencies, creating multiple obsolete toolchain dependencies.
6
+
7
+ 2. **Limited TypeScript Support**: The SDK provides a limited amount of .d.ts files but lacks compilation pipeline and automated type checking in CI, leading to type definition errors discovered only through user reports.
8
+
9
+ 3. **Inconsistent Code Quality**: No automated formatting enforcement and limited linting integration in CI allows inconsistent code style and quality issues to persist across the codebase.
10
+
11
+ 4. **Legacy Tooling**: Grunt is effectively obsolete with minimal maintenance (last release 2 years ago, 703K weekly downloads vs 29M+ for modern alternatives), representing outdated task-runner architecture superseded by direct bundler usage.
12
+
13
+ 5. **Perception**: Enterprise engineers who evaluate our SDK examine our GitHub repository and development practices. Our outdated tooling stack creates an unfavorable impression that can influence their technology adoption decisions.
14
+
15
+ ### Why Consider Modernization Beyond TypeScript Requirements
16
+
17
+ While not required for TypeScript, selective tooling improvements offer compelling technical benefits:
18
+
19
+ 1. **Configuration Complexity**: Current Grunt setup requires 273 lines just to orchestrate tools
20
+ 2. **Maintenance Burden**: Grunt plugins often lag behind their underlying tools
21
+ 3. **Developer Experience**: Modern tools provide better error messages, faster rebuilds, improved debugging
22
+ 4. **Ecosystem Alignment**: Most TypeScript tutorials/examples assume modern tooling (npm scripts, direct tool usage)
23
+ 5. **Build Performance**: Modern bundlers (Rollup, esbuild) are significantly faster than Webpack for libraries
24
+ 6. **Simpler Mental Model**: Direct tool usage (`"build": "webpack"`) vs indirection (`"build": "grunt"`)
25
+
26
+ ## Proposed Solution
27
+
28
+ **Goal**: Incrementally modernize Rollbar.js development toolchain through targeted infrastructure improvements, enabling TypeScript support and enhanced developer productivity.
29
+
30
+ **Strategic Approach**: This is a **mature SDK/Library** with extensive production usage. Our approach prioritizes:
31
+
32
+ - **Zero disruption** to existing users and API surface
33
+ - **Incremental improvements** that can be validated at each step
34
+ - **Backwards compatibility** maintained throughout the process
35
+ - **Risk mitigation** through careful, staged implementation
36
+
37
+ **Project Type**: This is a **JavaScript SDK/Library**, not a web application. Our tooling choices should prioritize:
38
+
39
+ - Multiple distribution formats (ES modules, CommonJS, UMD, browser bundles, <script> tag)
40
+ - Tree-shaking compatibility for consuming applications
41
+ - Minimal runtime dependencies
42
+ - Package publishing and versioning workflows
43
+ - Cross-platform compatibility (Node.js, browsers, React Native, browser extensions, Electron)
44
+
45
+ **Change Philosophy**: Rather than wholesale replacement, we propose strategic improvements that:
46
+
47
+ 1. Enable TypeScript development and compilation capabilities
48
+ 2. Improve developer experience through targeted tooling updates
49
+ 3. Enhance build performance while maintaining all existing outputs
50
+ 4. Provide foundation for future maintainability improvements
51
+
52
+ ## Working Relationship & Learning Focus
53
+
54
+ - You (matux) are an experienced systems programmer (C/C++, Rust) learning web development ecosystem
55
+ - Claude acts as both implementation partner AND professor/teacher
56
+ - **Didactic Approach**: Claude will explain the "why" behind every tool choice, architectural decision, and modernization step
57
+ - **Educational Goals**: Understanding modern web development tooling, build systems, and JavaScript/TypeScript ecosystem
58
+
59
+ ## Current State Analysis
60
+
61
+ ### Legacy Tooling Stack
62
+
63
+ - **Build System**: Grunt (circa 2012-2014 technology)
64
+ - **Module System**: Mixed CommonJS/UMD with manual bundling
65
+ - **Linting**: ESLint with flat config (partially modern)
66
+ - **Testing**: Karma (deprecated) + Vows.js (abandoned)
67
+ - **Bundling**: Webpack 5 (modern, but limited configuration)
68
+ - **Target Compatibility**: ES5 for broad browser support
69
+ - **TypeScript**: Only type definitions (index.d.ts), no compilation pipeline
70
+
71
+ ### Modernization Challenges
72
+
73
+ 1. **Grunt Dependency**: Heavy reliance on Grunt for build orchestration
74
+ 2. **Mixed Module Systems**: Inconsistent import/export patterns
75
+ 3. **Limited TypeScript**: No compilation pipeline, only definitions
76
+ 4. **Legacy Browser Support**: ES5 targeting limits modern feature adoption
77
+ 5. **Build Complexity**: Multiple output formats (UMD, AMD, vanilla) with manual configuration
78
+
79
+ ## Educational Context: Why These Tools Matter for Libraries
80
+
81
+ ### Build Systems Evolution (Library Perspective)
82
+
83
+ - **Grunt (2012)**: Configuration-heavy task runner, good for complex multi-step builds
84
+ - **Rollup (2015)**: **Ideal for libraries** - ES module-first, excellent tree-shaking, minimal output
85
+ - **Webpack (2012-present)**: Application-focused bundler, heavier runtime, less optimal for libraries
86
+ - **esbuild (2020)**: Ultra-fast bundler/transpiler, excellent for library compilation
87
+ - **tsup (2021)**: Modern library build tool, TypeScript-first, zero-config approach
88
+
89
+ ### Library-Specific Tooling Considerations
90
+
91
+ 1. **Bundle Size**: Libraries should minimize size impact on consuming applications
92
+ 2. **Module Formats**: Must support multiple formats (ESM, CJS, UMD) for compatibility
93
+ 3. **Tree-Shaking**: Enable dead code elimination in consuming applications
94
+ 4. **Peer Dependencies**: Minimize runtime dependencies to avoid version conflicts
95
+ 5. **API Surface**: TypeScript definitions crucial for developer experience
96
+
97
+ ### TypeScript Integration for Libraries
98
+
99
+ 1. **Declaration Generation**: Automatic .d.ts file generation from TypeScript source
100
+ 2. **Multiple Targets**: Compile to different module systems simultaneously
101
+ 3. **API Compatibility**: Ensure TypeScript changes don't break JavaScript consumers
102
+ 4. **Type-Only Imports**: Optimize bundle size by removing type-only code
103
+
104
+ ## Implementation Strategy: Incremental Enhancement
105
+
106
+ **Key Finding**: TypeScript support does NOT require wholesale tooling replacement. We can enable TypeScript capabilities through targeted enhancements to existing infrastructure.
107
+
108
+ **Proposal Rationale**: This approach minimizes risk while delivering immediate value to the development team.
109
+
110
+ ### Current Build Analysis
111
+
112
+ - **Grunt Role**: Orchestrates Webpack, Karma tests, and snippet replacement (273 lines of config)
113
+ - **Webpack Role**: Bundling and minification; Babel transpilation added in v3.x for modern JS/TS support
114
+ - **Karma Issues**: Outdated architecture, complex configuration, performance bottlenecks
115
+ - **Opportunity**: Modern Web Test Runner + TypeScript integration eliminates testing complexity
116
+
117
+ ## Implementation Plan
118
+
119
+ **Primary Goal**: Enable TypeScript support through incremental, validated improvements.
120
+
121
+ ### Phase 1: Complete ES Modules Migration
122
+
123
+ **Rationale**: The mixture of CommonJS and ESM files makes migrating away from Karma to modern solutions like Web Test Runner significantly more difficult. Standardizing on ES modules across the entire codebase will simplify subsequent modernization efforts and provide a consistent module system.
124
+
125
+ **Critical Finding**: Vows.js is fundamentally incompatible with ES modules and blocks server test migration. This must be addressed before completing the ES module migration.
126
+
127
+ 1. **Partial Test Migration to ES Modules** ✅
128
+
129
+ - Migrated 19 of 27 test files from CommonJS to ES modules
130
+ - 8 server test files remain blocked due to Vows.js dependency
131
+ - Migration pattern: `require()` → `import`, add `.js` extensions
132
+ - Completed: utility, API, browser, platform, and example tests
133
+
134
+ 2. **Migrate Vows.js to Mocha** ✅
135
+
136
+ - Replace abandoned Vows.js (last commit 5 years ago) with Mocha
137
+ - Unify test frameworks across browser and server tests
138
+ - Convert Vows patterns: topics → `beforeEach`, batches → `describe`
139
+ - Maintain test coverage and assertion equivalence
140
+
141
+ 3. **Complete Server Test ES Module Migration** ✅
142
+
143
+ - Convert 8 remaining server test files to ES modules
144
+ - Update imports and add `.js` extensions
145
+ - Ensure Node.js test runner supports ES modules
146
+ - Validate all server tests pass with new module system
147
+
148
+ 4. **Migrate Source Code to ES Modules** ✅
149
+ - Start with leaf modules (no internal dependencies)
150
+ - Progress to core modules while maintaining API compatibility
151
+ - Update build configuration for native ES module handling
152
+ - Preserve all distribution formats (CommonJS, UMD, ES modules)
153
+
154
+ ### Phase 2: Modern Testing & TypeScript Foundation
155
+
156
+ 1. **Migrate from Karma to Web Test Runner**
157
+
158
+ - Replace Karma with @web/test-runner for modern, performant browser testing
159
+ - Maintain existing Mocha + Chai + Sinon test framework
160
+ - Configure native TypeScript support without complex preprocessors
161
+ - Update CI/CD pipeline to use new test runner
162
+ - See detailed migration plan in CLAUDE.testrunner.md
163
+
164
+ 2. **Add TypeScript to Build Pipeline**
165
+
166
+ - Install TypeScript and `@babel/preset-typescript`
167
+ - Configure Babel preset for TypeScript compilation
168
+ - Add `tsconfig.json` for type checking and IDE support
169
+ - Update Webpack config to handle `.ts` files
170
+
171
+ 3. **Validation & Testing**
172
+ - Convert small utility functions to TypeScript
173
+ - Verify existing build outputs remain unchanged
174
+ - Test type checking and compilation pipeline
175
+ - Ensure IDE integration works properly
176
+ - Validate all tests pass with new test runner
177
+
178
+ ### Phase 3: Code Quality Standardization
179
+
180
+ **Rationale**: ESLint and Prettier are configured after TypeScript support to enable unified configuration for both JavaScript and TypeScript files, avoiding the need to reconfigure linting rules when TypeScript plugins are added.
181
+
182
+ 1. **Modernize ESLint Configuration**
183
+
184
+ - Review and update ESLint rules for modern JavaScript/TypeScript compatibility
185
+ - Configure ESLint to work seamlessly with TypeScript files
186
+ - Standardize code style rules across browser, server, and test code
187
+ - Add ESLint plugins for better error detection and modern practices
188
+
189
+ 2. **Integrate Prettier for Consistent Formatting**
190
+
191
+ - Add Prettier configuration for automated code formatting
192
+ - Configure Prettier to work alongside ESLint without conflicts
193
+ - Define formatting rules that align with existing code style preferences
194
+ - Set up editor integration for automatic formatting on save
195
+
196
+ 3. **CI/CD Integration**
197
+
198
+ - Add linting and formatting checks to continuous integration pipeline
199
+ - Configure CI to fail builds on linting errors or formatting violations
200
+ - Implement automated formatting validation for pull requests
201
+ - Ensure consistent code quality enforcement across all contributions
202
+
203
+ 4. **Developer Workflow Enhancement**
204
+ - Add npm scripts for linting (`npm run lint`) and formatting (`npm run format`)
205
+ - Set up pre-commit hooks using Husky for automatic code quality checks
206
+ - Update development documentation with code style guidelines
207
+ - Ensure compatibility with popular editors and IDEs
208
+
209
+ ### Phase 4: Build System Migration
210
+
211
+ **Rationale**: Grunt is unmaintained (last release 2 years ago) and adds unnecessary complexity. Direct tool usage via npm scripts provides better performance, clearer workflows, and easier maintenance.
212
+
213
+ 1. **Audit Current Build Process**
214
+
215
+ - Map all Grunt tasks and their purposes
216
+ - Document all output formats (UMD, ES modules, minified versions)
217
+ - Analyze bundle sizes and compilation times
218
+ - Identify pain points in current developer workflow
219
+
220
+ 2. **Research Modern Alternatives**
221
+
222
+ - Evaluate continuing with Webpack vs migrating to library-focused alternatives (Rollup, esbuild, tsup)
223
+ - Compare build performance and output quality
224
+ - Assess migration complexity for each option
225
+ - Plan strategy to maintain all current outputs
226
+
227
+ 3. **Replace Grunt with Direct Tool Usage**
228
+ - Migrate to npm scripts calling tools directly
229
+ - Implement modern bundling with library-optimized tools
230
+ - Maintain all existing output formats
231
+ - Optimize for tree-shaking and bundle efficiency
232
+
233
+ ### Phase 5: TypeScript Migration
234
+
235
+ 1. **Systematic TypeScript Conversion**
236
+ - Start with utility functions and shared code
237
+ - Convert platform-specific implementations
238
+ - Maintain JavaScript API compatibility
239
+ - Enable stricter TypeScript settings incrementally
240
+
241
+ ### Phase 6: Developer Experience & Library Enhancements
242
+
243
+ 1. **Enhanced Development Experience**
244
+
245
+ - Fast TypeScript compilation with watch mode
246
+ - Improved source maps and debugging
247
+ - Better error reporting and build feedback
248
+ - Hot module replacement for development
249
+
250
+ 2. **Library-Specific Enhancements**
251
+ - Automatic declaration file generation
252
+ - Type-only import optimization
253
+ - Enhanced IDE support and developer experience
254
+ - Cross-platform TypeScript testing
255
+
256
+ ## Success Criteria
257
+
258
+ 1. **TypeScript Support**: Full compilation pipeline with declaration generation
259
+ 2. **Multiple Formats**: ESM, CJS, UMD outputs all maintained
260
+ 3. **Tree-Shaking**: Consuming applications can eliminate unused code
261
+ 4. **Developer Experience**: Fast builds, excellent IDE support
262
+ 5. **Backward Compatibility**: No breaking changes; existing users unaffected by development toolchain improvements
263
+ 6. **Bundle Efficiency**: Smaller or equivalent bundle sizes
264
+ 7. **Security**: All security alerts resolved (https://github.com/rollbar/rollbar.js/security/dependabot)
265
+
266
+ ---
267
+
268
+ _This document will evolve as we learn and make decisions together. Each major decision will include educational context about why we chose specific approaches for library development._
269
+
270
+ --
271
+
272
+ ## Next Steps
273
+
274
+ **Current Status**: Phase 2.1 (Migrate from Karma to Web Test Runner) 🚧 Ready to Start
275
+
276
+ - Phase 1.1: Partial Test Migration to ES Modules ✅
277
+ - Phase 1.2: Migrate Vows.js to Mocha ✅
278
+ - Phase 1.3: Complete Server Test ES Module Migration ✅
279
+ - Phase 1.4: Migrate Source Code to ES Modules ✅ Complete
280
+
281
+ **Phase 1 Completion Notes**:
282
+ - Successfully migrated all source and test files from CommonJS to ES modules
283
+ - Handled Node.js version compatibility for JSON imports using `createRequire`
284
+ - All tests passing with ES module syntax
285
+ - Package.json updated with `"type": "module"`
286
+ - Configuration files renamed to `.cjs` extension for compatibility
287
+
288
+ **Immediate Next Step**:
289
+
290
+ - **Execute Karma to Web Test Runner Migration (Phase 2.1)** - Create a thorough and well-thought-out migration plan in CLAUDE.testrunner.md
291
+
292
+ **Upcoming Steps**:
293
+
294
+ 1. **Add TypeScript to Build Pipeline (Phase 2.2)** - Enable TypeScript compilation without changing build system
295
+ 2. **Implement Code Quality Standards (Phase 3)** - Add Prettier and modernize ESLint configuration
296
+ 3. **Build System Migration (Phase 4)** - Replace Grunt with direct tool usage
297
+ 4. **TypeScript Migration (Phase 5)** - Systematic conversion to TypeScript
package/CLAUDE.md ADDED
@@ -0,0 +1,201 @@
1
+ ## About Rollbar.js
2
+
3
+ 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.
4
+
5
+ The library works across platforms, supporting both browser and server-side JavaScript including frameworks like React, Angular, Express, and Next.js. Key features include:
6
+
7
+ - Cross-platform error tracking for client and server-side code
8
+ - Telemetry to provide context around errors (breadcrumbs of events)
9
+ - Automatic error grouping to reduce noise
10
+ - Real-time notifications for critical issues
11
+ - Detailed stack traces with source maps support
12
+ - Distributed tracing and session management
13
+ - Session replay capabilities for reproducing user actions
14
+
15
+ ## Project Structure
16
+
17
+ ```
18
+ src/
19
+ ├── browser/ # Browser-specific implementation
20
+ ├── server/ # Node.js-specific implementation
21
+ ├── react-native/ # React Native implementation
22
+ ├── tracing/ # Distributed tracing support
23
+ └── utility/ # Shared utility functions
24
+ ```
25
+
26
+ ## Build & Test Commands
27
+
28
+ - Build: `npm run build` (runs Grunt)
29
+ - Lint: `npm run lint` (ESLint)
30
+ - Test all: `npm run test` (runs both server and browser tests)
31
+ - Test browser only: `npm run test-browser`
32
+ - Test server only: `npm run test-server`
33
+ - Test specific browser test: `grunt test-browser:specificTestName`
34
+ - Example: `grunt test-browser:transforms`
35
+ - Single test: `./node_modules/.bin/karma start --single-run --files={path/to/test}`
36
+
37
+ ## Modern Development Environment
38
+
39
+ As of version 3.0.0, the SDK has been updated to use modern JavaScript features with appropriate transpilation:
40
+
41
+ - **ES Modules**: The codebase supports ES modules (`import/export`) syntax
42
+ - **Target Compatibility**:
43
+ - Source code uses ECMAScript 2021 features
44
+ - Builds target ES5 for broad browser compatibility
45
+ - Lower versions can use the ES5/CommonJS compatible bundles
46
+ - **Build System**:
47
+ - Webpack 5 with Babel for transpilation
48
+ - ESLint for code quality
49
+ - Configurable output formats (UMD, AMD, vanilla)
50
+ - **Minimum Node.js**: Version 18+ for absolute imports
51
+ - **Toolchain Configuration**:
52
+ - `babel.config.json`: Controls transpilation options
53
+ - `eslint.config.mjs`: Modern ESLint flat config format
54
+ - `webpack.config.js`: Manages bundling and output formats
55
+
56
+ ## Code Style Guidelines
57
+
58
+ - Use single quotes for strings
59
+ - Use camelCase for variables (underscore prefix for private)
60
+ - Indentation: 2 spaces
61
+ - Include trailing commas in multiline objects/arrays
62
+ - Max function complexity: 35
63
+ - Unused parameters prefixed with underscore: `function(a, _unused) {}`
64
+ - No whitespace in empty lines
65
+ - Files should end with exactly one newline
66
+ - Control statements (if, for, while, etc.) MUST use braces and newlines, even for single statements
67
+ - Opening braces should be on the same line as the control statement
68
+ - ESLint is used for enforcing code style
69
+ - Prettier for code formatting
70
+
71
+ ### Documentation vs. Comments
72
+
73
+ - **Function Documentation (JSDoc/TSDoc)**: Always include comprehensive documentation for functions, classes, and methods using JSDoc/TSDoc format (`/** ... */`). These serve as API documentation, appear in IDE tooltips, and help developers understand purpose, parameters, and return values.
74
+
75
+ - **Inline Code Comments**: Avoid redundant comments that merely restate what the code is doing. Only add comments to explain:
76
+ - Why the code works a certain way (decisions and reasoning)
77
+ - Non-obvious behavior or edge cases
78
+ - Complex algorithms or business logic
79
+ - Workarounds for bugs or limitations
80
+
81
+ - **Self-documenting Code**: Write clear, readable code that explains itself through descriptive variable/function names and straightforward logic. Well-written code rarely needs explanatory comments.
82
+
83
+ - **Examples**:
84
+ ```javascript
85
+ // BAD - Redundant comment
86
+ // Add one to x
87
+ x += 1;
88
+
89
+ // GOOD - Explains the non-obvious "why"
90
+ // Increment before sending to API to account for zero-indexing
91
+ x += 1;
92
+ ```
93
+
94
+ ## SDK Design Principles
95
+
96
+ - **User Problems Are SDK Improvement Opportunities**: When users encounter integration issues, treat these as SDK design improvements rather than user implementation mistakes.
97
+ - Focus on enhancing the SDK to be more robust, intuitive and resilient
98
+ - Implement automatic environment detection and appropriate behavior selection
99
+ - Design APIs that work correctly across all supported contexts without requiring special user handling
100
+ - Errors should be informative and suggest correct usage patterns
101
+ - The burden of complexity should rest with the SDK, not its users
102
+
103
+ ## Error Handling
104
+
105
+ - Prefer try/catch blocks around risky operations
106
+ - Log errors through Rollbar's own logger system
107
+ - Scrub sensitive fields in error payloads (see package.json defaults)
108
+ - The codebase uses a comprehensive error tracking approach with appropriate levels:
109
+ - Debug level for development info
110
+ - Warning level for non-critical issues
111
+ - Error level for uncaught exceptions
112
+
113
+ ## TypeScript Support
114
+
115
+ - Type definitions in index.d.ts
116
+ - Add JSDoc types to enable intellisense when needed
117
+
118
+ ## Common Patterns
119
+
120
+ When working with this codebase, be aware of these patterns:
121
+
122
+ - Error transformation and normalization before sending
123
+ - Telemetry collection for context
124
+ - Queue-based sending with retry logic
125
+ - Environment and context detection
126
+ - Scrubbing of sensitive data
127
+
128
+ ## Testing Philosophy
129
+
130
+ - **Analyze Test Failures Objectively**: When tests fail, evaluate both possibilities objectively:
131
+
132
+ - The test could be correctly identifying an actual code issue
133
+ - The test itself might contain errors or invalid expectations
134
+
135
+ - **Diagnostic Process**:
136
+
137
+ 1. Examine what the test is expecting vs. what the code actually does
138
+ 2. Consider the intended behavior and design of the system
139
+ 3. If the test is correct and identifying a legitimate bug, fix the code
140
+ 4. If the test contains misconceptions or errors, fix the test
141
+
142
+ - **Default to Code Quality**: When in doubt and both seem potentially valid, prioritize improving code quality over modifying tests to pass
143
+
144
+ ## Tracing & Session Replay
145
+
146
+ The `src/tracing/` directory contains an OpenTelemetry-inspired tracing implementation that powers both distributed tracing and session recording features:
147
+
148
+ ### Components
149
+
150
+ - **Context & ContextManager**: Manages propagation of tracing context through the application
151
+ - **Span**: Represents a unit of work or operation with timing information and attributes
152
+ - **Tracer**: Creates and manages spans for tracking operations
153
+ - **SpanProcessor & SpanExporter**: Processes and exports spans to their destination
154
+ - **Session**: Manages browser session data persistence and creation
155
+
156
+ ### Usage Patterns
157
+
158
+ - **Tracing initialization**: Initialize via the main Tracing class with appropriate configuration
159
+ - **Context propagation**: Use context to pass trace information between components
160
+ - **Span creation**: Create spans to measure operations with `startSpan()`
161
+ - **Attributes and events**: Add metadata to spans with `setAttribute()` and `addEvent()`
162
+ - **Session management**: Automatically manages user sessions via browser sessionStorage
163
+
164
+ ### Session Replay Implementation
165
+
166
+ The `src/browser/replay` directory contains the implementation of the Session Replay feature:
167
+
168
+ - **Recorder**: Core class that integrates with rrweb to record DOM events
169
+ - **ReplayMap**: Manages the mapping between error occurrences and session recordings
170
+ - **Configuration**: Configurable options in `defaults.js` for replay behavior
171
+
172
+ The Session Replay feature utilizes our tracing infrastructure to:
173
+
174
+ - Record user interactions using rrweb in a memory-efficient way
175
+ - Store recordings with checkpoints for better performance
176
+ - Generate spans that contain replay events with proper timing
177
+ - Associate recordings with user sessions for complete context
178
+ - Transport recordings to Rollbar servers via the API
179
+
180
+ ### Session Replay Flow
181
+
182
+ 1. **Recording**: The Recorder class continuously records DOM events using rrweb
183
+ 2. **Error Occurrence**: When an error occurs, Queue.addItem() calls ReplayMap.add()
184
+ 3. **Correlation**: ReplayMap generates a replayId and attaches it to the error
185
+ 4. **Coordination**: After successful error submission, Queue triggers ReplayMap.send()
186
+ 5. **Transport**: ReplayMap retrieves stored replay data and sends via api.postSpans()
187
+
188
+ ### Testing Infrastructure
189
+
190
+ - **Unit Tests**: Component-focused tests in `test/replay/unit/`
191
+ - **Integration Tests**: Test component interactions in `test/replay/integration/`
192
+ - **End-to-End Tests**: Full flow verification in `test/replay/integration/e2e.test.js`
193
+ - **Mock Implementation**: `test/replay/util/mockRecordFn.js` provides a deterministic mock of rrweb
194
+ - **Fixtures**: Realistic rrweb events in `test/fixtures/replay/` for testing
195
+ - **Test Tasks**: Custom Grunt tasks for testing replay code specifically
196
+
197
+ ## File Creation Guidelines
198
+
199
+ - **Newlines**: All new files MUST end with exactly one newline character
200
+ - **Encoding**: Use UTF-8 encoding for all text files
201
+ - **Line Endings**: Use LF (Unix-style) line endings, not CRLF