Repository navigation
Conversation
Summary by CodeRabbit
WalkthroughThis change introduces a utility for safe integer environment variable parsing and applies it to configure Pyroscope profiling parameters. Pyroscope initialization is updated to use these parameters explicitly. Error statistics tracking is refined to pass selected error fields instead of whole objects. Prometheus counters gain two new error-related labels. Associated tests are expanded. Changes
Sequence Diagram(s)sequenceDiagram
participant Env as process.env
participant MW as middleware.js
participant Pyro as Pyroscope
Env->>MW: Provide environment variables
MW->>MW: parseEnvInt for each Pyroscope config param
MW->>Pyro: Initialize Pyroscope with explicit params
MW->>Pyro: Pyroscope.start()
sequenceDiagram
participant Service as Service
participant Stats as stats.increment
Service->>Stats: increment({ destType, module, destinationId, workspaceId, feature, implementation, errorCategory, errorType })
Estimated code review effort3 (~40 minutes) Possibly related PRs
Suggested reviewers
Suggestions for improvement:
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/middleware.test.js (1)
206-206: Optimize delete operator for better performance.The static analysis tool correctly identified that the
deleteoperator can impact performance. Use an undefined assignment instead.Apply this change:
- delete process.env.TEST_VAR; + process.env.TEST_VAR = undefined;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
CHANGELOG.mdis excluded by!**/*.mdpackage-lock.jsonis excluded by!**/package-lock.json,!**/*.jsonpackage.jsonis excluded by!**/*.json
📒 Files selected for processing (5)
src/middleware.js(2 hunks)src/middleware.test.js(4 hunks)src/services/destination/cdkV2Integration.ts(1 hunks)src/services/destination/postTransformation.ts(3 hunks)src/util/prometheus.js(2 hunks)
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit Configuration File
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/util/prometheus.jssrc/middleware.jssrc/middleware.test.js
🧠 Learnings (3)
src/services/destination/cdkV2Integration.ts (6)
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/routerTransformCompactedPayloadV1.ts:13-24
Timestamp: 2025-04-02T08:21:38.217Z
Learning: In the Rudder Transformer codebase, use generic Error objects instead of TransformationError when error monitoring with Bugsnag is needed, as TransformationError is configured to not trigger Bugsnag alerts.
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js assumes metadata is always an array throughout its implementation, but defensive programming should be added to handle cases where metadata might not be an array type to prevent runtime errors.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the ArraySpreader/BaseSpreader middleware, error handling for the transform function is already implemented in the caller (BaseSpreader's middleware method), making additional error handling in individual transform functions unnecessary.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/destTransformCompactedPayloadV1.ts:13-19
Timestamp: 2025-04-02T08:16:58.002Z
Learning: In the Rudder Transformer project, error handling should throw errors with descriptive messages (after logging them) rather than returning HTTP status codes, so that Bugsnag can catch them for debugging purposes.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the BaseSpreader middleware implementation, error handling for transform functions is already handled in the middleware() method with a try-catch block, which wraps errors in a PlatformError. This makes additional error handling inside individual transform functions unnecessary.
src/services/destination/postTransformation.ts (8)
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/routerTransformCompactedPayloadV1.ts:13-24
Timestamp: 2025-04-02T08:21:38.217Z
Learning: In the Rudder Transformer codebase, use generic Error objects instead of TransformationError when error monitoring with Bugsnag is needed, as TransformationError is configured to not trigger Bugsnag alerts.
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the ArraySpreader/BaseSpreader middleware, error handling for the transform function is already implemented in the caller (BaseSpreader's middleware method), making additional error handling in individual transform functions unnecessary.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/destTransformCompactedPayloadV1.ts:13-19
Timestamp: 2025-04-02T08:16:58.002Z
Learning: In the Rudder Transformer project, error handling should throw errors with descriptive messages (after logging them) rather than returning HTTP status codes, so that Bugsnag can catch them for debugging purposes.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the BaseSpreader middleware implementation, error handling for transform functions is already handled in the middleware() method with a try-catch block, which wraps errors in a PlatformError. This makes additional error handling inside individual transform functions unnecessary.
Learnt from: anantjain45823
PR: #2884
File: src/services/destination/nativeIntegration.ts:207-207
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The startTime variable is correctly scoped within the map callback function in the processUserDeletion method, ensuring individual timing metrics for each user deletion request.
Learnt from: anantjain45823
PR: #2884
File: src/services/destination/nativeIntegration.ts:207-207
Timestamp: 2024-10-08T15:52:59.819Z
Learning: The startTime variable is correctly scoped within the map callback function in the processUserDeletion method, ensuring individual timing metrics for each user deletion request.
src/middleware.test.js (1)
Learnt from: anantjain45823
PR: #2842
File: src/v1/sources/shopify/identifierEventsLayer.test.js:5-40
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The processIdentifierEvent function in identifierEventsLayer.test.js is designed to succeed for any input, hence no negative test cases are required.
🪛 Biome (1.9.4)
src/middleware.test.js
[error] 206-206: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit Configuration File
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/util/prometheus.jssrc/middleware.jssrc/middleware.test.js
🧠 Learnings (3)
src/services/destination/cdkV2Integration.ts (6)
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/routerTransformCompactedPayloadV1.ts:13-24
Timestamp: 2025-04-02T08:21:38.217Z
Learning: In the Rudder Transformer codebase, use generic Error objects instead of TransformationError when error monitoring with Bugsnag is needed, as TransformationError is configured to not trigger Bugsnag alerts.
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js assumes metadata is always an array throughout its implementation, but defensive programming should be added to handle cases where metadata might not be an array type to prevent runtime errors.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the ArraySpreader/BaseSpreader middleware, error handling for the transform function is already implemented in the caller (BaseSpreader's middleware method), making additional error handling in individual transform functions unnecessary.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/destTransformCompactedPayloadV1.ts:13-19
Timestamp: 2025-04-02T08:16:58.002Z
Learning: In the Rudder Transformer project, error handling should throw errors with descriptive messages (after logging them) rather than returning HTTP status codes, so that Bugsnag can catch them for debugging purposes.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the BaseSpreader middleware implementation, error handling for transform functions is already handled in the middleware() method with a try-catch block, which wraps errors in a PlatformError. This makes additional error handling inside individual transform functions unnecessary.
src/services/destination/postTransformation.ts (8)
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/routerTransformCompactedPayloadV1.ts:13-24
Timestamp: 2025-04-02T08:21:38.217Z
Learning: In the Rudder Transformer codebase, use generic Error objects instead of TransformationError when error monitoring with Bugsnag is needed, as TransformationError is configured to not trigger Bugsnag alerts.
Learnt from: maheshkutty
PR: #4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The combineBatchRequestsWithSameJobIds function in src/v0/util/index.js is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the ArraySpreader/BaseSpreader middleware, error handling for the transform function is already implemented in the caller (BaseSpreader's middleware method), making additional error handling in individual transform functions unnecessary.
Learnt from: vinayteki95
PR: #4220
File: src/middlewares/destTransformCompactedPayloadV1.ts:13-19
Timestamp: 2025-04-02T08:16:58.002Z
Learning: In the Rudder Transformer project, error handling should throw errors with descriptive messages (after logging them) rather than returning HTTP status codes, so that Bugsnag can catch them for debugging purposes.
Learnt from: ItsSudip
PR: #4186
File: src/middlewares/arraySpreader.ts:48-63
Timestamp: 2025-04-08T02:59:55.677Z
Learning: In the BaseSpreader middleware implementation, error handling for transform functions is already handled in the middleware() method with a try-catch block, which wraps errors in a PlatformError. This makes additional error handling inside individual transform functions unnecessary.
Learnt from: anantjain45823
PR: #2884
File: src/services/destination/nativeIntegration.ts:207-207
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The startTime variable is correctly scoped within the map callback function in the processUserDeletion method, ensuring individual timing metrics for each user deletion request.
Learnt from: anantjain45823
PR: #2884
File: src/services/destination/nativeIntegration.ts:207-207
Timestamp: 2024-10-08T15:52:59.819Z
Learning: The startTime variable is correctly scoped within the map callback function in the processUserDeletion method, ensuring individual timing metrics for each user deletion request.
src/middleware.test.js (1)
Learnt from: anantjain45823
PR: #2842
File: src/v1/sources/shopify/identifierEventsLayer.test.js:5-40
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The processIdentifierEvent function in identifierEventsLayer.test.js is designed to succeed for any input, hence no negative test cases are required.
🪛 Biome (1.9.4)
src/middleware.test.js
[error] 206-206: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (15)
src/util/prometheus.js (2)
265-266: LGTM: Enhanced error tracking granularityThe addition of
errorCategoryanderrorTypelabels to theevent_transform_failurecounter will provide better observability and debugging capabilities for transformation failures.
394-402: LGTM: Consistent label additions with improved formattingThe addition of
errorCategoryanderrorTypelabels to theregulation_worker_user_deletion_failurecounter maintains consistency with theevent_transform_failuremetric. The reformatting of the labelNames array also improves readability.src/services/destination/cdkV2Integration.ts (1)
101-110: LGTM: Explicit error detail passing improves consistencyThe change from passing the entire
metaTo.errorDetailsobject to explicitly enumerating each property ensures better control over what data is sent to the metrics system. This aligns perfectly with the newerrorCategoryanderrorTypelabels added to the Prometheusevent_transform_failurecounter.src/services/destination/postTransformation.ts (3)
111-120: LGTM: Consistent explicit error detail passingThe modification to explicitly pass individual error detail properties instead of the entire
metaTo.errorDetailsobject maintains consistency with similar changes across the codebase and aligns with the enhanced Prometheus metric labels.
149-159: LGTM: Proper error tracking alignmentThe explicit enumeration of error detail properties for the
event_transform_failuremetric ensures consistent data structure and aligns with the updated Prometheus metric definition that includeserrorCategoryanderrorTypelabels.
238-247: LGTM: User deletion error tracking enhancementThe change to explicitly pass error detail properties for the
regulation_worker_user_deletion_failuremetric is consistent with the pattern applied throughout the codebase and properly leverages the newerrorCategoryanderrorTypelabels added to the corresponding Prometheus counter.src/middleware.js (5)
6-15: Well-implemented environment variable parsing utility.The
parseEnvIntfunction properly handles edge cases including undefined values, empty strings, whitespace, and non-integer inputs. The use ofNumber.isInteger()ensures only valid integers are returned, with fallback to defaults for invalid inputs.
17-29: Appropriate default values for Pyroscope profiling parameters.The constants use sensible defaults: 60-second sampling duration, 10ms sampling interval, 512KB heap sampling interval, and 64 stack depth. These values provide good balance between profiling detail and performance impact.
31-43: Enhanced Pyroscope configuration with proper parameterization.The initialization now includes explicit wall and heap profiling parameters, making the profiling behavior configurable through environment variables. The pull mode comment clearly explains the serverAddress omission for Grafana Agent integration.
45-46: Essential Pyroscope.start() call added.The explicit
Pyroscope.start()call is required to activate profiling after initialization. The comment clearly indicates this requirement.
102-106: Appropriate exports for testing and reusability.The new exports enable comprehensive testing of the environment variable parsing utility and Pyroscope configuration constants.
src/middleware.test.js (4)
8-12: Necessary imports for testing new functionality.The imported constants and
parseEnvIntfunction are properly utilized in the expanded test suite.
23-23: Required mock update for Pyroscope.start() method.The mock properly includes the
startmethod that's now called in the main module.
42-49: Comprehensive validation of Pyroscope configuration parameters.The test now properly verifies that all wall and heap profiling parameters are correctly passed to the Pyroscope initialization, ensuring the environment variable configuration works as expected.
192-277: Comprehensive test suite with excellent coverage.The
parseEnvInttest suite thoroughly covers all edge cases including undefined values, empty strings, whitespace, valid/invalid inputs, and different data types. The environment variable isolation is properly implemented.
|
Allure Test reports for this run are available at:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4520 +/- ##
========================================
Coverage 91.44% 91.44%
========================================
Files 639 639
Lines 33772 33786 +14
Branches 7983 7989 +6
========================================
+ Hits 30884 30897 +13
- Misses 2626 2627 +1
Partials 262 262 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|


👑 An automated PR