fire and foreget
This commit is contained in:
parent
32d928074a
commit
9f6f4cd60d
1 changed files with 25 additions and 18 deletions
|
|
@ -294,18 +294,18 @@ async def _send_scarf_event(
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
except httpx.TimeoutException as e:
|
except httpx.TimeoutException:
|
||||||
# Retry timeout errors
|
# Don't retry timeouts - Scarf is slow/unreachable, retrying won't help
|
||||||
logger.error(
|
logger.warning(
|
||||||
f"Failed to send telemetry event: {category}:{message_id}. "
|
f"Telemetry timeout for {category}:{message_id}, skipping retries"
|
||||||
f"Timeout error: {e}"
|
|
||||||
)
|
)
|
||||||
except httpx.ConnectError as e:
|
return
|
||||||
# Retry connection errors
|
except httpx.ConnectError:
|
||||||
logger.error(
|
# Don't retry connection errors - network is unreachable
|
||||||
f"Failed to send telemetry event: {category}:{message_id}. "
|
logger.warning(
|
||||||
f"Connection error: {e}"
|
f"Telemetry connection failed for {category}:{message_id}, skipping retries"
|
||||||
)
|
)
|
||||||
|
return
|
||||||
except httpx.RequestError as e:
|
except httpx.RequestError as e:
|
||||||
# Non-retryable request errors
|
# Non-retryable request errors
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
@ -333,11 +333,14 @@ async def _send_scarf_event(
|
||||||
|
|
||||||
class TelemetryClient:
|
class TelemetryClient:
|
||||||
"""Telemetry client for sending events to Scarf."""
|
"""Telemetry client for sending events to Scarf."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def send_event(category: str, message_id: str, metadata: dict = None) -> None:
|
async def send_event(category: str, message_id: str, metadata: dict = None) -> None:
|
||||||
"""Send a telemetry event asynchronously.
|
"""Send a telemetry event in the background (fire-and-forget).
|
||||||
|
|
||||||
|
This method creates a background task and returns immediately,
|
||||||
|
so telemetry never blocks application operations.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
category: Event category
|
category: Event category
|
||||||
message_id: Event message ID
|
message_id: Event message ID
|
||||||
|
|
@ -348,11 +351,15 @@ class TelemetryClient:
|
||||||
f"Telemetry event aborted: {category}:{message_id}. DO_NOT_TRACK is enabled"
|
f"Telemetry event aborted: {category}:{message_id}. DO_NOT_TRACK is enabled"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
async def _send_with_error_handling():
|
||||||
await _send_scarf_event(category, message_id, metadata)
|
try:
|
||||||
except Exception as e:
|
await _send_scarf_event(category, message_id, metadata)
|
||||||
logger.error(f"Error sending telemetry event: {e}")
|
except Exception as e:
|
||||||
|
logger.error(f"Error sending telemetry event: {e}")
|
||||||
|
|
||||||
|
# Fire and forget - don't block the caller
|
||||||
|
asyncio.create_task(_send_with_error_handling())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def send_event_sync(category: str, message_id: str, metadata: dict = None) -> None:
|
def send_event_sync(category: str, message_id: str, metadata: dict = None) -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue