add example showing that using pointer to labels struct is fine

Signed-off-by: Eugene <eugene@amberpixels.io>
This commit is contained in:
Eugene 2024-09-20 00:32:13 +03:00
parent 6724abaa0b
commit 83a2a655ae
No known key found for this signature in database
GPG Key ID: 51AC89611A689305
1 changed files with 22 additions and 0 deletions

View File

@ -118,6 +118,28 @@ func ExampleNewCounterVecT_promauto_global_migrated() {
// Output: // Output:
} }
func ExampleNewCounterVecT_pointer_to_labels_promauto() {
// It's possible to use pointer to labels struct
myReg := prometheus.NewRegistry()
counterOpts := prometheus.CounterOpts{
Name: "items_counted_detailed_ptr",
}
type MyLabels struct {
promsafe.StructLabelProvider
EventType string
Source string
}
c := promsafe.WithAuto[*MyLabels](myReg).NewCounterVecT(counterOpts)
c.With(&MyLabels{
EventType: "reservation", Source: "source1",
}).Inc()
// Output:
}
func ExampleNewCounterVecT_single_label_manual() { func ExampleNewCounterVecT_single_label_manual() {
// Manually registering with a single label // Manually registering with a single label
// Example of usage of shorthand: no structs no generics, but one string only // Example of usage of shorthand: no structs no generics, but one string only