Skip to content

Commit b3c5d10

Browse files
findleyrgopherbot
authored andcommitted
gopls: record telemetry counters for settings that are used
Instrument telemetry recording which settings are passed to gopls. In some cases, this merely records whether settings were set. In others, it records buckets for the setting value. Fixes golang/go#71285 Change-Id: I820318fe9cf1b05accb3105e5e2d6ddc3c5e768f Reviewed-on: https://go-review.googlesource.com/c/tools/+/648416 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent d2585c4 commit b3c5d10

File tree

7 files changed

+262
-82
lines changed

7 files changed

+262
-82
lines changed

gopls/internal/cache/session_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ replace (
337337
for _, f := range test.folders {
338338
opts := settings.DefaultOptions()
339339
if f.options != nil {
340-
for _, err := range opts.Set(f.options(dir)) {
340+
_, errs := opts.Set(f.options(dir))
341+
for _, err := range errs {
341342
t.Fatal(err)
342343
}
343344
}

gopls/internal/server/general.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"golang.org/x/tools/gopls/internal/protocol"
2929
"golang.org/x/tools/gopls/internal/protocol/semtok"
3030
"golang.org/x/tools/gopls/internal/settings"
31+
"golang.org/x/tools/gopls/internal/telemetry"
3132
"golang.org/x/tools/gopls/internal/util/bug"
3233
"golang.org/x/tools/gopls/internal/util/goversion"
3334
"golang.org/x/tools/gopls/internal/util/moremaps"
@@ -74,7 +75,11 @@ func (s *server) Initialize(ctx context.Context, params *protocol.ParamInitializ
7475
// TODO(rfindley): eliminate this defer.
7576
defer func() { s.SetOptions(options) }()
7677

77-
s.handleOptionErrors(ctx, options.Set(params.InitializationOptions))
78+
// Process initialization options.
79+
{
80+
res, errs := options.Set(params.InitializationOptions)
81+
s.handleOptionResult(ctx, res, errs)
82+
}
7883
options.ForClientCapabilities(params.ClientInfo, params.Capabilities)
7984

8085
if options.ShowBugReports {
@@ -541,7 +546,8 @@ func (s *server) fetchFolderOptions(ctx context.Context, folder protocol.Documen
541546

542547
opts = opts.Clone()
543548
for _, config := range configs {
544-
s.handleOptionErrors(ctx, opts.Set(config))
549+
res, errs := opts.Set(config)
550+
s.handleOptionResult(ctx, res, errs)
545551
}
546552
return opts, nil
547553
}
@@ -555,7 +561,12 @@ func (s *server) eventuallyShowMessage(ctx context.Context, msg *protocol.ShowMe
555561
s.notifications = append(s.notifications, msg)
556562
}
557563

558-
func (s *server) handleOptionErrors(ctx context.Context, optionErrors []error) {
564+
func (s *server) handleOptionResult(ctx context.Context, applied []telemetry.CounterPath, optionErrors []error) {
565+
for _, path := range applied {
566+
path = append(settings.CounterPath{"gopls", "setting"}, path...)
567+
counter.Inc(path.FullName())
568+
}
569+
559570
var warnings, errs []string
560571
for _, err := range optionErrors {
561572
if err == nil {

0 commit comments

Comments
 (0)