MCPcopy
hub / github.com/colbymchenry/codegraph / recordUsage

Method recordUsage

src/telemetry/index.ts:236–253  ·  view source on GitHub ↗

In-memory increment — safe on the MCP tool-call hot path.

(kind: UsageKind, name: string, ok: boolean, client?: ClientInfo)

Source from the content-addressed store, hash-verified

234
235 /** In-memory increment — safe on the MCP tool-call hot path. */
236 recordUsage(kind: UsageKind, name: string, ok: boolean, client?: ClientInfo): void {
237 if (!this.isEnabled()) return;
238 const day = this.utcDay();
239 const cn = client?.name?.slice(0, 64);
240 const cv = client?.version?.slice(0, 32);
241 const key = [day, kind, name, cn ?? '', cv ?? ''].join('');
242 const line = this.counts.get(key);
243 if (line) {
244 line.c += 1;
245 if (!ok) line.e += 1;
246 } else {
247 const fresh: CountLine = { v: SCHEMA_VERSION, d: day, k: kind, n: name.slice(0, 64), c: 1, e: ok ? 0 : 1 };
248 if (cn) fresh.cn = cn;
249 if (cv) fresh.cv = cv;
250 this.counts.set(key, fresh);
251 }
252 this.ensureExitHook();
253 }
254
255 /** install / index / uninstall — buffered like everything else. */
256 recordLifecycle(event: LifecycleEvent, props: Record<string, unknown>): void {

Callers 4

handleLocallyFunction · 0.80
handleToolsCallMethod · 0.80
mainFunction · 0.80
telemetry.test.tsFile · 0.80

Calls 6

isEnabledMethod · 0.95
utcDayMethod · 0.95
ensureExitHookMethod · 0.95
joinMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected