-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Prep work for adding Mixpanel session recording #36895
Conversation
WalkthroughThe changes in this pull request involve updates to various files to enhance logging and analytics capabilities, particularly focusing on Mixpanel integration. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
|
APPSMITH_FEATURE_CONFIGS?.enableMixpanel || | ||
false, | ||
mixpanel: { | ||
enabled: segment.enabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentionally using segment enabled because that is how it was working before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
app/client/src/ce/configs/types.ts (1)
Line range hint
1-89
: Let's tidy up our code classroom, shall we?While the Mixpanel changes are good, I've noticed a few areas where we could improve our overall code structure:
Consistency is key: Some configuration objects have an
enabled
property, while others don't. Let's aim for consistency across all our configurations.Breaking down a big task: Our
AppsmithUIConfigs
interface is quite large. Consider splitting it into smaller, more focused interfaces. This is like dividing a big project into manageable homework assignments.Grouping related items: We could group related configurations together. For example, all analytics-related configs (Mixpanel, Segment, etc.) could be in one sub-interface.
Remember, clean code is like a well-organized backpack - it makes everything easier to find and use!
Would you like some examples of how we could refactor this interface for better organization?
app/client/src/ce/utils/AnalyticsUtil.tsx (1)
Line range hint
17-24
: Excellent work extending the 'Window' interface, but let's refine it furtherExtending the
Window
interface to include thezipy
object is thoughtfully implemented. However, it's advisable to place global interface augmentations in a separate.d.ts
declaration file. This approach keeps the codebase organized and minimizes potential conflicts within the global namespace.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
app/client/yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (6)
- app/client/jest.config.js (2 hunks)
- app/client/package.json (2 hunks)
- app/client/public/index.html (1 hunks)
- app/client/src/ce/configs/index.ts (4 hunks)
- app/client/src/ce/configs/types.ts (1 hunks)
- app/client/src/ce/utils/AnalyticsUtil.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (10)
app/client/src/ce/configs/types.ts (2)
50-53
: Class, pay attention to this excellent configuration update!Well done on restructuring the Mixpanel configuration! This change from a simple boolean to an object with
enabled
andapiKey
properties is a step in the right direction. It's like upgrading from a simple on/off switch to a more sophisticated control panel.Let's break down why this is beneficial:
- It provides more flexibility in configuring Mixpanel.
- It aligns well with other configuration objects in the interface.
- It supports the PR objective of integrating Mixpanel for session recording.
Remember, students, good code structure is like a well-organized classroom - everything has its place and purpose!
50-53
: Time for a pop quiz on our codebase!Now that we've updated our Mixpanel configuration, we need to make sure the rest of our code is on the same page. Let's do a quick search to find any lingering references to the old
enableMixpanel
property.Here's a little homework assignment for our codebase:
This script will help us find any places where we might need to update our code to use the new
mixpanel
object. Remember, thorough testing is like double-checking your homework - it helps catch any mistakes before they become problems!✅ Verification successful
Let's tackle these hiccups together! It looks like our previous search script ran into some roadblocks. No worries—we'll adjust our approach to get things back on track.
This updated script removes the problematic
--type
flags and adjusts the regex to ensure proper parsing. Let's give it another go and see what we uncover!
Verification Successful: 'enableMixpanel' Removed
Great news! All instances of
enableMixpanel
have been successfully removed from the codebase. The newmixpanel
configuration is properly implemented in the following files:
app/client/jest.config.js
app/client/public/index.html
app/client/src/ce/configs/index.ts
app/client/src/ce/configs/types.ts
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining uses of 'enableMixpanel' echo "Searching for 'enableMixpanel' in the codebase:" rg --type typescript --type javascript 'enableMixpanel' echo "\nSearching for uses of the new 'mixpanel' object:" rg --type typescript --type javascript 'mixpanel\s*:\s*{'Length of output: 474
Script:
#!/bin/bash # Description: Check for any remaining uses of 'enableMixpanel' without specifying file types echo "Searching for 'enableMixpanel' in the codebase:" rg 'enableMixpanel' echo "\nSearching for uses of the new 'mixpanel' object:" rg 'mixpanel\s*:\s*\{'Length of output: 565
app/client/jest.config.js (3)
4-6
: Class, let's examine these new constants.Good morning, students! Today, we're going to learn about two new constants that have been added to our Jest configuration:
LOG_LEVELS
: This is an array that defines our logging levels. It's like a set of rules for how detailed our error messages should be.CONFIG_LOG_LEVEL_INDEX
: This is set to 1, which means we're choosing the "error" level from ourLOG_LEVELS
array.These constants will help us manage how our tests report issues. It's a great way to keep our test output organized and consistent. Well done!
105-108
: Let's discuss the changes to our Mixpanel configuration, class.Attention, everyone! We've made some exciting updates to our Mixpanel setup. Instead of a simple on/off switch, we now have a more sophisticated configuration:
enabled
: This tells us whether Mixpanel is turned on or off, just like before.apiKey
: This is a new addition! It's like a special password that lets our application talk to Mixpanel.This change is very important because it allows us to use Mixpanel's features, like session recording, which we'll be learning about soon. It's a big step forward in understanding how people use our application!
Line range hint
109-112
: Now, let's examine how we're setting our log level.Class, pay attention to this clever bit of code! We're using what we call a "ternary operator" to decide which log level to use. Here's how it works:
- First, we check if our
CONFIG_LOG_LEVEL_INDEX
is a valid number (greater than -1).- If it is, we use that to pick a log level from our
LOG_LEVELS
array.- If it's not valid, we default to the second item in the array, which is "error".
This is a very smart way to set our log level because it's flexible and helps prevent errors. Great job on making our code more robust!
app/client/src/ce/configs/index.ts (1)
29-32
: Class, let's examine this new addition to our configuration!I'm pleased to see this well-structured
mixpanel
object in ourINJECTED_CONFIGS
interface. It's like adding a new chapter to our configuration book, isn't it? This change allows us to not only enable or disable Mixpanel but also to specify its API key. It's a more comprehensive approach to managing our analytics tools.Remember, students, when we enhance our interfaces like this, we're making our code more flexible and easier to manage in the future. Good job!
app/client/public/index.html (1)
246-249
:⚠️ Potential issueClass, let's examine this new configuration carefully.
I see you've added a new
mixpanel
object to our configuration. That's a good step towards organizing our analytics setup. However, I have a question about line 247:enabled: parseConfig('{{env "APPSMITH_SEGMENT_KEY"}}'),It appears you're using the Segment key to enable Mixpanel. Is this intentional? Typically, we'd expect a boolean value or a Mixpanel-specific environment variable here. Let's discuss this in class:
- Should this be
APPSMITH_MIXPANEL_ENABLED
instead?- If we're using the Segment key, can you explain the reasoning behind this choice?
Remember, clear and accurate configurations are crucial for our application's behavior. Let's ensure we're setting this up correctly.
To double-check our configuration, let's run a quick test:
This will help us understand how the Mixpanel configuration is used throughout our codebase and if there are any other Mixpanel-related environment variables we should consider.
app/client/package.json (1)
159-159
: Excellent additions, class! Let's discuss why these are important.Children, we've added two new packages to our project today:
- "mixpanel-browser": "^2.55.1"
- "@types/mixpanel-browser": "^2.50.1"
Can anyone tell me why these are significant? That's right! The first one allows us to use Mixpanel for session recording, which will help us understand how users interact with our application. The second one, class, is a TypeScript definition file. Who can tell me why that's important? Correct! It helps us maintain type safety in our TypeScript code.
Remember, using the caret (^) before the version number is like giving our package manager permission to update to newer, compatible versions. It's like when I give you permission to use colored pencils instead of regular ones - you can use them, but they still have to write words!
Also applies to: 265-265
app/client/src/ce/utils/AnalyticsUtil.tsx (2)
74-76
: Well done adding the 'initializeSmartLook' methodYou've correctly implemented the
initializeSmartLook
method, which initializes the Smartlook client with the provided ID. This enhances our analytics capabilities effectively.
369-371
: Good job introducing the 'setBlockErrorLogs' methodThe
setBlockErrorLogs
method effectively controls error logging behavior within theAnalyticsUtil
class. This addition allows for better management of error events in our analytics.
mixpanel: { | ||
enabled: process.env.REACT_APP_SEGMENT_KEY | ||
? process.env.REACT_APP_SEGMENT_KEY.length > 0 | ||
: false, | ||
apiKey: process.env.REACT_APP_MIXPANEL_KEY || "", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention, class! We have an interesting configuration setup here.
While I appreciate the effort to include Mixpanel in our configuration, I have a concern about our implementation. Can anyone spot the potential issue?
Let's break it down:
- We're setting
enabled
based onREACT_APP_SEGMENT_KEY
. - We're getting the
apiKey
fromREACT_APP_MIXPANEL_KEY
.
Do you see the mismatch? We're using Segment's key to enable Mixpanel. This could lead to confusion or unexpected behavior.
Here's a homework assignment for you: How could we improve this to make it more logical and less prone to errors? Think about using a dedicated environment variable for enabling Mixpanel.
Would you like to discuss a more appropriate implementation for enabling Mixpanel?
const mixpanel = getConfig( | ||
ENV_CONFIG.mixpanel.apiKey, | ||
APPSMITH_FEATURE_CONFIGS?.mixpanel.apiKey, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class, let's examine how we're configuring Mixpanel in our getAppsmithConfigs function.
I see some room for improvement here. Let's analyze it together:
- We're correctly retrieving the Mixpanel API key (lines 170-173). Good job on that!
- However, in our final configuration (lines 291-294), we're setting
enabled
based onsegment.enabled
. Can anyone tell me why this might not be ideal?
Remember, Mixpanel and Segment are different analytics tools. By tying Mixpanel's enablement to Segment, we might be creating a dependency that doesn't necessarily exist.
Also, notice that we're not using the enabled
property we set earlier in getConfigsFromEnvVars
. We're missing an opportunity to make our configuration more flexible and accurate.
For your next assignment, I want you to think about how we can make this configuration more independent and aligned with our earlier setup. How can we ensure that Mixpanel's configuration stands on its own?
Shall we discuss a more appropriate implementation for configuring Mixpanel in this function?
Also applies to: 291-294
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Update the Appsmith config to allow for mixpanel api key that will be used for session recording
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/11360469261
Commit: bede558
Cypress dashboard.
Tags:
@tag.Sanity
Spec:
Wed, 16 Oct 2024 07:52:26 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores