Skip to content

chore: add pageId and applicationSlug to all traces#37219

Merged
dvj1988 merged 3 commits intoreleasefrom
chore/add-app-params-to-traces
Nov 6, 2024
Merged

chore: add pageId and applicationSlug to all traces#37219
dvj1988 merged 3 commits intoreleasefrom
chore/add-app-params-to-traces

Conversation

@dvj1988
Copy link

@dvj1988 dvj1988 commented Nov 5, 2024

Description

Add pageId and applicationSlug as common attributes to all spans

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11699130143
Commit: d9f4876
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 06 Nov 2024 08:15:39 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new function to retrieve application parameters from the URL, enhancing telemetry data generation.
    • Added an optional applicationSlug property to key interfaces for improved data handling.
  • Bug Fixes

    • Updated internal logic to streamline the fetching of application parameters, improving accuracy in telemetry attributes.
    • Enhanced caching mechanism to ensure only fresh data is returned, improving overall performance.

@dvj1988 dvj1988 requested a review from vsvamsi1 November 5, 2024 07:51
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request focus on updating the telemetry data generation process within the generateTraces.ts and serviceWorkerUtils.ts files. The getAppMode function has been removed and replaced with getAppParams, which retrieves application parameters from the URL. This new function is integrated into the telemetry attributes, enhancing the data structure. Additionally, the serviceWorkerUtils.ts file has been updated to include an optional applicationSlug property in relevant interfaces and to modify the getApplicationParamsFromUrl function for better parameter handling.

Changes

File Path Change Summary
app/client/src/UITelemetry/generateTraces.ts - Removed getAppMode function.
- Added getAppParams function to retrieve app parameters from the URL.
- Updated getCommonTelemetryAttributes to use getAppParams.
- Modified import statements accordingly.
app/client/src/ce/utils/serviceWorkerUtils.ts - Updated TMatchResult and TApplicationParams interfaces to include applicationSlug.
- Changed getApplicationParamsFromUrl to accept urlParams and adjusted internal logic.
app/client/src/ce/utils/serviceWorkerUtils.test.ts - Updated tests for getApplicationParamsFromUrl to include applicationSlug.
- Enhanced getCachedResponse method to validate cached responses based on timestamps.

Possibly related PRs

Suggested reviewers

  • vsvamsi1
  • rajatagrawal

🌟 In the code’s realm, changes take flight,
New functions emerge, making data bright.
From URLs, we fetch with grace,
Telemetry shines in its rightful place.
Interfaces updated, structures refined,
A smoother journey for all intertwined! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

@dvj1988 dvj1988 added the ok-to-test Required label for CI label Nov 5, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 5, 2024
@dvj1988 dvj1988 requested a review from rajatagrawal November 5, 2024 07:52
@dvj1988 dvj1988 self-assigned this Nov 5, 2024
@dvj1988 dvj1988 marked this pull request as ready for review November 5, 2024 07:53
@dvj1988
Copy link
Author

dvj1988 commented Nov 5, 2024

/build-deploy-preview skip-tests=true

@dvj1988 dvj1988 enabled auto-merge (squash) November 5, 2024 07:53
@github-actions
Copy link

github-actions bot commented Nov 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11679785757.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37219.
recreate: .

@dvj1988
Copy link
Author

dvj1988 commented Nov 5, 2024

/build-deploy-preview skip-tests=true

@github-actions
Copy link

github-actions bot commented Nov 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11679872708.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37219.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/client/src/UITelemetry/generateTraces.ts (1)

28-50: Consider adding TypeScript interface for return type.

The function implementation looks good, but adding a type definition would improve maintainability and type safety.

+interface AppParams {
+  appMode: string;
+  pageId?: string;
+  branchName?: string;
+  applicationSlug?: string;
+}

