Skip to content

fix: add uuid as fallback to missing anonymousId in webhook events - #4276

Merged
yashasvibajpai merged 1 commit into
developfrom
fix.fallback.uuid.to.shopify.anonid
May 19, 2025
Merged

yashasvibajpai merged 1 commit into
developfrom
fix.fallback.uuid.to.shopify.anonid

Conversation

@yashasvibajpai

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

This pull request introduces a new utility function, ensureAnonymousId, to guarantee that every message has an anonymousId, using a UUID as a fallback if one is not present. The changes also include corresponding updates to the codebase and unit tests to integrate and validate this functionality.

New Functionality: ensureAnonymousId

  • Definition and Implementation:

    • Added the ensureAnonymousId function in serverSideUtlis.js. This function checks if a message has an anonymousId and generates a random UUID if it is missing. It also logs the event using the stats.increment method.
    • Exported ensureAnonymousId in the module.exports object of serverSideUtlis.js.
  • Integration in Event Processing:

    • Updated the processEvent function in serverSideTransform.js to call ensureAnonymousId after setting the anonymousId using setAnonymousId. This ensures a fallback mechanism for anonymousId.

Testing Enhancements

  • Unit Tests for ensureAnonymousId:
    • Added a new test suite in serverSideUtils.test.js to validate the behavior of ensureAnonymousId. Tests include scenarios where anonymousId already exists and where it needs to be generated.

Dependency Updates

  • UUID Library:
    • Imported the uuidv4 function from the uuid library in serverSideUtlis.js to generate random UUIDs for anonymousId.

Codebase Updates

  • Imports:
    • Added ensureAnonymousId to the list of imported functions in both serverSideTransform.js and serverSideUtils.test.js. [1] [2]

What is the related Linear task?

Resolves INT-3553

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

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

N/A

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?

N/A

@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?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

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.

@yashasvibajpai yashasvibajpai self-assigned this Apr 23, 2025
@yashasvibajpai
yashasvibajpai requested a review from a team April 23, 2025 22:07
@coderabbitai

coderabbitai Bot commented Apr 23, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Improved reliability by ensuring every event message now always includes an anonymous ID, even if one was not originally present.
  • Tests

    • Added tests to verify that anonymous IDs are correctly generated and tracked when missing from event messages.

Walkthrough

The changes introduce a new utility function, ensureAnonymousId, to guarantee that the message object always contains an anonymousId. This function is integrated into the Shopify server-side event processing flow, ensuring that if an anonymousId is missing after the initial assignment, a random UUID is generated and assigned. The function also increments a specific metric to track such fallback events. Corresponding tests have been added to verify this behavior, including metric reporting and correct assignment of the anonymousId. No existing function signatures or exports were altered, aside from the addition of the new utility.

Changes

File(s) Change Summary
src/sources/shopify/webhookTransformations/serverSideUtlis.js Added ensureAnonymousId utility function, imported uuidv4, and updated exports.
src/sources/shopify/webhookTransformations/serverSideTransform.js Imported and integrated ensureAnonymousId into processEvent to ensure anonymousId is always set.
src/sources/shopify/webhookTransformations/serverSideUtils.test.js Added tests for ensureAnonymousId, verifying correct behavior and metric incrementing.

Sequence Diagram(s)

sequenceDiagram
    participant ShopifyWebhook as Shopify Webhook
    participant ServerSideTransform as processEvent
    participant ServerSideUtils as setAnonymousId / ensureAnonymousId
    participant Metrics as stats.increment

    ShopifyWebhook->>ServerSideTransform: Receive event
    ServerSideTransform->>ServerSideUtils: setAnonymousId(message)
    ServerSideUtils-->>ServerSideTransform: message (may have anonymousId)
    ServerSideTransform->>ServerSideUtils: ensureAnonymousId(message, metadata)
    alt anonymousId missing
        ServerSideUtils->>ServerSideUtils: Generate UUID
        ServerSideUtils->>Metrics: Increment shopify_pixel_id_stitch_gaps
    end
    ServerSideUtils-->>ServerSideTransform: message (with anonymousId)
    ServerSideTransform->>NextStep: Continue processing with guaranteed anonymousId
