| 1 | // Copyright 2025 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package telemetry |
| 6 | |
| 7 | import "strings" |
| 8 | |
| 9 | // A CounterPath represents the components of a telemetry counter name. |
| 10 | // |
| 11 | // By convention, counter names follow the format path/to/counter:bucket. The |
| 12 | // CounterPath holds the '/'-separated components of this path, along with a |
| 13 | // final element representing the bucket. |
| 14 | // |
| 15 | // CounterPaths may be used to build up counters incrementally, such as when a |
| 16 | // set of observed counters shared a common prefix, to be controlled by the |
| 17 | // caller. |
| 18 | type CounterPath []string |
| 19 | |
| 20 | // FullName returns the counter name for the receiver. |
| 21 | func (p CounterPath) FullName() string { |
| 22 | if len(p) == 0 { |
| 23 | return "" |
| 24 | } |
| 25 | name := strings.Join([]string(p[:len(p)-1]), "/") |
| 26 | if bucket := p[len(p)-1]; bucket != "" { |
| 27 | name += ":" + bucket |
| 28 | } |
| 29 | return name |
| 30 | } |