Add --tag flag to agent for custom metric metadata#25
Merged
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tags like --tag event_type=foo or --tag ts=... would overwrite core payload fields and produce invalid Insights data. Now only "host" is allowed as an override; all other built-in fields are rejected at startup with a clear error message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Group var declarations, wrap long lines in flag registration and test assertions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support for custom user-defined tags on hb agent metric events via a repeatable --tag/-t key=value flag and agent.tags config, with CLI tags overriding config.
Changes:
- Added
--tag/-tsupport tohb agent, with parsing, reserved-key validation, and config/CLI merging. - Updated metric submission so tags are injected into the JSON payload (including
hostoverride behavior). - Added unit/integration-style tests for tag parsing/merging and tag presence across submitted events; updated README examples.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/agent.go | Implements tag flag/config loading, reserved key validation, and tag merging into metric payload JSON. |
| cmd/agent_test.go | Adds coverage for tag parsing/merging, config loading, and verifying tags/host override appear in emitted events. |
| README.md | Documents agent.tags config and --tag CLI usage examples, including hostname override. |
Comments suppressed due to low confidence (1)
cmd/agent_test.go:242
reportMetricsis synchronous; thetime.Sleep(2 * time.Second)here doesn’t cause additional events to be emitted and only slows the test. Consider removing the sleep and asserting onreceivedEventsimmediately afterreportMetricsreturns.
err := reportMetrics("test-host", nil)
require.NoError(t, err)
// Wait for metrics to be reported
time.Sleep(2 * time.Second)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…c precision Avoids float64 coercion of uint64 metric fields (e.g. total_bytes) during the unmarshal/merge/remarshal roundtrip. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
joshuap
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--tag key=valueflag (short:-t) tohb agentso users can annotate metric events with custom metadata like environment, role, or a custom hostnameagent.tags--tag host=foooverrides the auto-detected hostname; all other built-in metric fields (ts,event_type,used_percent, etc.) are reserved and rejected at startup with a clear errorTest plan
hosttag overrides auto-detected hostname--tag event_type=foois rejected at startup🤖 Generated with Claude Code