Repository navigation
Replies: 1 comment
|
这个思路可以: 1. 调用点不止两个,而且现在已经重复计数了。 除了 建议只在 2. 缺省值别自己发明。 解析时,非法值会被归一化:category 变成 另外,循环里逐条 Drafted with AI assistance; I checked the code references above. |
|
这个思路可以: 1. 调用点不止两个,而且现在已经重复计数了。 除了 建议只在 2. 缺省值别自己发明。 解析时,非法值会被归一化:category 变成 另外,循环里逐条 Drafted with AI assistance; I checked the code references above. |
Uh oh!
There was an error while loading. Please reload this page.
想在遥测增加一个缺陷类型的维度。
Ai分析结果如下:
修改 internal/telemetry/metrics.go在 RecordCommentsGenerated 函数后面新增:
`// CommentAttrs holds per-comment classification data for telemetry.
type CommentAttrs struct {
Category string // bug, security, performance, maintainability, test, style, documentation, other
Severity string // critical, high, medium, low
}
// RecordCommentsGeneratedWithAttrs records each comment individually with
// category and severity dimensions, enabling aggregation by type.
func RecordCommentsGeneratedWithAttrs(ctx context.Context, comments []CommentAttrs) {
if !IsEnabled() {
return
}
ensureMetrics()
if mCommentsGenerated == nil {
return
}
for _, c := range comments {
cat := c.Category
if cat == "" {
cat = "other"
}
sev := c.Severity
if sev == "" {
sev = "medium"
}
attrs := []attribute.KeyValue{
attribute.String("category", cat),
attribute.String("severity", sev),
}
mCommentsGenerated.Add(ctx, 1, metric.WithAttributes(attrs...))
}
}`
修改 internal/agent/agent.go 找到第 416-418 行:
if len(comments) > 0 { telemetry.RecordCommentsGenerated(ctx, int64(len(comments))) }改为
if len(comments) > 0 { attrs := make([]telemetry.CommentAttrs, len(comments)) for i, c := range comments { attrs[i] = telemetry.CommentAttrs{ Category: c.Category, Severity: c.Severity, } } telemetry.RecordCommentsGeneratedWithAttrs(ctx, attrs) }同样修改 internal/scan/agent.go(scan 模式也有类似调用)
All reactions