|
1 | | -"""Compile-time telemetry context.""" |
| 1 | +"""Compile-time telemetry context. |
| 2 | +
|
| 3 | +Lives in ``reflex_base`` (not ``reflex``) so deep packages like |
| 4 | +``reflex_components_core`` — which depend on ``reflex_base`` but not |
| 5 | +``reflex`` — can read the active context without inverting the |
| 6 | +dependency hierarchy. |
| 7 | +""" |
2 | 8 |
|
3 | 9 | from __future__ import annotations |
4 | 10 |
|
|
31 | 37 |
|
32 | 38 | _KNOWN_FEATURES: tuple[FeatureName, ...] = get_args(FeatureName) |
33 | 39 |
|
34 | | -# Counters bumped outside an active compile context (import-time class |
35 | | -# definitions, decorators, registrations) accumulate here so they survive |
36 | | -# into the next compile event. |
37 | | -_recorded_features: dict[FeatureName, int] = {} |
38 | | - |
39 | | - |
40 | | -def increment_feature(name: FeatureName, by: int = 1) -> None: |
41 | | - """Bump a feature invocation counter. |
42 | | -
|
43 | | - Writes to the active TelemetryContext if one is attached, else to the |
44 | | - process-level counter so import-time signals survive into the next compile. |
45 | | -
|
46 | | - Args: |
47 | | - name: The feature counter to bump. |
48 | | - by: How much to add. Defaults to 1. |
49 | | - """ |
50 | | - target = TelemetryContext.get() |
51 | | - target_dict = target.features_used if target is not None else _recorded_features |
52 | | - target_dict[name] = target_dict.get(name, 0) + by |
53 | | - |
54 | 40 |
|
55 | 41 | @dataclasses.dataclass(frozen=True, kw_only=True, slots=True, eq=False) |
56 | 42 | class TelemetryContext(BaseContext): |
57 | 43 | """Per-compile telemetry handle attached to the current contextvar.""" |
58 | 44 |
|
59 | 45 | start_perf_counter: float = dataclasses.field(default_factory=time.perf_counter) |
60 | | - features_used: dict[FeatureName, int] = dataclasses.field(default_factory=dict) |
61 | 46 | trigger: CompileTrigger | None = None |
62 | 47 | exception: BaseException | None = dataclasses.field(default=None, repr=False) |
63 | 48 |
|
|
0 commit comments