Upgrade CloudLogger to aepipe-sdk v0.1.1 with D1 payload support#91
Upgrade CloudLogger to aepipe-sdk v0.1.1 with D1 payload support#91loadchange merged 5 commits intomainfrom
Conversation
核心升级: - 使用官方 aepipe-sdk 0.1.1 替代手写 HTTP 客户端,客户端防截断校验 - 利用 D1 payload 存储完整 AI 响应、Prompt、市场数据快照,突破 16KB blob 限制 - blobs 仅存轻量索引字段(symbol/action/status),大数据全走 payload - AI 响应不再截断到 500 字符,决策推理过程完整可追溯 新增事件类型覆盖完整交易生命周期: - system: 启动/关闭/配置变更 - cycle: 交易周期开始/结束/跳过 - account: 账户余额/权益/持仓快照 - risk: 回撤保护/止损失败/安全平仓等风控事件 - grid: 网格重建/同步/撤单等操作 - alert: 异常波动/API 故障/订单失败等告警 关键模块日志增强: - main.py: 启动/关闭/周期异常/波动告警/账户快照 - grid_main.py: 启动/周期异常 - client.py: 止损失败自动平仓/安全平仓失败严重告警 - account_protector.py: 保护机制触发事件 - grid_manager.py: 网格重建完整参数 - order_manager.py: TPSL 设置失败紧急平仓 配置新增: - cloud_logging.payload_ttl: D1 payload 过期时间(默认 90 天) 测试:39 个测试全部通过,431 个完整测试套件通过 https://claude.ai/code/session_01McaLk3VSxwmNnMVybEsbW9
There was a problem hiding this comment.
Code Review
This pull request upgrades the cloud logging infrastructure to version 2 by integrating the aepipe-sdk and implementing D1 payload support for storing large datasets like AI responses and prompts. It significantly expands logging coverage across the application, adding specific event types for system lifecycle, risk management, grid operations, and account snapshots. Review feedback recommends enhancing error reporting in main.py by replacing repr(e) with traceback.format_exc() to provide more detailed stack traces for debugging decision and cycle errors.
| alert_type="decision_error", | ||
| severity="high", | ||
| message=str(e), | ||
| details={"traceback": repr(e), "cycle": self.cycle_counter}, |
There was a problem hiding this comment.
For better debuggability, it's recommended to use traceback.format_exc() instead of repr(e) to capture the full stack trace of the exception. This provides more context when an error occurs. Other parts of the codebase, like in grid_main.py, already use this approach, and maintaining consistency is good practice.
You'll also need to add import traceback at the top of the file.
| details={"traceback": repr(e), "cycle": self.cycle_counter}, | |
| details={"traceback": traceback.format_exc(), "cycle": self.cycle_counter}, |
| alert_type="cycle_error", | ||
| severity="extreme", | ||
| message=str(e), | ||
| details={"traceback": repr(e), "cycle": self.cycle_counter}, |
There was a problem hiding this comment.
Similar to my other comment, using traceback.format_exc() here instead of repr(e) would provide a more detailed traceback for easier debugging of cycle errors. This will also require importing the traceback module if it's not already present.
| details={"traceback": repr(e), "cycle": self.cycle_counter}, | |
| details={"traceback": traceback.format_exc(), "cycle": self.cycle_counter}, |
根据 PR review 建议,在云端日志的异常记录中使用 traceback.format_exc() 替代 repr(e),提供完整的堆栈信息便于远程调试。 https://claude.ai/code/session_01McaLk3VSxwmNnMVybEsbW9
- cloud_logger.py: 移除未使用的 json import(已由 aepipe-sdk 处理序列化) - test_cloud_logger.py: 移除未使用的 patch import https://claude.ai/code/session_01McaLk3VSxwmNnMVybEsbW9
Summary
Upgrade the CloudLogger module from a custom HTTP-based implementation to use the official
aepipe-sdk(v0.1.1), introducing D1 payload support for storing complete data without truncation and adding comprehensive event types for the full trading lifecycle.Key Changes
Core SDK Integration
urllib-based HTTP implementation with officialaepipe-sdkclientAepipeclient for all cloud communication with built-in blob size validationDataPoint,LogEntry,AepipeError, andValidationErrorfrom aepipe SDKData Model Improvements
dictto SDK types:LogEntryfor logs,DataPointfor eventsDecision Logging Enhancement
New Event Types
send_system_event(): System lifecycle events (startup, shutdown, config changes)send_risk_event(): Risk management events (drawdown, daily loss, stop loss triggers)send_grid_event(): Grid trading events (sync, rebuild, cancel)send_cycle_event(): Trading cycle events (start, end, skip)send_account_snapshot(): Periodic account state snapshots with positionssend_alert(): Market alerts with severity mapping (extreme/high → error, elevated → warn)Trade Event Expansion
Error Handling
ValidationError(client-side validation, skip without retry) andAepipeError(server errors, retry)Integration Points
main.pyto send system startup event with configuration detailsgrid_main.pyand related modules to use new cloud logger APIConfiguration
payload_ttlparameter to CloudLogger initializationImplementation Details
https://claude.ai/code/session_01McaLk3VSxwmNnMVybEsbW9