Skip to content

feat: implement transformerProxy for am - #4703

Merged
ItsSudip merged 7 commits into
chore/amProxyTestCasesfrom
feat/amTransformerProxy
Oct 14, 2025
Merged

ItsSudip merged 7 commits into
chore/amProxyTestCasesfrom
feat/amTransformerProxy

Conversation

@ItsSudip

@ItsSudip ItsSudip commented Oct 8, 2025 •

Copy link
Copy Markdown
Member

What are the changes introduced in this PR?

This PR implements transformerProxy support for Amplitude (am) destination through the v1 route. It introduces a new network handler that enables proxy-based event delivery with comprehensive error handling, batch support, and Amplitude-specific response processing.

What is the related Linear task?

Resolves INT-4077

Please explain the objectives of your changes below

This PR enables the transformerProxy functionality for Amplitude destination, which was previously unsupported. The implementation allows events to be delivered through the proxy layer with proper response handling, error classification, and retry logic specific to Amplitude's API behavior.

Key Objectives:

  1. Enable v1 proxy delivery for Amplitude destination
  2. Implement proper error handling for different HTTP status codes
  3. Add special handling for Amplitude's throttling mechanism (throttled users/devices)
  4. Support batch event processing with dontBatch logic for partial failures
  5. Enable comprehensive test coverage for proxy delivery scenarios

Any changes to existing capabilities/behaviour, mention the reason & what are the changes?

No changes to existing capabilities. This is a new feature addition that:

  • Adds v1 proxy support without affecting existing v0 transformation logic
  • Existing Amplitude destination functionality remains unchanged
  • Only adds new v1 proxy delivery capability

Any new dependencies introduced with this change?

No new dependencies. The implementation uses existing utilities:

  • @rudderstack/integrations-lib (already exists)
  • Existing proxy infrastructure (prepareProxyRequest, proxyRequest)
  • Existing utility functions (processAxiosResponse, HTTP status helpers)

Any new generic utility introduced or modified. Please explain the changes.

No new generic utilities. The implementation leverages existing utilities:

  • Uses standard isHttpStatusSuccess, isHttpStatusRetryable, isHttpStatusThrottled helpers
  • Utilizes existing AbortedError, RetryableError, ThrottledError error classes
  • Follows established proxy handler patterns from other v1 destinations

Any technical or performance related pointers to consider with the change?

Technical Considerations:

  1. Error Classification: Implements intelligent error handling:

    • 200-299: Success response with individual event status mapping
    • 429 (Throttled): Special handling for throttled_users and throttled_devices
      • If users/devices are throttled: Throws RetryableError (will retry with backoff)
      • Other 429 cases: Throws ThrottledError (circuit breaker logic)
    • 500-599: Retryable errors (infrastructure/temporary failures)
    • 400-499 (except 429): Aborted errors (permanent failures)
  2. Batch Processing Logic:

    • For batch requests with multiple events that fail, returns individual responses with dontBatch: true
    • This signals the server to retry events individually rather than as a batch
    • Improves delivery success rate for partially failed batches
  3. Amplitude-Specific Handling:

    • Properly parses Amplitude's throttled_users and throttled_devices response fields
    • Differentiates between user/device-level throttling vs general rate limiting
    • Ensures appropriate retry behavior based on throttle type
  4. Performance Benefits:

    • Enables batched event delivery through proxy (previously unsupported)
    • Reduces network overhead by processing multiple events in single requests
    • Proper error handling prevents unnecessary retries for permanent failures
  5. Test Coverage:

    • Enabled 11 comprehensive test cases covering:
      • Success scenarios (200 responses)
      • Retryable errors (500, 503)
      • Throttling scenarios (429 with throttled users/devices)
      • Aborted errors (400, 413)
      • Batch processing with partial failures
      • Single and multiple event scenarios

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project
  • No breaking changes are being introduced.
  • All related docs linked with the PR?
  • All changes manually tested?
  • Any documentation changes needed with this change?
  • Is the PR limited to 10 file changes? (2 files changed)
  • Is the PR limited to one linear task?
  • Are relevant unit and component test-cases added in new readability format? (11 test cases enabled)

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?
  • Verified that there are no credentials or confidential data exposed with the changes.

Files Changed Summary