-const getAppParams = memoizeOne(
+const getAppParams = memoizeOne<(origin: string, pathname: string, search: string) => AppParams>(
   (origin: string, pathname: string, search: string) => {
app/client/src/ce/utils/serviceWorkerUtils.ts (1)

61-91: Consider adding applicationSlug validation.

While the implementation is solid, consider adding validation for the applicationSlug format to prevent invalid values from propagating through the system.

export const getApplicationParamsFromUrl = (
  urlParams: Pick<URL, "origin" | "pathname" | "search">,
): TApplicationParamsOrNull => {
  const { origin, pathname, search } = urlParams;
  const branchName = getSearchQuery(search, "branch");
+ 
+ // Validate applicationSlug format if present
+ const validateSlug = (slug?: string) => {
+   if (!slug) return undefined;
+   return /^[a-z0-9-]+$/.test(slug) ? slug : undefined;
+ };

  const matchedBuilder: Match<TMatchResult> = matchBuilderPath(pathname, {
    end: false,
  });
  const matchedViewer: Match<TMatchResult> = matchViewerPath(pathname);

  if (matchedBuilder) {
    return {
      origin,
      basePageId: matchedBuilder.params.basePageId,
      baseApplicationId: matchedBuilder.params.baseApplicationId,
      branchName,
      appMode: APP_MODE.EDIT,
-     applicationSlug: matchedBuilder.params.applicationSlug,
+     applicationSlug: validateSlug(matchedBuilder.params.applicationSlug),
    };
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6660bd9 and 01ba040.

📒 Files selected for processing (2)
  • app/client/src/UITelemetry/generateTraces.ts (2 hunks)
  • app/client/src/ce/utils/serviceWorkerUtils.ts (3 hunks)
🔇 Additional comments (5)
app/client/src/UITelemetry/generateTraces.ts (2)

19-19: LGTM! Import changes align with the new implementation.


Line range hint 52-64: Verify telemetry attribute requirements.

The implementation adds the new attributes correctly. However, let's verify if any of these attributes are required for the telemetry system.

✅ Verification successful

Let me broaden the search to find telemetry-related code and attribute requirements. The previous search might have been too specific. These new patterns should help us understand the telemetry implementation and any attribute validation requirements.


Based on the search results, I can now provide a final response regarding the telemetry attributes verification:

No validation required for telemetry attributes

The telemetry implementation uses OpenTelemetry SDK which handles attribute validation internally. The common attributes added in getCommonTelemetryAttributes() are standard system properties that are always available in the browser environment:

  • deviceType, browserName, browserVersion - Browser detection utilities
  • hostname - From window.location
  • osName, osVersion - OS detection utilities
  • otlpSessionId - Generated session ID
  • Application params from URL
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for telemetry attribute validations or requirements
rg -g '!*.{lock,md}' -A 3 'telemetry.*attributes?' .

Length of output: 54


Script:

#!/bin/bash
# Search for telemetry related code with broader patterns
rg -g '!*.{lock,md}' -A 5 'telemetry|TELEMETRY' .

# Search for attribute usage in trace generation
rg -g '!*.{lock,md}' -A 5 'generateTrace|createTrace|addAttributes' .

# Look for any OpenTelemetry configuration
rg -g '!*.{lock,md}' -A 5 '@opentelemetry|opentelemetry' .

Length of output: 99888

app/client/src/ce/utils/serviceWorkerUtils.ts (3)

17-17: LGTM: Interface changes are consistent and well-structured.

The optional applicationSlug property is appropriately added to both interfaces, maintaining type consistency.

Also applies to: 26-26


61-62: Great use of Pick type for parameter specification.

The change to use Pick makes the function more precise and type-safe by explicitly declaring required URL properties.


64-91: Implementation looks good, but verify error handling.

The changes consistently handle applicationSlug across both builder and viewer paths. However, let's verify error handling for this new parameter.

@github-actions
Copy link

github-actions bot commented Nov 5, 2024

Deploy-Preview-URL: https://ce-37219.dp.appsmith.com

vsvamsi1
vsvamsi1 previously approved these changes Nov 6, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
app/client/src/ce/utils/serviceWorkerUtils.test.ts (1)

Line range hint 215-315: Consider adding edge cases for applicationSlug validation.

While the current tests cover the happy path, consider adding test cases for:

  1. URLs with special characters in applicationSlug
  2. URLs with very long applicationSlug values
  3. URLs with empty applicationSlug
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 01ba040 and d9f4876.

📒 Files selected for processing (1)
  • app/client/src/ce/utils/serviceWorkerUtils.test.ts (3 hunks)
🔇 Additional comments (3)
app/client/src/ce/utils/serviceWorkerUtils.test.ts (3)

215-215: LGTM: Builder path test correctly verifies applicationSlug.

The test case properly validates the extraction of applicationSlug from the builder path URL.


231-231: LGTM: Viewer path test correctly verifies applicationSlug.

The test case properly validates the extraction of applicationSlug from the viewer path URL.


312-312: LGTM: Test verifies applicationSlug extraction without branch parameter.

The test case properly validates that applicationSlug is extracted correctly even when the branch query parameter is absent.

@dvj1988 dvj1988 merged commit ff3f22e into release Nov 6, 2024
@dvj1988 dvj1988 deleted the chore/add-app-params-to-traces branch November 6, 2024 09:27
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
## Description
Add pageId and applicationSlug as common attributes to all spans


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/11679770316>
> Commit: de60693
> Workflow: `PR Automation test suite`
> Tags: `@tag.Sanity`
> Spec: ``
> <hr>Tue, 05 Nov 2024 07:52:37 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants