Skip to content

Commit

Permalink
gopls: enable telemetry uploading only with 'serve'
Browse files Browse the repository at this point in the history
Fixes golang/go#64425

Change-Id: Ic27115a7034020313109f8268b4656f8fef66fb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/545475
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
hyangah authored and gopherbot committed Nov 28, 2023
1 parent eee280c commit 1896879
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions gopls/internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"golang.org/x/tools/gopls/internal/lsp/debug"
"golang.org/x/tools/gopls/internal/lsp/lsprpc"
"golang.org/x/tools/gopls/internal/lsp/protocol"
"golang.org/x/tools/gopls/internal/telemetry"
"golang.org/x/tools/internal/fakenet"
"golang.org/x/tools/internal/jsonrpc2"
"golang.org/x/tools/internal/tool"
Expand Down Expand Up @@ -77,6 +78,8 @@ func (s *Serve) remoteArgs(network, address string) []string {
// Run configures a server based on the flags, and then runs it.
// It blocks until the server shuts down.
func (s *Serve) Run(ctx context.Context, args ...string) error {
telemetry.Upload()

if len(args) > 0 {
return tool.CommandLineErrorf("server does not take arguments, got %v", args)
}
Expand Down
6 changes: 2 additions & 4 deletions gopls/internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ func SetMode(mode string) error {
return telemetry.SetMode(mode)
}

// Start starts telemetry instrumentation.
func Start() {
counter.Open()
// upload only once at startup, hoping that users restart gopls often.
// Upload starts a goroutine for telemetry upload.
func Upload() {
go upload.Run(nil)
}

Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/telemetry/telemetry_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func SetMode(mode string) error {
return nil
}

func Start() {
func Upload() {
}

func RecordClientInfo(params *protocol.ParamInitialize) {
Expand Down
4 changes: 2 additions & 2 deletions gopls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"context"
"os"

"golang.org/x/telemetry/counter"
"golang.org/x/tools/gopls/internal/cmd"
"golang.org/x/tools/gopls/internal/hooks"
"golang.org/x/tools/gopls/internal/telemetry"
"golang.org/x/tools/internal/tool"
)

func main() {
telemetry.Start()
counter.Open() // Enable telemetry counter writing.
ctx := context.Background()
tool.Main(ctx, cmd.New("gopls", "", nil, hooks.Options), os.Args[1:])
}

0 comments on commit 1896879

Please sign in to comment.