|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
+import asyncio
|
|
|
import multiprocessing
|
|
|
import platform
|
|
|
|
|
@@ -157,17 +158,7 @@ def _send_event(event_data: dict) -> bool:
|
|
|
return False
|
|
|
|
|
|
|
|
|
-def send(event: str, telemetry_enabled: bool | None = None, **kwargs) -> bool:
|
|
|
- """Send anonymous telemetry for Reflex.
|
|
|
-
|
|
|
- Args:
|
|
|
- event: The event name.
|
|
|
- telemetry_enabled: Whether to send the telemetry (If None, get from config).
|
|
|
- kwargs: Additional data to send with the event.
|
|
|
-
|
|
|
- Returns:
|
|
|
- Whether the telemetry was sent successfully.
|
|
|
- """
|
|
|
+def _send(event, telemetry_enabled, **kwargs):
|
|
|
from reflex.config import get_config
|
|
|
|
|
|
# Get the telemetry_enabled from the config if it is not specified.
|
|
@@ -182,3 +173,36 @@ def send(event: str, telemetry_enabled: bool | None = None, **kwargs) -> bool:
|
|
|
if not event_data:
|
|
|
return False
|
|
|
return _send_event(event_data)
|
|
|
+
|
|
|
+
|
|
|
+def send(event: str, telemetry_enabled: bool | None = None, **kwargs):
|
|
|
+ """Send anonymous telemetry for Reflex.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ event: The event name.
|
|
|
+ telemetry_enabled: Whether to send the telemetry (If None, get from config).
|
|
|
+ kwargs: Additional data to send with the event.
|
|
|
+ """
|
|
|
+
|
|
|
+ async def async_send(event, telemetry_enabled, **kwargs):
|
|
|
+ return _send(event, telemetry_enabled, **kwargs)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # Within an event loop context, send the event asynchronously.
|
|
|
+ asyncio.create_task(async_send(event, telemetry_enabled, **kwargs))
|
|
|
+ except RuntimeError:
|
|
|
+ # If there is no event loop, send the event synchronously.
|
|
|
+ _send(event, telemetry_enabled, **kwargs)
|
|
|
+
|
|
|
+
|
|
|
+def send_error(error: Exception, context: str):
|
|
|
+ """Send an error event.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ error: The error to send.
|
|
|
+ context: The context of the error (e.g. "frontend" or "backend")
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Whether the telemetry was sent successfully.
|
|
|
+ """
|
|
|
+ return send("error", detail=type(error).__name__, context=context)
|