Skip to content

[azd ai agents] Glharper/monitor compact logs#7790

Open
glharper wants to merge 4 commits intomainfrom
glharper/monitor-compact-logs
Open

[azd ai agents] Glharper/monitor compact logs#7790
glharper wants to merge 4 commits intomainfrom
glharper/monitor-compact-logs

Conversation

@glharper
Copy link
Copy Markdown
Member

Fixes #7209

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves azd ai agent monitor (azure.ai.agents extension) log readability by formatting the hosted agent SSE logstream into compact, single-line entries (with special handling for session metadata), while still supporting a raw passthrough mode for scripting/compatibility.

Changes:

  • Add a dedicated SSE log formatter with compact rendering, per-stream coloring, UTC/local timestamp support, and raw passthrough.
  • Wire the formatter into azd ai agent monitor and add --utc / --raw flags.
  • Add unit tests for SSE formatting behavior and bump extension version + changelog.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/version.txt Bumps extension version to 0.1.24-preview.
cli/azd/extensions/azure.ai.agents/extension.yaml Keeps extension manifest version in sync with version.txt.
cli/azd/extensions/azure.ai.agents/CHANGELOG.md Documents the monitor output change and new flags.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor.go Uses the new formatter and adds --utc/--raw flags.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_format.go Implements compact SSE log formatting and parsing logic.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_format_test.go Adds formatter test coverage for multiple SSE cases.

Comment on lines +78 to +82
if len(dataLines) == 0 {
return
}
data := strings.Join(dataLines, "\n")
f.renderEvent(eventName, data)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

In formatStream's flush() helper, when an event has an event: line but no data: lines, flush() returns early and leaves eventName unchanged. That can leak the previous event name into the next event (especially for data-only events) and misclassify payloads. Consider always resetting eventName (and clearing dataLines) on blank-line flush, even when len(dataLines)==0.

Suggested change
if len(dataLines) == 0 {
return
}
data := strings.Join(dataLines, "\n")
f.renderEvent(eventName, data)
if len(dataLines) != 0 {
data := strings.Join(dataLines, "\n")
f.renderEvent(eventName, data)
}

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +141
func (f *logFormatter) renderEvent(eventName, data string) {
// Accept events with no "event:" line (data-only) and "event: log".
// Anything else we don't recognize is passed through raw.
if eventName != "" && eventName != "log" {
fmt.Fprintf(f.writer, "event: %s\ndata: %s\n\n", eventName, data)
return
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

renderEvent claims to pass through unknown event names as raw SSE, but it re-emits the payload as a single data: line. If the original SSE event had multiple data: lines (or if data contains embedded newlines after concatenation), the output is no longer valid SSE because the continuation lines won't be prefixed with data:. Consider preserving the original SSE framing by writing one data: line per original data line (and a blank line terminator), or otherwise emitting a clearly non-SSE raw representation.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +19
func init() {
// Disable color globally for stable assertions in this test file.
color.NoColor = true
}
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This test file sets color.NoColor = true in an init() function, which mutates global state for the entire cmd package test run and can affect unrelated tests that rely on color behavior. Prefer a per-test approach (e.g., t.Setenv("NO_COLOR", "1")) or saving/restoring the previous color.NoColor value via t.Cleanup/TestMain to keep tests isolated.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

A couple of low-severity nits below. Solid PR overall, tests cover the interesting cases.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_format.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_format_test.go Outdated
@glharper
Copy link
Copy Markdown
Member Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

@copilot apply changes based on the comments in this thread

Applied all three changes from that review thread in 9f5ab2e:

  • flush() now always resets eventName/dataLines, even when there are no data lines.
  • Unknown event pass-through now emits one data: line per original data line for valid SSE framing.
  • Replaced the global init() that mutated color.NoColor with per-test save/restore via t.Cleanup inside newTestFormatter.

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.

improve the formatting and display of logs for hosted agents

4 participants