1. src/v1/destinations/am/networkHandler.ts (New File - 107 lines)

Purpose: Implements v1 transformerProxy network handler for Amplitude

Key Components:

  • populateResponseWithDontBatch(): Creates individual error responses for batch processing failures
  • responseHandler(): Main response handler with comprehensive error classification
    • Success handling (200)
    • Retryable error handling (5xx, specific 429 cases)
    • Throttled error handling (429 with circuit breaker logic)
    • Batch failure handling (multiple events with partial failure)
    • Aborted error handling (4xx permanent failures)
  • networkHandler(): Binds proxy functions to handler context

Error Handling Logic:

// Success: Map each metadata to 200 response
if (isHttpStatusSuccess(status)) → Return 200 for each event

// Retryable: Throw RetryableError for infrastructure failures
if (isHttpStatusRetryable(status)) → Throw RetryableError (500)

// Throttled: Special Amplitude throttling logic
if (isHttpStatusThrottled(status)) {
  if (throttled_users || throttled_devices present) → Throw RetryableError (500)
  else → Throw ThrottledError (circuit breaker)
}

// Batch Failure: Return individual responses with dontBatch flag
if (batch with failure) → Return dontBatch: true for each event

// Aborted: Permanent failure
else → Throw AbortedError (400)

2. test/integrations/destinations/am/dataDelivery/data.ts (+11 lines)

Purpose: Enable comprehensive proxy v1 test cases

Changes: Changed skip: true to skip: false for 11 test cases covering:

  1. ✅ Success with 200 response
  2. ✅ Aborted with 400 invalid API key
  3. ✅ Retryable with 500 internal error
  4. ✅ Success with 200 for single event
  5. ✅ Success with dontBatch false in metadata
  6. ✅ Batch with throttled users (retryable)
  7. ✅ Batch with throttled devices (retryable)
  8. ✅ Throttled with 429 (circuit breaker)
  9. ✅ Retryable with 503 service unavailable
  10. ✅ Aborted with 413 payload too large
  11. ✅ Success for group event

Test Coverage: Success scenarios, error handling, throttling, batching, single/multiple events


Impact Analysis

What Works Now (That Didn't Before):

  1. ✅ V1 proxy delivery for Amplitude events
  2. ✅ Batch event processing through proxy
  3. ✅ Intelligent retry logic based on error type
  4. ✅ Amplitude-specific throttle handling
  5. ✅ Partial failure handling for batches

Backward Compatibility:

  • ✅ No changes to v0 transformation logic
  • ✅ Existing Amplitude integrations unaffected
  • ✅ New functionality is opt-in (v1 route)

Risk Assessment: LOW

  • Isolated changes to the new v1 destination directory
  • Follows established patterns from other v1 destinations
  • Comprehensive test coverage
  • No modifications to existing code paths

@ItsSudip
ItsSudip requested a review from a team as a code owner October 8, 2025 08:56
@ItsSudip
ItsSudip requested review from koladilip and vinayteki95 and removed request for a team October 8, 2025 08:56
@coderabbitai

coderabbitai Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/amTransformerProxy

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Oct 8, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.81%. Comparing base (e86f2cf) to head (6f62bca).
⚠️ Report is 1 commits behind head on chore/amProxyTestCases.

Additional details and impacted files
@@                    Coverage Diff                     @@
##           chore/amProxyTestCases    #4703      +/-   ##
==========================================================
- Coverage                   91.90%   91.81%   -0.09%     
==========================================================
  Files                         650      651       +1     
  Lines                       34486    34529      +43     
  Branches                     8098     8107       +9     
==========================================================
+ Hits                        31694    31703       +9     
- Misses                       2543     2574      +31     
- Partials                      249      252       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

throw new ThrottledError(
`Request Failed during ${DESTINATION} response transformation: ${error} - due to Request Limit exceeded, (Throttled)`,
destinationResponse,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why do we need two different retryable errors?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we get this answered?

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@vinayteki95

Copy link
Copy Markdown
Contributor

@ItsSudip Can you add PR description detailing the changes?

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@ItsSudip
ItsSudip merged commit dcdc81c into chore/amProxyTestCases Oct 14, 2025
@ItsSudip
ItsSudip deleted the feat/amTransformerProxy branch October 14, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants