Skip to content

Commit 4b271f9

Browse files
committed
gopls: add gopls/client telemetry counters
These counters are incremented once per session when the LSP initialize message is received. This cl adds a new dependency on x/telemetry. Note that writing to the disk will be enabled when GOPLS_TELEMETRY_EXP is set. We plan to remove this condition once we are ready. Updates golang/go#61038 Change-Id: Ibb8ebbd039ab5ffbaa869dee01bee0ba5450f350 Reviewed-on: https://go-review.googlesource.com/c/tools/+/506635 Reviewed-by: Jamal Carvalho <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
1 parent d0b18e2 commit 4b271f9

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

gopls/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
golang.org/x/mod v0.12.0
1111
golang.org/x/sync v0.3.0
1212
golang.org/x/sys v0.10.0
13+
golang.org/x/telemetry v0.0.0-20230728182230-e84a26264b60
1314
golang.org/x/text v0.11.0
1415
golang.org/x/tools v0.6.0
1516
golang.org/x/vuln v0.0.0-20230110180137-6ad3e3d07815

gopls/go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2
5454
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
5555
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5656
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
57+
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5758
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
5859
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5960
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -74,6 +75,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7475
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7576
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
7677
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
78+
golang.org/x/telemetry v0.0.0-20230728182230-e84a26264b60 h1:OCiXqf7/gdoaS7dKppAtPxi783Ke/JIb+r20ZYGiEFg=
79+
golang.org/x/telemetry v0.0.0-20230728182230-e84a26264b60/go.mod h1:kO7uNSGGmqCHII6C0TYfaLwSBIfcyhj53//nu0+Fy4A=
7780
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
7881
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
7982
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=

gopls/internal/lsp/general.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"golang.org/x/tools/gopls/internal/lsp/protocol"
2323
"golang.org/x/tools/gopls/internal/lsp/source"
2424
"golang.org/x/tools/gopls/internal/span"
25+
"golang.org/x/tools/gopls/internal/telemetry"
2526
"golang.org/x/tools/internal/event"
2627
"golang.org/x/tools/internal/jsonrpc2"
2728
)
@@ -30,6 +31,8 @@ func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitializ
3031
ctx, done := event.Start(ctx, "lsp.Server.initialize")
3132
defer done()
3233

34+
telemetry.RecordClientInfo(params)
35+
3336
s.stateMu.Lock()
3437
if s.state >= serverInitializing {
3538
defer s.stateMu.Unlock()

gopls/internal/telemetry/telemetry.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package telemetry
6+
7+
import (
8+
"os"
9+
10+
"golang.org/x/telemetry/counter"
11+
"golang.org/x/tools/gopls/internal/lsp/protocol"
12+
)
13+
14+
// Start starts telemetry instrumentation.
15+
func Start() {
16+
if os.Getenv("GOPLS_TELEMETRY_EXP") != "" {
17+
counter.Open()
18+
// TODO: add upload logic.
19+
}
20+
}
21+
22+
// RecordClientInfo records gopls client info.
23+
func RecordClientInfo(params *protocol.ParamInitialize) {
24+
client := "gopls/client:other"
25+
if params != nil && params.ClientInfo != nil {
26+
switch params.ClientInfo.Name {
27+
case "Visual Studio Code":
28+
client = "gopls/client:vscode"
29+
case "VSCodium":
30+
client = "gopls/client:vscodium"
31+
case "code-server":
32+
// https://github.com/coder/code-server/blob/3cb92edc76ecc2cfa5809205897d93d4379b16a6/ci/build/build-vscode.sh#L19
33+
client = "gopls/client:code-server"
34+
case "Eglot":
35+
// https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-03/msg00954.html
36+
client = "gopls/client:eglot"
37+
case "govim":
38+
// https://github.com/govim/govim/pull/1189
39+
client = "gopls/client:govim"
40+
case "Neovim":
41+
// https://github.com/neovim/neovim/blob/42333ea98dfcd2994ee128a3467dfe68205154cd/runtime/lua/vim/lsp.lua#L1361
42+
client = "gopls/client:neovim"
43+
case "coc.nvim":
44+
// https://github.com/neoclide/coc.nvim/blob/3dc6153a85ed0f185abec1deb972a66af3fbbfb4/src/language-client/client.ts#L994
45+
client = "gopls/client:coc.nvim"
46+
case "Sublime Text LSP":
47+
// https://github.com/sublimelsp/LSP/blob/e608f878e7e9dd34aabe4ff0462540fadcd88fcc/plugin/core/sessions.py#L493
48+
client = "gopls/client:sublimetext"
49+
}
50+
}
51+
counter.Inc(client)
52+
}

gopls/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import (
1919

2020
"golang.org/x/tools/gopls/internal/hooks"
2121
"golang.org/x/tools/gopls/internal/lsp/cmd"
22+
"golang.org/x/tools/gopls/internal/telemetry"
2223
"golang.org/x/tools/internal/tool"
2324
)
2425

2526
func main() {
27+
telemetry.Start()
2628
ctx := context.Background()
2729
tool.Main(ctx, cmd.New("gopls", "", nil, hooks.Options), os.Args[1:])
2830
}

0 commit comments

Comments
 (0)