Skip to content

Commit 83a2a65

Browse files
committed
add example showing that using pointer to labels struct is fine
Signed-off-by: Eugene <[email protected]>
1 parent 6724aba commit 83a2a65

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

prometheus/promsafe/safe_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ func ExampleNewCounterVecT_promauto_global_migrated() {
118118
// Output:
119119
}
120120

121+
func ExampleNewCounterVecT_pointer_to_labels_promauto() {
122+
// It's possible to use pointer to labels struct
123+
myReg := prometheus.NewRegistry()
124+
125+
counterOpts := prometheus.CounterOpts{
126+
Name: "items_counted_detailed_ptr",
127+
}
128+
129+
type MyLabels struct {
130+
promsafe.StructLabelProvider
131+
EventType string
132+
Source string
133+
}
134+
c := promsafe.WithAuto[*MyLabels](myReg).NewCounterVecT(counterOpts)
135+
136+
c.With(&MyLabels{
137+
EventType: "reservation", Source: "source1",
138+
}).Inc()
139+
140+
// Output:
141+
}
142+
121143
func ExampleNewCounterVecT_single_label_manual() {
122144
// Manually registering with a single label
123145
// Example of usage of shorthand: no structs no generics, but one string only

0 commit comments

Comments
 (0)