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)
| 594 | // - promauto.With(reg): direct chained call |
| 595 | // - factory: variable that was assigned from promauto.With() |
| 596 | func 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: |
no outgoing calls
no test coverage detected