Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Drop mcp.fields.bytes_saved metric
Remove the mcp.fields.bytes_saved counter. It is derivable on the
dashboard from the two remaining byte counters, since
sum(bytes_full) - sum(bytes_sent) equals the total saved at any rollup,
so emitting it separately is redundant. Keeping only bytes_full and
bytes_sent shrinks the emitted telemetry surface.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
tommaso-moro and Copilot committed Jul 7, 2026
commit 1f51e0d831edd2337a266860cd546287f1fb8331
20 changes: 10 additions & 10 deletions pkg/github/fields_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import (
// (a small fixed set of tool names) and `filtered` (a boolean). Unbounded values
// such as repository, owner, user, the query, or the requested field list are
// never used as tags.
//
// The realized savings (bytes_full - bytes_sent) is intentionally not emitted as
// its own metric: it is derivable on the dashboard from the two byte counters,
// since sum(bytes_full) - sum(bytes_sent) equals the total saved at any rollup.
const (
metricFieldsToolCall = "mcp.fields.tool_call"
metricFieldsBytesFull = "mcp.fields.bytes_full"
metricFieldsBytesSent = "mcp.fields.bytes_sent"
metricFieldsBytesSaved = "mcp.fields.bytes_saved"
metricFieldsToolCall = "mcp.fields.tool_call"
metricFieldsBytesFull = "mcp.fields.bytes_full"
metricFieldsBytesSent = "mcp.fields.bytes_sent"
)

// recordFieldsUsage emits telemetry for a single call to a tool that supports
Expand All @@ -27,10 +30,9 @@ const (
// Every call increments mcp.fields.tool_call tagged by tool and whether the
// response was filtered, which yields the adoption rate (filtered / total). When
// the response was filtered, it also records the unfiltered (fullBytes) and
// returned (sentBytes) payload sizes plus their difference, which yields the
// realized savings. Byte counters are only emitted for filtered calls so that
// "percent saved" (bytes_saved / bytes_full) is computed over the population
// where filtering actually applied.
// returned (sentBytes) payload sizes. Byte counters are only emitted for
// filtered calls so that "percent saved" (1 - bytes_sent / bytes_full) is
// computed over the population where filtering actually applied.
func recordFieldsUsage(ctx context.Context, deps ToolDependencies, tool string, filtered bool, fullBytes, sentBytes int) {
m := deps.Metrics(ctx)
if m == nil {
Expand All @@ -47,8 +49,6 @@ func recordFieldsUsage(ctx context.Context, deps ToolDependencies, tool string,
}

toolTag := map[string]string{"tool": tool}
saved := max(fullBytes-sentBytes, 0)
m.Counter(metricFieldsBytesFull, toolTag, int64(fullBytes))
m.Counter(metricFieldsBytesSent, toolTag, int64(sentBytes))
m.Counter(metricFieldsBytesSaved, toolTag, int64(saved))
}
17 changes: 1 addition & 16 deletions pkg/github/fields_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ func Test_recordFieldsUsage_Filtered(t *testing.T) {
sent, ok := rec.counter(metricFieldsBytesSent)
require.True(t, ok)
assert.Equal(t, int64(30), sent.value)

saved, ok := rec.counter(metricFieldsBytesSaved)
require.True(t, ok)
assert.Equal(t, int64(70), saved.value)
}

func Test_recordFieldsUsage_NotFiltered(t *testing.T) {
Expand All @@ -115,21 +111,10 @@ func Test_recordFieldsUsage_NotFiltered(t *testing.T) {
// No byte counters are emitted when the response was not filtered.
_, ok = rec.counter(metricFieldsBytesFull)
assert.False(t, ok)
_, ok = rec.counter(metricFieldsBytesSaved)
_, ok = rec.counter(metricFieldsBytesSent)
assert.False(t, ok)
}

func Test_recordFieldsUsage_ClampsNegativeSavings(t *testing.T) {
deps, rec := depsWithRecordingMetrics(t, BaseDeps{})

// sent larger than full should never yield negative savings.
recordFieldsUsage(context.Background(), deps, "get_file_contents", true, 10, 25)

saved, ok := rec.counter(metricFieldsBytesSaved)
require.True(t, ok)
assert.Equal(t, int64(0), saved.value)
}

func Test_recordFieldsUsage_NilExporterDoesNotPanic(t *testing.T) {
// BaseDeps with no Obsv falls back to a noop sink rather than panicking.
assert.NotPanics(t, func() {
Expand Down
3 changes: 0 additions & 3 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,7 @@ func Test_GetFileContents_DirectoryFieldsTelemetry(t *testing.T) {
require.True(t, ok)
sent, ok := rec.counter(metricFieldsBytesSent)
require.True(t, ok)
saved, ok := rec.counter(metricFieldsBytesSaved)
require.True(t, ok)
assert.Greater(t, full.value, sent.value, "filtering should remove bytes")
assert.Equal(t, full.value-sent.value, saved.value)
}

func Test_GetFileContents_IFC_InsidersMode(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/github/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ func Test_SearchCode_FieldsTelemetry(t *testing.T) {
require.True(t, ok)
sent, ok := rec.counter(metricFieldsBytesSent)
require.True(t, ok)
saved, ok := rec.counter(metricFieldsBytesSaved)
require.True(t, ok)
assert.Greater(t, full.value, sent.value, "filtering should remove bytes")
assert.Equal(t, full.value-sent.value, saved.value)
})

t.Run("unfiltered call records adoption only", func(t *testing.T) {
Expand Down
Loading