Skip to content

Commit 75f6f9c

Browse files
hyangahgopherbot
authored andcommitted
gopls/internal/bug: add gopls/bug telemetry counter
This counter (tentatively named 'gopls/bug') will track and report the number of `report` calls. Since bug.Report* can be called in a type loop, we increment the stack counter only where this is the first exemplar, and after getting out of the critical section. Change-Id: I42ee385bd69bc148454a82c98f7d623d5c803907 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513100 Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Hyang-Ah Hana Kim <[email protected]>
1 parent 4b271f9 commit 75f6f9c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

gopls/internal/bug/bug.go

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"sort"
1919
"sync"
2020
"time"
21+
22+
"golang.org/x/telemetry/counter"
2123
)
2224

2325
// PanicOnBugs controls whether to panic when bugs are reported.
@@ -63,6 +65,8 @@ func Report(description string) {
6365
report(description)
6466
}
6567

68+
var bugReport = counter.NewStack("gopls/bug", 16)
69+
6670
func report(description string) {
6771
_, file, line, ok := runtime.Caller(2) // all exported reporting functions call report directly
6872

@@ -84,17 +88,22 @@ func report(description string) {
8488
AtTime: time.Now(),
8589
}
8690

91+
newBug := false
8792
mu.Lock()
8893
if _, ok := exemplars[key]; !ok {
8994
if exemplars == nil {
9095
exemplars = make(map[string]Bug)
9196
}
9297
exemplars[key] = bug // capture one exemplar per key
98+
newBug = true
9399
}
94100
hh := handlers
95101
handlers = nil
96102
mu.Unlock()
97103

104+
if newBug {
105+
bugReport.Inc()
106+
}
98107
// Call the handlers outside the critical section since a
99108
// handler may itself fail and call bug.Report. Since handlers
100109
// are one-shot, the inner call should be trivial.

0 commit comments

Comments
 (0)