forked from github/github-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfields_telemetry.go
More file actions
54 lines (48 loc) · 2.08 KB
/
Copy pathfields_telemetry.go
File metadata and controls
54 lines (48 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package github
import (
"context"
"strconv"
)
// Metric names for the optional `fields` response-filtering feature. They let a
// dashboard answer two questions on real traffic: how often the model actually
// filters (adoption) and how many bytes that filtering removes (effectiveness).
//
// Cardinality is kept deliberately low: the only tags ever attached are `tool`
// (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"
)
// recordFieldsUsage emits telemetry for a single call to a tool that supports
// the `fields` parameter. It is best-effort: the local server wires a no-op
// metrics sink, while hosted deployments inject a real sink.
//
// 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. 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 {
return
}
m.Increment(metricFieldsToolCall, map[string]string{
"tool": tool,
"filtered": strconv.FormatBool(filtered),
})
if !filtered {
return
}
toolTag := map[string]string{"tool": tool}
m.Counter(metricFieldsBytesFull, toolTag, int64(fullBytes))
m.Counter(metricFieldsBytesSent, toolTag, int64(sentBytes))
}