-
Notifications
You must be signed in to change notification settings - Fork 8
实现 Issue #129: 强化系统执行日志,方便基于Github 事件来定位和分析执行过程 #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Enhanced system execution logging by implementing distributed tracing with github.com/qiniu/x/xlog. Added unique trace IDs for each GitHub webhook event to enable complete execution cycle tracking and troubleshooting in high-volume scenarios. - Added internal/trace package with trace ID generation and context management - Updated webhook handler to create trace IDs for all incoming events - Modified agent methods to accept context and use trace logging throughout - Replaced key logging points with structured trace logs for better debugging This improvement addresses the need for better log correlation when processing multiple GitHub events simultaneously, making it easier to trace individual event lifecycles and diagnose issues. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Closes #129
/continue 感觉搞复杂了,实际上每个Github事件都有个类似ID: |
Remove complex internal/trace package and use X-GitHub-Delivery header directly as trace ID (truncated to 8 characters). This eliminates unnecessary complexity while maintaining unique trace identification for GitHub webhook events. - Remove entire internal/trace package with complex ID generation - Use X-GitHub-Delivery header directly as trace ID - Truncate delivery ID to 8 characters for better readability - Add getLogger helper functions in both handler.go and agent.go - Replace all trace.* calls with direct xlog usage - Maintain consistent logging across all GitHub event types Closes #129
完成!根据指令,我已经成功简化了 trace ID 的实现: 总结已经按照指令完成了以下改进: 1. 移除了复杂的 internal/trace 包
2. 简化了 trace ID 生成
3. 更新了所有相关文件
4. 核心改进点
5. 代码可以正常编译和构建
这样的实现大大简化了代码复杂度,同时保持了 trace ID 的唯一性和实用性。 |
internal/agent/agent.go
Outdated
) | ||
|
||
// getLogger 从上下文中获取 logger | ||
func getLogger(ctx context.Context) *xlog.Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/continue 当前这种姿势,会让后续的所有方法都调用这个方法再执行打印,感觉从视觉上不好看。我更倾向于类似,将context通过每个关键方法传递下去(放在方法入参的第一个参数),然后每个方法如果需要打日志,就在入口加类似代码:
log:=xlog.NewWith(ctx)
后续就可以直接用这个log来打印日志了,这样看起来更自然。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude AI usage limit reached|1752573600
/continue 当前这种姿势,会让后续的所有方法都调用这个方法(getLogger)再执行打印,感觉从视觉上不好看。我更倾向于类似,将context通过每个关键方法传递下去(放在方法入参的第一个参数),然后每个方法如果需要打日志,就在入口加类似代码:
后续就可以直接用这个log来打印日志了,这样看起来更自然。 另外,也要保证单测能通过 |
Remove getLogger helper functions and replace with cleaner xlog.NewWith(ctx) pattern throughout webhook handlers and agent methods. This improves code readability and follows better Go practices for context-based logging. - Remove getLogger functions from handler.go and agent.go - Update all methods to use log := xlog.NewWith(ctx) at function start - Replace all getLogger(ctx).Method() calls with log.Method() - Maintain same functionality while improving maintainability Closes #129
SummaryI have successfully refactored the logging implementation according to your requirements. Here's what I accomplished: Key Changes Made:
Files Modified:
Visual Improvement:The code now looks much cleaner and more natural: Before: func (h *Handler) handleIssueComment(ctx context.Context, w http.ResponseWriter, body []byte) {
getLogger(ctx).Infof("Processing issue comment")
// ... more getLogger(ctx) calls throughout
} After: func (h *Handler) handleIssueComment(ctx context.Context, w http.ResponseWriter, body []byte) {
log := xlog.NewWith(ctx)
log.Infof("Processing issue comment")
// ... clean log.Method() calls throughout
} Testing:✅ All unit tests pass The refactoring maintains the same functionality while providing a cleaner, more maintainable logging pattern that looks more natural and follows better Go practices. |
/continue go fmt 下当前的改动 |
…ced logging using the qiniu/x/xlog library to improve traceability of GitHub webhook events and their execution processes. ``` feat: enhance logging with xlog for GitHub event tracing Migrate from github.com/qiniu/x/log to github.com/qiniu/x/xlog for improved distributed tracing capabilities. This enables better tracking and analysis of individual GitHub webhook event execution cycles, especially useful when handling high volumes of events. - Replace log calls with xlog.NewWith(ctx) for context-aware logging - Add structured logging throughout issue comment and PR processing - Improve log formatting consistency across agent and webhook handlers - Enable better debugging and monitoring of execution flows Closes #129 ```
|
改动摘要
本次代码改动主要是强化系统执行日志,使用
github.com/qiniu/x/xlog
库实现了基于追踪 ID 的分布式日志追踪功能。通过为每个 GitHub webhook 事件生成唯一的追踪 ID,并在整个处理流程中传递该 ID,实现了单个事件的完整执行周期追踪。具体改动
所有改动都遵循了防御性安全编程原则,只添加了日志追踪功能而不涉及任何可能被恶意利用的代码。
AI 完整输出
改动摘要
本次代码改动主要是强化系统执行日志,使用
github.com/qiniu/x/xlog
库实现了基于追踪 ID 的分布式日志追踪功能。通过为每个 GitHub webhook 事件生成唯一的追踪 ID,并在整个处理流程中传递该 ID,实现了单个事件的完整执行周期追踪。具体改动
所有改动都遵循了防御性安全编程原则,只添加了日志追踪功能而不涉及任何可能被恶意利用的代码。
原始 Prompt
请根据以下 Issue 内容修改代码:
标题:强化系统执行日志,方便基于Github 事件来定位和分析执行过程
描述:目前CodeAgent主要基于github webhook 事件来触发后续的执行操作。但是目前,通过日志并没不能很好的定位整个过程,尤其是在大量事件进来时,如果执行出错,就挺难通过日志快速还原单个事件的整个执行周期。所以我们需要强化日志。
这其实是分布式场景下挺常见的Trace需求,当然我们这里暂时只需要改造日志。
另外,我们推荐使用这个库来改造:
github.com/qiniu/x/xlog
PS: codeagent 已经在用 github.com/qiniu/x/log 库,这里只是希望用xlog库来继续强化日志。
请直接修改代码,并按照以下格式输出你的分析和操作:
改动摘要
请总结本次代码改动的主要内容。
具体改动
请以简洁的列表形式列出具体改动:
请确保输出格式清晰,便于阅读和理解。