Skip to content

Commit

Permalink
gopls/internal/bug: add gopls/bug telemetry counter
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
hyangah authored and gopherbot committed Aug 1, 2023
1 parent 4b271f9 commit 75f6f9c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gopls/internal/bug/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"sort"
"sync"
"time"

"golang.org/x/telemetry/counter"
)

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

var bugReport = counter.NewStack("gopls/bug", 16)

func report(description string) {
_, file, line, ok := runtime.Caller(2) // all exported reporting functions call report directly

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

newBug := false
mu.Lock()
if _, ok := exemplars[key]; !ok {
if exemplars == nil {
exemplars = make(map[string]Bug)
}
exemplars[key] = bug // capture one exemplar per key
newBug = true
}
hh := handlers
handlers = nil
mu.Unlock()

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

0 comments on commit 75f6f9c

Please sign in to comment.