Repository navigation
fix: fireHTTPStats to emit metrics about requests only - #4635
Conversation
Summary by CodeRabbit
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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. Comment Pre-merge checks✅ Passed checks (3 passed)
|
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/adapters/network.js (1)
8-8: Fix ESLint error: remove unused import.
isDefinedAndNotNullis unused and breaks the Verify job.Apply:
-const { isDefinedAndNotNull, PlatformError } = require('@rudderstack/integrations-lib'); +const { PlatformError } = require('@rudderstack/integrations-lib');
🧹 Nitpick comments (5)
src/adapters/network.js (3)
85-101: Single-call semantics: good simplification; align observability.Change is clear and reduces complexity. Please notify owners of dashboards/alerts relying on per-metadata fan-out so they can adjust expectations and thresholds.
87-88: Edge-case: network errors without response.status.For successful paths,
response.statusshould exist, but adding a safe default keeps tags consistent if any custom client returns a truthysuccesswithoutstatus.- const statusCode = clientResponse.success - ? clientResponse.response?.status + const statusCode = clientResponse.success + ? (clientResponse.response?.status ?? 200) : getErrorStatusCode(clientResponse.response);
90-100: Minor readability: deconstructstatTagsonce.Reduces repetition and keeps the call-site compact.
- fireOutgoingReqStats({ - destType: statTags.destType || '', - feature: statTags.feature || '', - endpointPath: statTags.endpointPath || '', - requestMethod: statTags.requestMethod || '', - module: statTags.module || '', - metadata: statTags.metadata, + const { + destType = '', + feature = '', + endpointPath = '', + requestMethod = '', + module: moduleTag = '', + metadata, + } = statTags || {}; + + fireOutgoingReqStats({ + destType, + feature, + endpointPath, + requestMethod, + module: moduleTag, + metadata, statusCode, startTime, clientResponse, });src/adapters/network.test.js (2)
139-176: Array metadata test updated: good; add counter assertion to cover status code path.You’ve validated the single timing event. Also assert
outgoing_request_countto exercise the new statusCode derivation.expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.counter).toHaveBeenCalledTimes(1); + expect(stats.counter).toHaveBeenNthCalledWith( + 1, + 'outgoing_request_count', + 1, + expect.objectContaining({ + destType: 'DT', + feature: 'feat', + module: '', + endpointPath: '/some/url', + requestMethod: 'post', + success: false, + statusCode: 400, + }), + );
382-558: Additional shape tests: solid; consider one success-path counter assertion.Great spread across null/string/boolean/complex/mixed. Add at least one assertion for
stats.counteron a success case to ensurestatusCode: 200is emitted.expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.counter).toHaveBeenCalledTimes(1); + expect(stats.counter).toHaveBeenNthCalledWith( + 1, + 'outgoing_request_count', + 1, + expect.objectContaining({ + destType: 'DT', + feature: 'feat', + module: '', + endpointPath: '/some/url', + requestMethod: 'post', + success: true, + statusCode: 200, + }), + );
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/adapters/network.js(1 hunks)src/adapters/network.test.js(7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/adapters/network.test.jssrc/adapters/network.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#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.
Applied to files:
src/adapters/network.test.js
🧬 Code graph analysis (2)
src/adapters/network.test.js (2)
src/v0/destinations/marketo_static_list/transform.js (1)
metadataArray(166-166)src/adapters/network.js (6)
stats(9-9)startTime(163-163)clientResponse(116-116)clientResponse(128-128)clientResponse(151-151)fireHTTPStats(85-101)
src/adapters/network.js (6)
src/v0/destinations/marketo/util.js (2)
clientResponse(250-257)clientResponse(269-276)src/v0/destinations/monday/util.js (1)
clientResponse(183-202)src/adapters/utils/networkUtils.js (2)
clientResponse(136-136)clientResponse(161-161)src/cdk/v2/destinations/intercom/utils.js (3)
statTags(483-490)statTags(537-543)statTags(577-583)src/v0/destinations/klaviyo/util.js (1)
statusCode(103-103)src/v0/util/index.js (1)
getErrorStatusCode(1553-1567)
🪛 GitHub Actions: Verify
src/adapters/network.js
[error] 8-8: ESLint failed on command 'npx eslint src/adapters/network.js src/adapters/network.test.js --fix'. 'isDefinedAndNotNull' is assigned a value but never used. (no-unused-vars)
⏰ 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). (9)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/adapters/network.test.js (2)
236-244: Edge-case coverage looks right.Validates empty/mixed/null arrays map to a single timing event with base tags only. Nice.
Also applies to: 304-312
166-176: Expectation change to single emission: aligned with new behavior.Assertion updated from 2 to 1 call is correct given the simplification.
- Remove complex metadata array processing logic - Pass metadata directly to fireOutgoingReqStats - Update tests to reflect simplified behavior - Add comprehensive test coverage for various metadata types
3c5c8ab to
5c275d8
Compare
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4635 +/- ##
========================================
Coverage 91.78% 91.78%
========================================
Files 642 642
Lines 33941 33943 +2
Branches 8042 8033 -9
========================================
+ Hits 31153 31155 +2
- Misses 2536 2558 +22
+ Partials 252 230 -22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/logger.js (1)
27-34: Add default in getLogger to satisfy ESLint and avoid undefined loggerMissing
defaultcan tripdefault-case/consistent-returnand returnundefinedfor unexpected values.const getLogger = () => { switch (loggerImpl) { case 'winston': return logger; case 'console': return console; + default: + return logger; } };
🧹 Nitpick comments (2)
src/logger.js (2)
36-40: Avoid shadowing outerloggerin setLogLevel (no-shadow)Rename the inner variable to prevent shadowing and silence lint.
const setLogLevel = (level) => { - const logger = getLogger(); + const currentLogger = getLogger(); logLevel = level || logLevel; - logger?.setLogLevel(logLevel); + currentLogger?.setLogLevel(logLevel); };
49-52: Pick first non-null object via find; align with array handling in log()Using
filter(...)[0]scans the whole array and may select a non-object (e.g., string) ahead of a valid object. Preferfindand restrict to objects; fall back to first defined non-null if no object exists.let reqMeta = metadata; if (Array.isArray(metadata)) { - [reqMeta] = metadata.filter(isDefinedAndNotNull); + reqMeta = + metadata.find((m) => isDefinedAndNotNull(m) && typeof m === 'object' && !Array.isArray(m)) ?? + metadata.find(isDefinedAndNotNull); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/adapters/network.js(2 hunks)src/adapters/network.test.js(7 hunks)src/logger.js(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/adapters/network.test.js
- src/adapters/network.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit configuration file
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/logger.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#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.
Applied to files:
src/logger.js
🧬 Code graph analysis (1)
src/logger.js (1)
src/v0/util/index.js (1)
isDefinedAndNotNull(51-51)
⏰ 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). (7)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
🔇 Additional comments (2)
src/logger.js (2)
2-6: Verify export: isDefinedAndNotNull from @rudderstack/integrations-libIf the package version used by this repo doesn’t export
isDefinedAndNotNull, ESLint’s import rules and runtime will fail. Please confirm the symbol exists in that package/version.
94-107: Confirm intent: array metadata logs multiple entriesThis path logs once per object in
metadata. Given the PR’s “single event” direction for HTTP stats, confirm whether logs should also be single-entry. If yes, consider collapsing to the first valid element.- if (Array.isArray(metadata)) { - metadata - .filter((m) => typeof m === 'object' && !Array.isArray(m)) - .forEach((m) => { - logMethod( - message, - { - ...getLogMetadata(m), - ...otherLogInfoArgs, - }, - ...otherArgs, - ); - }); - return; - } + if (Array.isArray(metadata)) { + const m = + metadata.find((x) => typeof x === 'object' && x !== null && !Array.isArray(x)) ?? + metadata.find(isDefinedAndNotNull); + logMethod( + message, + { + ...getLogMetadata(m), + ...otherLogInfoArgs, + }, + ...otherArgs, + ); + return; + }



What are the changes introduced in this PR?
Fixed fireHTTPStats to fire only once per request instead of for each job. The function was incorrectly processing metadata arrays and calling fireOutgoingReqStats multiple times per request.
What is the related Linear task?
N/A
Please explain the objectives of your changes below
The fireHTTPStats function was incorrectly firing stats for each job in the metadata array instead of once per request. This change fixes the behavior by:
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
Bug Fix: The function now correctly calls fireOutgoingReqStats only once per request instead of multiple times for each job in the metadata array. This fixes the incorrect stats reporting behavior.
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
@coderabbitai review
Developer checklist
Reviewer checklist