Skip to content
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

refactor: make console logs and network performance buttons toggled ON by default #23900

Merged

Conversation

namit-chandwani
Copy link
Contributor

Linked Issues

Problem

  • Activating session recording should automatically turn on console logs and network performance monitoring.
  • To reflect this, the buttons for these features should be enabled and grayed out by default, indicating they are active and cannot be manually turned off until the session recording button is enabled.
  • This configuration ensures that users receive the full suite of features without any additional steps.
  • When session recording is toggled, only that specific setting changes, while the other related features remain active and ready for use.

Changes

  • Backend (models/team.py):

    • Added default=True to capture_console_log_opt_in and capture_performance_opt_in fields in the Team model.
    • This change ensures that these fields default to True when a new team instance is created.
    • Retained null=True and blank=True for both fields to ensure backward compatibility, preventing potential issues with older data containing empty or null values.
    • These changes ensure that these fields default to True when a new team instance is created, while maintaining compatibility with existing data.
  • Frontend (SessionRecordingSettings.tsx):

    • Updated the checked attribute logic for capture_console_log_opt_in and capture_performance_opt_in settings:
      • Changed from using currentTeam?.session_recording_opt_in ? !!currentTeam?.capture_console_log_opt_in : false to !!currentTeam?.capture_console_log_opt_in.
      • This ensures the checkbox states are directly tied to the respective capture_console_log_opt_in and capture_performance_opt_in fields without depending on session_recording_opt_in.
    • Removed the redundant check for session_recording_opt_in when determining the default state of capture_console_log_opt_in and capture_performance_opt_in checkboxes.

These changes improve the consistency and reliability of the log and performance capture settings by making their defaults explicit and simplifying the logic for determining their states, while ensuring backward compatibility with existing data.

Does this work well for both Cloud and self-hosted?

  • Yes, will work well for both Cloud and self-hosted Posthog instances.

How did you test this code?

  • Backend Testing:

    • Database Migration:
      • Applied and tested the database migration to confirm that the schema changes did not introduce any issues with existing data.
      • Manually inspected the database to ensure that older records with null or empty values for capture_console_log_opt_in and capture_performance_opt_in remain unaffected.
  • Frontend Testing:

    • Manual Testing:
      • Tested the user interface manually to ensure that the checkboxes for capture_console_log_opt_in and capture_performance_opt_in reflect the correct state based on the updated logic.
      • Verified that enabling and disabling these settings works as expected, both when session_recording_opt_in is enabled and disabled.
      • Checked that the "session recording must be enabled" message appears appropriately when needed.
  • Screen Recording of Testing:

    Feature.testing.recording.6.mp4

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (altering code without changing its external behaviour)
  • Documentation change
  • Other

Checklist:

  • Development completed
  • Comments added to code (wherever necessary)
  • Documentation updated (if applicable)
  • Added tests [Unit tests/Integration tests] (if required)
  • Tested changes locally

Follow-up tasks (if any):

  • None

Additional Comments

  • None

@pauldambra
Copy link
Member

hey @namit-chandwani

i'm actually torn on whether we should default these to true 🙈 am going to tag @daibhin to get his opinion too

I think you'll need to add a migration for this

something like DEBUG=1 python manage.py makemigrations posthog --name change_replay_team_setting_defaults

@daibhin
Copy link
Contributor

daibhin commented Jul 23, 2024

Feels like the right call to me.

The other option I guess would be to hide the settings until you've enabled Replay but I think that would hurt discovery of how powerful Replay is (console logs and network performance being some of the most powerful).

It would be great if we could also update the copy of the session recording must be enabled tooltip. Maybe Session replay must be enabled

@namit-chandwani
Copy link
Contributor Author

Thanks for the timely review @pauldambra and @daibhin!
I've now pushed the suggested changes through commits: 8905e9f and 8905e9f

Request you to have a look. TIA

@namit-chandwani namit-chandwani force-pushed the refactor/session-replay-toggles branch from 5b73d72 to adfe554 Compare July 24, 2024 10:31
@namit-chandwani
Copy link
Contributor Author

Will resolve the test cases failing in the workflow shortly

@namit-chandwani
Copy link
Contributor Author

@pauldambra @daibhin I've fixed all the failing backend test cases now. Seems like we're good to go

