MCPcopy Create free account
hub / github.com/coder/coder / isPromautoCall

Function isPromautoCall

scripts/metricsdocgen/scanner/scanner.go:596–621  ·  view source on GitHub ↗

isPromautoCall checks if an expression is a promauto factory call. Matches: - promauto.With(reg): direct chained call - factory: variable that was assigned from promauto.With()

(expr ast.Expr)

Source from the content-addressed store, hash-verified

594// - promauto.With(reg): direct chained call
595// - factory: variable that was assigned from promauto.With()
596func isPromautoCall(expr ast.Expr) bool {
597 switch e := expr.(type) {
598 case *ast.CallExpr:
599 // Check for promauto.With(reg).New*()
600 sel, ok := e.Fun.(*ast.SelectorExpr)
601 if !ok {
602 return false
603 }
604 ident, ok := sel.X.(*ast.Ident)
605 if !ok {
606 return false
607 }
608 // Match calls that are exactly "promauto.With(...)". This checks the local
609 // package identifier, not the resolved import path. If the promauto package
610 // is imported with an alias, this will not match.
611 return ident.Name == "promauto" && sel.Sel.Name == "With"
612 case *ast.Ident:
613 // Heuristic: assume any identifier that isn't "prometheus" used as a
614 // receiver for New*() methods is a promauto factory variable.
615 // This works for the codebase patterns (e.g., factory.NewGaugeVec(...))
616 // but could false-positive on other receivers. Downstream extractOpts
617 // validation prevents incorrect metrics from being emitted.
618 return e.Name != "prometheus"
619 }
620 return false
621}
622
623// extractPromautoMetric extracts a metric from promauto.With().New*() or factory.New*() calls.
624// Supported patterns:

Callers 1

extractPromautoMetricFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected