feat: capture pre-init Python environment in init telemetry#6534
feat: capture pre-init Python environment in init telemetry#6534FarhanAliRaza wants to merge 3 commits into
Conversation
Snapshot virtualenv state and presence of pyproject.toml/requirements.txt before template scaffolding runs so the "init" event reflects the user's actual starting environment, not files the template created.
Greptile SummaryThis PR adds a
Confidence Score: 5/5Safe to merge — the change is additive telemetry only and does not affect application init logic. The snapshot is captured before scaffolding, passed through the existing properties merge path in _prepare_event, and is never persisted or used in any control flow. reflex/utils/telemetry.py — the conda detection gap in is_in_virtualenv is worth a second look before the data is relied upon for analysis. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant initialize_app
participant get_init_environment
participant Filesystem
participant telemetry_send
User->>initialize_app: reflex init
initialize_app->>initialize_app: check Config.FILE exists (reinit guard)
initialize_app->>get_init_environment: capture pre-scaffolding state
get_init_environment->>get_init_environment: is_in_virtualenv() [sys.prefix, VIRTUAL_ENV]
get_init_environment->>Filesystem: Path("pyproject.toml").exists()
get_init_environment->>Filesystem: Path("requirements.txt").exists()
get_init_environment-->>initialize_app: "{in_virtualenv, has_pyproject_toml, has_requirements_txt}"
initialize_app->>initialize_app: scaffold template
initialize_app->>telemetry_send: "send("init", template=…, properties=init_environment)"
telemetry_send-->>User: async fire-and-forget to PostHog
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile |
# Conflicts: # tests/units/test_telemetry.py
|
@greptile |
| """ | ||
| return { | ||
| "in_virtualenv": is_in_virtualenv(), | ||
| "has_pyproject_toml": Path(constants.PyprojectToml.FILE).exists(), |
There was a problem hiding this comment.
add has_uv_lock and has_reflex_lock (directory) here
| A dict with ``in_virtualenv``, ``has_pyproject_toml`` and | ||
| ``has_requirements_txt`` boolean flags. | ||
| """ | ||
| return { |
There was a problem hiding this comment.
short circuit when telemetry is not enabled
|
|
||
| # Captured before scaffolding so the snapshot reflects the user's CWD, | ||
| # not files the template will create. | ||
| init_environment = telemetry.get_init_environment() |
There was a problem hiding this comment.
move this call above the constants.Config.FILE.exists() check and also include this information in the reinit event
Snapshot virtualenv state and presence of pyproject.toml/requirements.txt before template scaffolding runs so the "init" event reflects the user's actual starting environment, not files the template created.
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
fixes ENG-9476