Browse Source

identify app_class in telemetry events (#5374)

Thomas Brandého 4 ngày trước cách đây
mục cha
commit
5ecc8e9e2a
1 tập tin đã thay đổi với 22 bổ sung2 xóa
  1. 22 2
      reflex/utils/telemetry.py

+ 22 - 2
reflex/utils/telemetry.py

@@ -62,6 +62,22 @@ def get_reflex_version() -> str:
     return constants.Reflex.VERSION
 
 
+def _get_app_class_name() -> str | None:
+    """Get the app class name if available.
+
+    Returns:
+        The app class name (e.g. "App", "AppEnterprise") or None if not available.
+    """
+    try:
+        from reflex.utils.prerequisites import get_and_validate_app
+
+        app_info = get_and_validate_app()
+    except Exception:
+        return None
+    else:
+        return app_info.app.__class__.__name__
+
+
 def get_cpu_count() -> int:
     """Get the number of CPUs.
 
@@ -184,12 +200,16 @@ def _prepare_event(event: str, **kwargs) -> _Event | None:
     if not event_data:
         return None
 
-    additional_keys = ["template", "context", "detail", "user_uuid"]
+    additional_keys = ["template", "context", "detail", "user_uuid", "app_class"]
 
     properties = event_data["properties"]
 
+    # Auto-detect app class if not provided
+    if "app_class" not in kwargs:
+        kwargs["app_class"] = _get_app_class_name()
+
     for key in additional_keys:
-        if key in properties or key not in kwargs:
+        if key in properties or key not in kwargs or kwargs[key] is None:
             continue
 
         properties[key] = kwargs[key]