Loading

Suggestions for Improvement:

  • Consider documenting the new metric in your monitoring dashboard to ensure stakeholders are aware of the fallback mechanism.
  • If anonymousId assignment is critical for downstream analytics, review the upstream logic in setAnonymousId for potential improvements or additional edge-case handling.
  • Add integration tests to validate the end-to-end flow, ensuring that the fallback assignment works as expected in production-like scenarios.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 40f4ee7 and 2e744e7.

📒 Files selected for processing (3)
  • src/sources/shopify/webhookTransformations/serverSideTransform.js (2 hunks)
  • src/sources/shopify/webhookTransformations/serverSideUtils.test.js (2 hunks)
  • src/sources/shopify/webhookTransformations/serverSideUtlis.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

  • src/sources/shopify/webhookTransformations/serverSideTransform.js
  • src/sources/shopify/webhookTransformations/serverSideUtlis.js
  • src/sources/shopify/webhookTransformations/serverSideUtils.test.js
🧬 Code Graph Analysis (1)
src/sources/shopify/webhookTransformations/serverSideUtlis.js (4)
src/sources/shopify/webhookTransformations/serverSideTransform.js (12)
  • require (3-3)
  • require (5-5)
  • require (6-6)
  • require (8-8)
  • require (9-9)
  • require (10-15)
  • require (16-16)
  • require (17-24)
  • require (25-25)
  • require (26-26)
  • metricMetadata (186-189)
  • stats (4-4)
src/sources/shopify/webhookTransformations/serverSideUtils.test.js (5)
  • require (1-1)
  • require (2-10)
  • require (14-14)
  • require (16-16)
  • stats (12-12)
src/sources/shopify/tracker/util.js (1)
  • stats (6-6)
src/sources/shopify/utils.js (1)
  • stats (2-2)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • 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: 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: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (7)
src/sources/shopify/webhookTransformations/serverSideUtlis.js (3)

4-4: Good addition of uuid dependency.

The addition of the uuid library for generating unique identifiers is a solid choice. It's a well-established library with reliable implementation of UUID generation.


168-185: Well-designed fallback mechanism for anonymousId.

The ensureAnonymousId function provides a robust fallback mechanism to guarantee that all messages have an anonymousId. The implementation correctly:

  1. Checks if anonymousId is missing
  2. Assigns a UUID v4 when needed
  3. Tracks the fallback occurrence with appropriate metrics
  4. Returns the potentially modified message

The function is well-documented with clear JSDoc comments explaining its purpose and parameters.


195-195: Appropriate export of the new utility function.

The new function is correctly added to the module exports, making it available for use in other modules.

src/sources/shopify/webhookTransformations/serverSideTransform.js (2)

23-23: Clean import of the new utility function.

The new ensureAnonymousId function is properly imported from the serverSideUtlis module.


151-153: Effective integration of fallback anonymousId mechanism.

The new function is well-integrated into the event processing flow:

  1. It's called after setAnonymousId, which follows the correct sequence (try standard methods first, then use fallback)
  2. The code includes a helpful comment explaining the purpose
  3. The function call correctly passes both the message and required metadata
  4. The result is properly reassigned to the message variable for continued processing

This ensures that downstream code will always have an anonymousId available, improving robustness.

src/sources/shopify/webhookTransformations/serverSideUtils.test.js (2)

9-9: Proper import of the function for testing.

The new ensureAnonymousId function is correctly imported for testing.


182-208: Comprehensive test coverage for the new function.

The tests for ensureAnonymousId are well-structured and thorough:

  1. The first test verifies that an existing anonymousId is preserved and no metrics are incremented
  2. The second test ensures that:
    • A missing anonymousId is properly generated
    • The generated ID is a string
    • The correct metrics are incremented with appropriate metadata

