Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion daemon/aicode_otel_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *AICodeOtelProcessor) writeDebugFile(filename string, data interface{})

// ProcessMetrics receives OTEL metrics and forwards to backend immediately
func (p *AICodeOtelProcessor) ProcessMetrics(ctx context.Context, req *collmetricsv1.ExportMetricsServiceRequest) (*collmetricsv1.ExportMetricsServiceResponse, error) {
slog.Debug("AICodeOtel: Processing metrics request", "resourceMetricsCount", len(req.GetResourceMetrics()))
slog.Debug("AICodeOtel: Processing metrics request", "resourceMetricsCount", slog.Int("len", len(req.GetResourceMetrics())), slog.Bool("debug", p.debug))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current usage of slog.Debug is incorrect and will result in a malformed log entry with a !BADKEY attribute. The slog.Bool attribute is not preceded by a string key, which causes slog to report an error in the log output. To fix this and create the intended nested structure for resourceMetricsCount while also including the debug flag, you should use slog.Group.

Suggested change
slog.Debug("AICodeOtel: Processing metrics request", "resourceMetricsCount", slog.Int("len", len(req.GetResourceMetrics())), slog.Bool("debug", p.debug))
slog.Debug("AICodeOtel: Processing metrics request", slog.Group("resourceMetricsCount", slog.Int("len", len(req.GetResourceMetrics()))), slog.Bool("debug", p.debug))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mixing slog string key with slog.Attr value produces malformed log attribute

On line 83, "resourceMetricsCount" is a string key whose value becomes slog.Int("len", ...) — an slog.Attr. When slog encounters a string key followed by an slog.Attr as the value, it nests the Attr, producing an output like resourceMetricsCount.len=3 instead of the intended resourceMetricsCount=3.

Root Cause and comparison with ProcessLogs

The slog.Debug variadic args are parsed as follows: if an arg is a string, it's treated as a key, and the next arg becomes its value. If an arg is an slog.Attr, it's used directly. On line 83:

slog.Debug("...", "resourceMetricsCount", slog.Int("len", len(req.GetResourceMetrics())), slog.Bool("debug", p.debug))
  • "resourceMetricsCount" → key
  • slog.Int("len", ...) → value (an slog.Attr used as a value for the key above, creating a nested/group attribute resourceMetricsCount.len)
  • slog.Bool("debug", p.debug) → standalone attr, works fine

Compare with the correct pattern on daemon/aicode_otel_processor.go:138 in ProcessLogs:

slog.Debug("...", "resourceLogsCount", len(req.GetResourceLogs()), slog.Bool("debug", p.debug))

Here the value for "resourceLogsCount" is a plain int, producing the expected resourceLogsCount=3 output.

Impact: The metrics count log attribute will have a misleading nested key name (resourceMetricsCount.len) instead of the simple resourceMetricsCount seen in ProcessLogs. This degrades observability for daemon diagnostics — the stated goal of this PR.

Suggested change
slog.Debug("AICodeOtel: Processing metrics request", "resourceMetricsCount", slog.Int("len", len(req.GetResourceMetrics())), slog.Bool("debug", p.debug))
slog.Debug("AICodeOtel: Processing metrics request", "resourceMetricsCount", len(req.GetResourceMetrics()), slog.Bool("debug", p.debug))
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


if p.debug {
p.writeDebugFile("aicode-otel-debug-metrics.txt", req)
Expand Down