Skip to content

feat(telemetry): report export status, duration, and phase timings#6509

Open
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:export-event
Open

feat(telemetry): report export status, duration, and phase timings#6509
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:export-event

Conversation

@FarhanAliRaza
Copy link
Copy Markdown
Contributor

@FarhanAliRaza FarhanAliRaza commented May 14, 2026

Track per-phase timings (compile/build/zip) and success/failure for reflex export, and stop mutating the cached event defaults so kwargs from one event can't leak into the next.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Track per-phase timings (compile/build/zip) and success/failure for
`reflex export`, and stop mutating the cached event defaults so kwargs
from one event can't leak into the next.
@FarhanAliRaza FarhanAliRaza requested a review from a team as a code owner May 14, 2026 19:03
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 14, 2026

Merging this PR will degrade performance by 3.77%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 3 regressed benchmarks
✅ 21 untouched benchmarks
⏩ 2 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_get_all_imports[_complicated_page] 2.8 ms 2.9 ms -4.77%
test_get_all_imports[_stateful_page] 548.2 µs 567.8 µs -3.44%
test_compile_page[_complicated_page] 8.4 ms 8.6 ms -3.09%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing FarhanAliRaza:export-event (d8c7903) with main (c3c720f)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (39c74cb) during the generation of this report, so c3c720f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR adds per-phase timing (compile_duration, build_duration, zip_duration), overall duration, and status/detail fields to the reflex export telemetry event, and fixes a long-standing bug where mutating the cached get_event_defaults() properties dict caused kwargs from one _send call to leak into subsequent calls.

  • export.py: Wraps each phase in a _time_phase closure-based context manager that records duration into phase_durations via a finally block, ensuring partial timings are captured even on failure; telemetry is fired from a top-level finally so it is always sent.
  • telemetry.py: Adds the new fields to additional_keys, switches from properties = event_data["properties"] (mutating shared reference) to .copy(), and tightens the filter to drop None-valued kwargs rather than propagating them.
  • Tests: Existing test_send is expanded with parametrized cases; four new focused tests cover no-leak isolation, unknown-kwarg dropping, None-value filtering, and the new test_export.py covers success, all four partial-failure points, backend-only, and no-zip scenarios.

Confidence Score: 4/5

Safe to merge — the core bug fix is correct and the new telemetry instrumentation is well-tested across all branch paths.

The cached-mutation fix is correct and thoroughly exercised. The two observations (setup_frontend grouped into build_duration, overwrite guard removed) are non-breaking design choices with no effect on production behaviour today.

reflex/utils/export.py is worth a second glance on the phase grouping decision if PostHog analysis needs to distinguish frontend-setup failures from build failures.

Important Files Changed

Filename Overview
reflex/utils/export.py Wraps compilation, build, and zip steps in per-phase timers; reports status, detail, and durations to telemetry in a finally block.
reflex/utils/telemetry.py Fixes the cached-mutation bug by copying properties before modifying; expands additional_keys with new export fields; new logic correctly filters None values.
tests/units/test_telemetry.py Mock target correctly changed from _get_event_defaults to get_event_defaults; new parametrized and dedicated isolation/None-filter tests added.
tests/units/utils/test_export.py New test file covering success, all four partial-failure points, backend-only, and no-zip scenarios.

Sequence Diagram

sequenceDiagram
    participant C as Caller
    participant E as export()
    participant P as prerequisites
    participant B as build
    participant T as telemetry.send()
    participant PH as PostHog API

    C->>E: export(frontend, zipping, ...)
    E->>E: "start = time.monotonic()"
    E->>E: "phase_durations = {}"
    E->>E: "status = success"

    opt "frontend=True"
        E->>P: get_compiled_app() [_time_phase(compile_duration)]
        P-->>E: ok / raises
        E->>B: setup_frontend() + build.build() [_time_phase(build_duration)]
        B-->>E: ok / raises
    end

    opt "zipping=True"
        E->>B: zip_app() [_time_phase(zip_duration)]
        B-->>E: ok / raises
    end

    alt Exception raised
        E->>E: "status=failure, detail=type(exc).__name__, raise"
    end

    E->>T: send(export, status, detail, duration, compile_duration, build_duration, zip_duration)
    T->>T: _prepare_event(): copy defaults, filter None kwargs
    T->>PH: POST event (async background task)
    T-->>E: done (fire-and-forget)
    E-->>C: return (or re-raise)
Loading

Reviews (1): Last reviewed commit: "feat(telemetry): report export status, d..." | Re-trigger Greptile

Comment thread reflex/utils/export.py
Comment thread reflex/utils/telemetry.py
…vent

Time `build.setup_frontend` separately from `build.build` and skip
additional keys already present in defaults so callers can't overwrite
them.
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.

1 participant