This complete test coverage ensures the function behaves as expected in all scenarios.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Apr 23, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.21%. Comparing base (79cebfc) to head (2e744e7).
Report is 53 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4276   +/-   ##
========================================
  Coverage    91.21%   91.21%           
========================================
  Files          632      632           
  Lines        33053    33060    +7     
  Branches      7827     7825    -2     
========================================
+ Hits         30150    30157    +7     
- Misses        2658     2688   +30     
+ Partials       245      215   -30     

☔ 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.

@sonarqubecloud

Copy link
Copy Markdown

@yashasvibajpai
yashasvibajpai merged commit f6bbbf0 into develop May 19, 2025
@yashasvibajpai
yashasvibajpai deleted the fix.fallback.uuid.to.shopify.anonid branch May 19, 2025 09:22
ItsSudip added a commit that referenced this pull request May 27, 2025
* feat: update destination type with optional account types (#4291)

* feat: update destination type with optional account types

* chore: add authenticationType

* chore: update types with generics

* chore: add optional config to accountDefiition

* chore: update deleteAccount to regulationAccount

* chore: update regulationAccount to deleteAccount

* chore(destination): migrate slack destination tests to new format (#4279)

* chore(destination): migrate slack destination tests to new format

* refactor: tests to use proper types

* chore: fix status in mailchimp, fix cognitive complexity, add unit tests (#4314)

* chore: fix status in mailchimp, fix cognitive complexity, add unit tests

* chore: fix PR comments for mailchimp tests

* test: add tests for error cases to improve code coverage

---------

Co-authored-by: Dilip Kola <[email protected]>

* chore(braze): added docs for braze destination (#4297)

* chore(braze): added docs for braze destination

* chore: update braze docs

* chore: add multiplexing section

---------

Co-authored-by: Utsab Chowdhury <[email protected]>

* chore: add string check for phone in gaoc (#4311)

* chore: add string check for phone in gaoc

* chore: add unit test

* chore: update condition

Co-authored-by: Sudip Paul <[email protected]>

---------

Co-authored-by: Sudip Paul <[email protected]>

* chore: correct dotenv import (#4320)

* chore: payload size middleware performance improvement (#4318)

* fix: add uuid as fallback to missing anonymousId in webhook events (#4276)

* chore: bump codecov/codecov-action from 5.4.2 to 5.4.3 (#4335)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.2 to 5.4.3.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v5.4.2...v5.4.3)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: 5.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: bump slackapi/slack-github-action from 1.27.0 to 2.1.0 (#4312)

Bumps [slackapi/slack-github-action](https://github.com/slackapi/slack-github-action) from 1.27.0 to 2.1.0.
- [Release notes](https://github.com/slackapi/slack-github-action/releases)
- [Commits](slackapi/slack-github-action@v1.27.0...v2.1.0)

---
updated-dependencies:
- dependency-name: slackapi/slack-github-action
  dependency-version: 2.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: mp add content type header to all apis (#4344)

* fix: mp add content-type header and follow strict for engage and group apis

* chore: mp add content type header to all apis

* feat: bluecore email subscription event (#4304)

* fix: blucore optin event mapping

* fix: review comments

* chore: add subscription event

* chore: add subscription event

* fix: reviews comments

* fix: review comments

* fix: review comments

* fix: review comments

* chore: test description

* chore(release): 1.101.0

* chore: pass copy of metadata to avoid actual metadata modifications (#4351)

* Revert "feat: update destination type with optional account types (#4291)" (#4348)

This reverts commit f368f00.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: Yashasvi Bajpai <[email protected]>
Co-authored-by: Dilip Kola <[email protected]>
Co-authored-by: Dilip Kola <[email protected]>
Co-authored-by: Vinay Teki <[email protected]>
Co-authored-by: Utsab Chowdhury <[email protected]>
Co-authored-by: Aris Tzoumas <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mahesh Kutty <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Jayachand Mopidevi <[email protected]>
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.

4 participants