mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-20 23:45:22 +08:00
fix(telemetry): schedule the trace payload send instead of dropping it
close_trace() called the coroutine TelemetryManager.start_send_task without awaiting or scheduling it, so every payload closed on that path was silently dropped and the runtime logged "coroutine ... was never awaited". The only other caller awaits it correctly, so both call styles stay supported: call the manager, schedule the returned coroutine on the running loop, and close it with a debug log when no loop is available. Regression case added in tests/unit_tests/telemetry/test_trace.py: it fails before this change (payload never delivered) and passes after.
This commit is contained in:
@@ -344,3 +344,28 @@ class TestIngress:
|
||||
_, execution = get_modules()
|
||||
with execution.ingress(types.SimpleNamespace(), 'event_done'):
|
||||
pass
|
||||
|
||||
|
||||
class AsyncSendManager(FakeManager):
|
||||
"""Stand-in whose start_send_task is a coroutine, like TelemetryManager."""
|
||||
|
||||
async def start_send_task(self, payload: dict) -> None:
|
||||
self.sent.append(payload)
|
||||
|
||||
|
||||
class TestTraceDispatch:
|
||||
async def test_close_trace_schedules_the_coroutine_send(self):
|
||||
trace, execution = get_modules()
|
||||
manager = AsyncSendManager(trace_config())
|
||||
counters = execution.ExecutionCounters(manager)
|
||||
binding = trace.bind()
|
||||
try:
|
||||
counters.record(CONTEXT, **STAGE)
|
||||
counters.close_trace(binding.state, 'event_done')
|
||||
# The payload is only delivered once the scheduled task runs.
|
||||
assert manager.sent == []
|
||||
await asyncio.sleep(0)
|
||||
finally:
|
||||
trace.unbind_root(binding)
|
||||
assert len(manager.sent) == 1
|
||||
assert manager.sent[0]['event_type'] == 'feature_execution'
|
||||
|
||||
Reference in New Issue
Block a user