migrations.AlterField(
model_name="team",
name="capture_console_log_opt_in",
field=models.BooleanField(blank=True, default=True, null=True),
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this change affects existing rows... so I don't think we have any reason to worry about table locks here

@pauldambra
Copy link
Member

@daibhin are you ok to help get this over the line?

@namit-chandwani
Copy link
Contributor Author

Hey @daibhin, I’ve made the changes to the unit test as suggested in the review comment: #23900 (comment) now.

Please review the changes at your convenience and let me know if there are any further adjustments required.

Thanks!

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.

@namit-chandwani namit-chandwani force-pushed the refactor/session-replay-toggles branch from ee6fe50 to 10c3362 Compare August 15, 2024 04:45
@namit-chandwani
Copy link
Contributor Author

@daibhin The CI check: https://github.com/PostHog/posthog/actions/runs/10398937870/job/28847237140?pr=23900 was failing after the latest change that I had pushed

I've fixed it now. Seems like we're good to go

@namit-chandwani
Copy link
Contributor Author

namit-chandwani commented Aug 20, 2024

Hey @daibhin, I noticed that the latest Storybook workflow is failing: link to the failing workflow. The issue seems to be coming from the frontend/src/scenes/pipeline/Pipeline.stories.tsx file.

Interestingly, this PR doesn’t include any changes that would affect the Pipeline section.

So can you please suggest how we should address this?

@namit-chandwani namit-chandwani force-pushed the refactor/session-replay-toggles branch from 619daf1 to 0beaf18 Compare August 22, 2024 13:15
@daibhin
Copy link
Contributor

daibhin commented Aug 23, 2024

@namit-chandwani it is most likely a flakey test. I suggest rebasing off master and we can kick the CI off again

@namit-chandwani
Copy link
Contributor Author

@namit-chandwani it is most likely a flakey test. I suggest rebasing off master and we can kick the CI off again

@daibhin It's done. Request you to trigger the CI now

@namit-chandwani
Copy link
Contributor Author

namit-chandwani commented Aug 23, 2024

@daibhin Looks like we’ve encountered another flaky test: Link (This PR doesn't involve any feature flag related changes)

Anything I can do on my end to help fix this new one? :)

@namit-chandwani
Copy link
Contributor Author

Hey @daibhin, I appreciate your efforts on the review.
Just wanted to check in on the flaky test we discussed. If everything is resolved, could we move forward with approving the PR?

As this is my first contribution to the PostHog project, I’m really looking forward to seeing it completed :)
I’m more than happy to assist with any final steps needed to get this across the line.

TIA

@daibhin
Copy link
Contributor

daibhin commented Aug 28, 2024

@namit-chandwani hey, sorry for the slow turnaround on this one. I'm working across a bunch of things right now and haven't been quick enough here to beat the latest migration.

Would you be able to rebase again and update the migration? I can kickoff another CI run in that case and hopefully get things to pass.

Alternatively I can recreate your changes on my own branch and have a quicker feedback loop that way

@namit-chandwani
Copy link
Contributor Author

@daibhin No worries at all! I understand how it gets with multiple things going on.
I've regenerated the migration file again. Request you to proceed now

@daibhin
Copy link
Contributor

daibhin commented Aug 28, 2024

@namit-chandwani fantastic! Fingers crossed for some 🟢 this time 🤞

@daibhin daibhin merged commit e729463 into PostHog:master Aug 28, 2024
92 checks passed
@daibhin
Copy link
Contributor

daibhin commented Aug 28, 2024

@namit-chandwani went ahead and merged this one because I was afraid another migration would come otherwise. I'll leave the issue to you to close.

Congrats on getting this in!! Thanks for sticking with us 🙏

@namit-chandwani namit-chandwani deleted the refactor/session-replay-toggles branch August 28, 2024 13:49
@namit-chandwani
Copy link
Contributor Author

@daibhin Thanks a ton for merging the PR! Your support and insights have been incredibly helpful :)

Excited to see these changes in action and can’t wait to dive into more contributions.
Here’s to more awesome collaborations ahead! 🚀

pauldambra pushed a commit that referenced this pull request Aug 29, 2024
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.

Chore: Show console logs and network perf toggled ON by default
4 participants