Skip to content

fix(daemon): include debug context in OTEL metrics log#246

Merged
AnnatarHe merged 1 commit intomainfrom
fix/daemon-otel-metrics-log-args
Mar 1, 2026
Merged

fix(daemon): include debug context in OTEL metrics log#246
AnnatarHe merged 1 commit intomainfrom
fix/daemon-otel-metrics-log-args

Conversation

@AnnatarHe
Copy link
Contributor

@AnnatarHe AnnatarHe commented Mar 1, 2026

Summary

  • update OTEL metrics processing debug log to include structured length and debug mode context
  • keep logging at debug level while improving observability for daemon diagnostics

Testing

  • not run (not requested)

Open with Devin

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the debug logging for OpenTelemetry metrics processing within the daemon. It enhances diagnostic capabilities by adding structured details, such as the count of resource metrics and the processor's debug state, to the existing debug logs. The primary goal is to provide more context for troubleshooting without increasing the verbosity level beyond debug.

Highlights

  • Enhanced Debug Logging: The OpenTelemetry (OTEL) metrics processing debug log has been updated to include more structured and contextual information.
  • Structured Log Fields: The resourceMetricsCount is now logged as a structured integer field (slog.Int) and the processor's debug status (p.debug) is included as a boolean field (slog.Bool).
  • Improved Observability: These changes improve observability for daemon diagnostics by providing richer debug information without altering the logging level.
Changelog
  • daemon/aicode_otel_processor.go
    • Updated the ProcessMetrics function's debug log to include structured resourceMetricsCount and the debug flag.
Activity
  • Testing was not performed as it was not requested by the author.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve debug logging for OTEL metrics processing by adding more context. However, the implementation contains an incorrect usage of the slog library, which will result in malformed log entries. I've provided a specific comment with a code suggestion to correct the logging call.

// 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))

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

// 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))

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.

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
daemon/aicode_otel_processor.go 0.00% 1 Missing ⚠️
Flag Coverage Δ
unittests 37.46% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/aicode_otel_processor.go 38.11% <0.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AnnatarHe AnnatarHe merged commit 0f989d4 into main Mar 1, 2026
6 of 7 checks passed
@AnnatarHe AnnatarHe deleted the fix/daemon-otel-metrics-log-args branch March 1, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant