From 04208b9e8ab7e1fd757146e88df9f219f3442a11 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Tue, 10 Mar 2020 23:09:39 -0400 Subject: [PATCH] internal/lsp: move the telemetry package Move the lsp specific telemetry package that just declares the labels under the debug package and call it tag, to make all the usages much more readable. Change-Id: Ic89b3408dd3b8b3d914cc69d81f41b8919aaf424 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222850 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke --- internal/lsp/cache/analysis.go | 6 ++--- internal/lsp/cache/check.go | 8 +++--- internal/lsp/cache/errors.go | 6 ++--- internal/lsp/cache/external.go | 4 +-- internal/lsp/cache/load.go | 4 +-- internal/lsp/cache/mod.go | 6 ++--- internal/lsp/cache/parse.go | 4 +-- internal/lsp/cache/snapshot.go | 4 +-- internal/lsp/cache/view.go | 4 +-- internal/lsp/code_action.go | 8 +++--- internal/lsp/debug/metrics.go | 22 ++++++++-------- internal/lsp/debug/rpc.go | 8 +++--- .../telemetry.go => debug/tag/tag.go} | 5 ++-- internal/lsp/diagnostics.go | 8 +++--- internal/lsp/generate.go | 4 +-- internal/lsp/highlight.go | 4 +-- internal/lsp/lsprpc/telemetry.go | 26 +++++++++---------- internal/lsp/mod/code_lens.go | 4 +-- internal/lsp/mod/diagnostics.go | 8 +++--- internal/lsp/source/completion_format.go | 4 +-- internal/lsp/source/diagnostics.go | 6 ++--- internal/lsp/symbols.go | 4 +-- 22 files changed, 78 insertions(+), 79 deletions(-) rename internal/lsp/{telemetry/telemetry.go => debug/tag/tag.go} (92%) diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index 1fb346a424..a517223127 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -15,8 +15,8 @@ import ( "golang.org/x/sync/errgroup" "golang.org/x/tools/go/analysis" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -207,7 +207,7 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An } defer func() { if r := recover(); r != nil { - event.Print(ctx, fmt.Sprintf("analysis panicked: %s", r), telemetry.Package.Of(pkg.PkgPath)) + event.Print(ctx, fmt.Sprintf("analysis panicked: %s", r), tag.Package.Of(pkg.PkgPath)) data.err = errors.Errorf("analysis %s for package %s panicked: %v", analyzer.Name, pkg.PkgPath(), r) } }() @@ -343,7 +343,7 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An for _, diag := range diagnostics { srcErr, err := sourceError(ctx, fset, pkg, diag) if err != nil { - event.Error(ctx, "unable to compute analysis error position", err, event.TagOf("category", diag.Category), telemetry.Package.Of(pkg.ID())) + event.Error(ctx, "unable to compute analysis error position", err, event.TagOf("category", diag.Category), tag.Package.Of(pkg.ID())) continue } data.diagnostics = append(data.diagnostics, srcErr) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index c472b2b6e8..801c661265 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -17,8 +17,8 @@ import ( "sync" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" @@ -143,7 +143,7 @@ func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.Parse } depHandle, err := s.buildPackageHandle(ctx, depID, mode) if err != nil { - event.Error(ctx, "no dep handle", err, telemetry.Package.Of(depID)) + event.Error(ctx, "no dep handle", err, tag.Package.Of(depID)) // One bad dependency should not prevent us from checking the entire package. // Add a special key to mark a bad dependency. @@ -259,7 +259,7 @@ func (s *snapshot) parseGoHandles(ctx context.Context, files []span.URI, mode so } func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode source.ParseMode, goFiles []source.ParseGoHandle, compiledGoFiles []source.ParseGoHandle, deps map[packagePath]*packageHandle) (*pkg, error) { - ctx, done := event.StartSpan(ctx, "cache.importer.typeCheck", telemetry.Package.Of(m.id)) + ctx, done := event.StartSpan(ctx, "cache.importer.typeCheck", tag.Package.Of(m.id)) defer done() var rawErrors []error @@ -393,7 +393,7 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc for _, e := range rawErrors { srcErr, err := sourceError(ctx, fset, pkg, e) if err != nil { - event.Error(ctx, "unable to compute error positions", err, telemetry.Package.Of(pkg.ID())) + event.Error(ctx, "unable to compute error positions", err, tag.Package.Of(pkg.ID())) continue } pkg.errors = append(pkg.errors, srcErr) diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go index 23906089dc..72b6e22b79 100644 --- a/internal/lsp/cache/errors.go +++ b/internal/lsp/cache/errors.go @@ -16,9 +16,9 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -60,7 +60,7 @@ func sourceError(ctx context.Context, fset *token.FileSet, pkg *pkg, e interface kind = source.ParseError spn, err = scannerErrorRange(ctx, fset, pkg, e.Pos) if err != nil { - event.Error(ctx, "no span for scanner.Error pos", err, telemetry.Package.Of(pkg.ID())) + event.Error(ctx, "no span for scanner.Error pos", err, tag.Package.Of(pkg.ID())) spn = span.Parse(e.Pos.String()) } @@ -73,7 +73,7 @@ func sourceError(ctx context.Context, fset *token.FileSet, pkg *pkg, e interface kind = source.ParseError spn, err = scannerErrorRange(ctx, fset, pkg, e[0].Pos) if err != nil { - event.Error(ctx, "no span for scanner.Error pos", err, telemetry.Package.Of(pkg.ID())) + event.Error(ctx, "no span for scanner.Error pos", err, tag.Package.Of(pkg.ID())) spn = span.Parse(e[0].Pos.String()) } case types.Error: diff --git a/internal/lsp/cache/external.go b/internal/lsp/cache/external.go index 9f5d970cbd..806499aabb 100644 --- a/internal/lsp/cache/external.go +++ b/internal/lsp/cache/external.go @@ -9,8 +9,8 @@ import ( "io/ioutil" "os" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -48,7 +48,7 @@ func (h *nativeFileHandle) Identity() source.FileIdentity { } func (h *nativeFileHandle) Read(ctx context.Context) ([]byte, string, error) { - ctx, done := event.StartSpan(ctx, "cache.nativeFileHandle.Read", telemetry.File.Of(h.identity.URI.Filename())) + ctx, done := event.StartSpan(ctx, "cache.nativeFileHandle.Read", tag.File.Of(h.identity.URI.Filename())) _ = ctx defer done() diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 380c4fe24a..d7b5b582c2 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -12,8 +12,8 @@ import ( "strings" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/packagesinternal" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" @@ -77,7 +77,7 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) error { } sort.Strings(query) // for determinism - ctx, done := event.StartSpan(ctx, "cache.view.load", telemetry.Query.Of(query)) + ctx, done := event.StartSpan(ctx, "cache.view.load", tag.Query.Of(query)) defer done() cfg := s.Config(ctx) diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go index 18ab91aebc..a5bff23a49 100644 --- a/internal/lsp/cache/mod.go +++ b/internal/lsp/cache/mod.go @@ -16,9 +16,9 @@ import ( "golang.org/x/mod/modfile" "golang.org/x/tools/go/packages" "golang.org/x/tools/internal/gocommand" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" @@ -144,7 +144,7 @@ func (s *snapshot) ModHandle(ctx context.Context, fh source.FileHandle) source.M view: folder, } h := s.view.session.cache.store.Bind(key, func(ctx context.Context) interface{} { - ctx, done := event.StartSpan(ctx, "cache.ModHandle", telemetry.File.Of(uri)) + ctx, done := event.StartSpan(ctx, "cache.ModHandle", tag.File.Of(uri)) defer done() contents, _, err := fh.Read(ctx) @@ -317,7 +317,7 @@ func (s *snapshot) ModTidyHandle(ctx context.Context, realfh source.FileHandle) return &modData{} } - ctx, done := event.StartSpan(ctx, "cache.ModTidyHandle", telemetry.File.Of(realURI)) + ctx, done := event.StartSpan(ctx, "cache.ModTidyHandle", tag.File.Of(realURI)) defer done() realContents, _, err := realfh.Read(ctx) diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go index 6641d9968c..9b52f9e934 100644 --- a/internal/lsp/cache/parse.go +++ b/internal/lsp/cache/parse.go @@ -13,9 +13,9 @@ import ( "go/token" "reflect" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" @@ -106,7 +106,7 @@ func hashParseKeys(phs []source.ParseGoHandle) string { } func parseGo(ctx context.Context, fset *token.FileSet, fh source.FileHandle, mode source.ParseMode) *parseGoData { - ctx, done := event.StartSpan(ctx, "cache.parseGo", telemetry.File.Of(fh.Identity().URI.Filename())) + ctx, done := event.StartSpan(ctx, "cache.parseGo", tag.File.Of(fh.Identity().URI.Filename())) defer done() if fh.Identity().Kind != source.Go { diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 78d83890dc..911cecf356 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -17,8 +17,8 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -151,7 +151,7 @@ func (s *snapshot) PackageHandles(ctx context.Context, fh source.FileHandle) ([] panic("called PackageHandles on a non-Go FileHandle") } - ctx = event.Label(ctx, telemetry.File.Of(fh.Identity().URI)) + ctx = event.Label(ctx, tag.File.Of(fh.Identity().URI)) // Check if we should reload metadata for the file. We don't invalidate IDs // (though we should), so the IDs will be a better source of truth than the diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 351b1389d0..933ec406cc 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -24,8 +24,8 @@ import ( "golang.org/x/tools/internal/gocommand" "golang.org/x/tools/internal/imports" "golang.org/x/tools/internal/lsp/debug" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" @@ -792,7 +792,7 @@ func (v *view) modfileFlagExists(ctx context.Context, env []string) (bool, error // If the output is not go1.14 or an empty string, then it could be an error. lines := strings.Split(stdout.String(), "\n") if len(lines) < 2 && stdout.String() != "" { - event.Error(ctx, "unexpected stdout when checking for go1.14", errors.Errorf("%q", stdout), telemetry.Directory.Of(folder)) + event.Error(ctx, "unexpected stdout when checking for go1.14", errors.Errorf("%q", stdout), tag.Directory.Of(folder)) return false, nil } return lines[0] == "go1.14", nil diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index ebf2e33e16..7cb16c8b59 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -11,10 +11,10 @@ import ( "strings" "golang.org/x/tools/internal/imports" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/mod" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) @@ -73,7 +73,7 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara // First, add the quick fixes reported by go/analysis. qf, err := quickFixes(ctx, snapshot, fh, diagnostics) if err != nil { - event.Error(ctx, "quick fixes failed", err, telemetry.File.Of(uri)) + event.Error(ctx, "quick fixes failed", err, tag.File.Of(uri)) } codeActions = append(codeActions, qf...) @@ -97,7 +97,7 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara } actions, err := mod.SuggestedGoFixes(ctx, snapshot, fh, diagnostics) if err != nil { - event.Error(ctx, "quick fixes failed", err, telemetry.File.Of(uri)) + event.Error(ctx, "quick fixes failed", err, tag.File.Of(uri)) } if len(actions) > 0 { codeActions = append(codeActions, actions...) @@ -234,7 +234,7 @@ func quickFixes(ctx context.Context, snapshot source.Snapshot, fh source.FileHan for uri, edits := range fix.Edits { fh, err := snapshot.GetFile(uri) if err != nil { - event.Error(ctx, "no file", err, telemetry.URI.Of(uri)) + event.Error(ctx, "no file", err, tag.URI.Of(uri)) continue } action.Edit.DocumentChanges = append(action.Edit.DocumentChanges, documentChanges(fh, edits)...) diff --git a/internal/lsp/debug/metrics.go b/internal/lsp/debug/metrics.go index 7da805f031..19ac0a1f3d 100644 --- a/internal/lsp/debug/metrics.go +++ b/internal/lsp/debug/metrics.go @@ -5,7 +5,7 @@ package debug import ( - "golang.org/x/tools/internal/lsp/telemetry" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/telemetry/metric" ) @@ -18,33 +18,33 @@ var ( receivedBytes = metric.HistogramInt64{ Name: "received_bytes", Description: "Distribution of received bytes, by method.", - Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{tag.RPCDirection, tag.Method}, Buckets: bytesDistribution, - }.Record(telemetry.ReceivedBytes) + }.Record(tag.ReceivedBytes) sentBytes = metric.HistogramInt64{ Name: "sent_bytes", Description: "Distribution of sent bytes, by method.", - Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{tag.RPCDirection, tag.Method}, Buckets: bytesDistribution, - }.Record(telemetry.SentBytes) + }.Record(tag.SentBytes) latency = metric.HistogramFloat64{ Name: "latency", Description: "Distribution of latency in milliseconds, by method.", - Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{tag.RPCDirection, tag.Method}, Buckets: millisecondsDistribution, - }.Record(telemetry.Latency) + }.Record(tag.Latency) started = metric.Scalar{ Name: "started", Description: "Count of RPCs started by method.", - Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, - }.CountInt64(telemetry.Started) + Keys: []*event.Key{tag.RPCDirection, tag.Method}, + }.CountInt64(tag.Started) completed = metric.Scalar{ Name: "completed", Description: "Count of RPCs completed by method and status.", - Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method, telemetry.StatusCode}, - }.CountFloat64(telemetry.Latency) + Keys: []*event.Key{tag.RPCDirection, tag.Method, tag.StatusCode}, + }.CountFloat64(tag.Latency) ) diff --git a/internal/lsp/debug/rpc.go b/internal/lsp/debug/rpc.go index dd14b9dcef..07aed82d40 100644 --- a/internal/lsp/debug/rpc.go +++ b/internal/lsp/debug/rpc.go @@ -13,7 +13,7 @@ import ( "sort" "sync" - tlm "golang.org/x/tools/internal/lsp/telemetry" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/telemetry/metric" ) @@ -97,10 +97,10 @@ func (r *rpcs) Metric(ctx context.Context, data event.MetricData) { defer r.mu.Unlock() for i, group := range data.Groups() { set := &r.Inbound - if group.Get(tlm.RPCDirection) == tlm.Outbound { + if group.Get(tag.RPCDirection) == tag.Outbound { set = &r.Outbound } - method, ok := group.Get(tlm.Method).(string) + method, ok := group.Get(tag.Method).(string) if !ok { continue } @@ -119,7 +119,7 @@ func (r *rpcs) Metric(ctx context.Context, data event.MetricData) { case started: stats.Started = data.(*metric.Int64Data).Rows[i] case completed: - status, ok := group.Get(tlm.StatusCode).(string) + status, ok := group.Get(tag.StatusCode).(string) if !ok { log.Printf("Not status... %v", group) continue diff --git a/internal/lsp/telemetry/telemetry.go b/internal/lsp/debug/tag/tag.go similarity index 92% rename from internal/lsp/telemetry/telemetry.go rename to internal/lsp/debug/tag/tag.go index 32d92a3991..d4e9219de4 100644 --- a/internal/lsp/telemetry/telemetry.go +++ b/internal/lsp/debug/tag/tag.go @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package telemetry provides the hooks and adapters to allow use of telemetry -// throughout gopls. -package telemetry +// Package tag provides the labels used for telemetry throughout gopls. +package tag import ( "golang.org/x/tools/internal/telemetry/event" diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index 44e7b8e0a7..5b9b5b93bc 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -10,10 +10,10 @@ import ( "strings" "sync" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/mod" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/xcontext" ) @@ -98,7 +98,7 @@ func (s *Server) diagnose(ctx context.Context, snapshot source.Snapshot, alwaysA } s.showedInitialErrorMu.Unlock() - event.Error(ctx, "diagnose: no workspace packages", err, telemetry.Snapshot.Of(snapshot.ID()), telemetry.Directory.Of(snapshot.View().Folder)) + event.Error(ctx, "diagnose: no workspace packages", err, tag.Snapshot.Of(snapshot.ID()), tag.Directory.Of(snapshot.View().Folder)) return nil } for _, ph := range wsPackages { @@ -124,7 +124,7 @@ func (s *Server) diagnose(ctx context.Context, snapshot source.Snapshot, alwaysA return } if err != nil { - event.Error(ctx, "diagnose: could not generate diagnostics for package", err, telemetry.Snapshot.Of(snapshot.ID()), telemetry.Package.Of(ph.ID())) + event.Error(ctx, "diagnose: could not generate diagnostics for package", err, tag.Snapshot.Of(snapshot.ID()), tag.Package.Of(ph.ID())) return } reportsMu.Lock() @@ -201,7 +201,7 @@ func (s *Server) publishReports(ctx context.Context, snapshot source.Snapshot, r Version: key.id.Version, }); err != nil { if ctx.Err() == nil { - event.Error(ctx, "publishReports: failed to deliver diagnostic", err, telemetry.URI.Of(key.id.URI)) + event.Error(ctx, "publishReports: failed to deliver diagnostic", err, tag.URI.Of(key.id.URI)) } continue } diff --git a/internal/lsp/generate.go b/internal/lsp/generate.go index 440ab28e14..08840aa986 100644 --- a/internal/lsp/generate.go +++ b/internal/lsp/generate.go @@ -12,8 +12,8 @@ import ( "strconv" "golang.org/x/tools/internal/gocommand" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) @@ -60,7 +60,7 @@ type eventWriter struct { } func (ew *eventWriter) Write(p []byte) (n int, err error) { - event.Print(ew.ctx, string(p), telemetry.Operation.Of("generate")) + event.Print(ew.ctx, string(p), tag.Operation.Of("generate")) return len(p), nil } diff --git a/internal/lsp/highlight.go b/internal/lsp/highlight.go index 5d31bfe7cf..9ff37e99f9 100644 --- a/internal/lsp/highlight.go +++ b/internal/lsp/highlight.go @@ -7,9 +7,9 @@ package lsp import ( "context" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" ) @@ -20,7 +20,7 @@ func (s *Server) documentHighlight(ctx context.Context, params *protocol.Documen } rngs, err := source.Highlight(ctx, snapshot, fh, params.Position) if err != nil { - event.Error(ctx, "no highlight", err, telemetry.URI.Of(params.TextDocument.URI)) + event.Error(ctx, "no highlight", err, tag.URI.Of(params.TextDocument.URI)) } return toProtocolHighlight(rngs), nil } diff --git a/internal/lsp/lsprpc/telemetry.go b/internal/lsp/lsprpc/telemetry.go index bc6aaa9430..1599a1ed34 100644 --- a/internal/lsp/lsprpc/telemetry.go +++ b/internal/lsp/lsprpc/telemetry.go @@ -10,7 +10,7 @@ import ( "time" "golang.org/x/tools/internal/jsonrpc2" - "golang.org/x/tools/internal/lsp/telemetry" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/telemetry/event" ) @@ -39,16 +39,16 @@ func (h telemetryHandler) Request(ctx context.Context, conn *jsonrpc2.Conn, dire payload: r.Params, } ctx = context.WithValue(ctx, statsKey, stats) - mode := telemetry.Outbound + mode := tag.Outbound if direction == jsonrpc2.Receive { - mode = telemetry.Inbound + mode = tag.Inbound } ctx, stats.close = event.StartSpan(ctx, r.Method, - telemetry.Method.Of(r.Method), - telemetry.RPCDirection.Of(mode), - telemetry.RPCID.Of(r.ID), + tag.Method.Of(r.Method), + tag.RPCDirection.Of(mode), + tag.RPCID.Of(r.ID), ) - telemetry.Started.Record(ctx, 1) + tag.Started.Record(ctx, 1) _, stats.delivering = event.StartSpan(ctx, "queued") return ctx } @@ -60,23 +60,23 @@ func (h telemetryHandler) Response(ctx context.Context, conn *jsonrpc2.Conn, dir func (h telemetryHandler) Done(ctx context.Context, err error) { stats := h.getStats(ctx) if err != nil { - ctx = event.Label(ctx, telemetry.StatusCode.Of("ERROR")) + ctx = event.Label(ctx, tag.StatusCode.Of("ERROR")) } else { - ctx = event.Label(ctx, telemetry.StatusCode.Of("OK")) + ctx = event.Label(ctx, tag.StatusCode.Of("OK")) } elapsedTime := time.Since(stats.start) latencyMillis := float64(elapsedTime) / float64(time.Millisecond) - telemetry.Latency.Record(ctx, latencyMillis) + tag.Latency.Record(ctx, latencyMillis) stats.close() } func (h telemetryHandler) Read(ctx context.Context, bytes int64) context.Context { - telemetry.SentBytes.Record(ctx, bytes) + tag.SentBytes.Record(ctx, bytes) return ctx } func (h telemetryHandler) Wrote(ctx context.Context, bytes int64) context.Context { - telemetry.ReceivedBytes.Record(ctx, bytes) + tag.ReceivedBytes.Record(ctx, bytes) return ctx } @@ -88,7 +88,7 @@ func (h telemetryHandler) Error(ctx context.Context, err error) { func (h telemetryHandler) getStats(ctx context.Context) *rpcStats { stats, ok := ctx.Value(statsKey).(*rpcStats) if !ok || stats == nil { - method, ok := ctx.Value(telemetry.Method).(string) + method, ok := ctx.Value(tag.Method).(string) if !ok { method = "???" } diff --git a/internal/lsp/mod/code_lens.go b/internal/lsp/mod/code_lens.go index 241e48d2fd..7f76a5bd8f 100644 --- a/internal/lsp/mod/code_lens.go +++ b/internal/lsp/mod/code_lens.go @@ -6,9 +6,9 @@ import ( "strings" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" ) @@ -22,7 +22,7 @@ func CodeLens(ctx context.Context, snapshot source.Snapshot, uri span.URI) ([]pr if uri != realURI { return nil, nil } - ctx, done := event.StartSpan(ctx, "mod.CodeLens", telemetry.File.Of(realURI)) + ctx, done := event.StartSpan(ctx, "mod.CodeLens", tag.File.Of(realURI)) defer done() fh, err := snapshot.GetFile(realURI) diff --git a/internal/lsp/mod/diagnostics.go b/internal/lsp/mod/diagnostics.go index 1ce54be8ec..ac72e7a3a7 100644 --- a/internal/lsp/mod/diagnostics.go +++ b/internal/lsp/mod/diagnostics.go @@ -12,9 +12,9 @@ import ( "regexp" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" ) @@ -27,7 +27,7 @@ func Diagnostics(ctx context.Context, snapshot source.Snapshot) (map[source.File return nil, nil, nil } - ctx, done := event.StartSpan(ctx, "mod.Diagnostics", telemetry.File.Of(realURI)) + ctx, done := event.StartSpan(ctx, "mod.Diagnostics", tag.File.Of(realURI)) defer done() realfh, err := snapshot.GetFile(realURI) @@ -97,7 +97,7 @@ func SuggestedFixes(ctx context.Context, snapshot source.Snapshot, realfh source for uri, edits := range fix.Edits { fh, err := snapshot.GetFile(uri) if err != nil { - event.Error(ctx, "no file", err, telemetry.URI.Of(uri)) + event.Error(ctx, "no file", err, tag.URI.Of(uri)) continue } action.Edit.DocumentChanges = append(action.Edit.DocumentChanges, protocol.TextDocumentEdit{ @@ -126,7 +126,7 @@ func SuggestedGoFixes(ctx context.Context, snapshot source.Snapshot, gofh source return nil, nil } - ctx, done := event.StartSpan(ctx, "mod.SuggestedGoFixes", telemetry.File.Of(realURI)) + ctx, done := event.StartSpan(ctx, "mod.SuggestedGoFixes", tag.File.Of(realURI)) defer done() realfh, err := snapshot.GetFile(realURI) diff --git a/internal/lsp/source/completion_format.go b/internal/lsp/source/completion_format.go index 815cdd917f..5144ba561e 100644 --- a/internal/lsp/source/completion_format.go +++ b/internal/lsp/source/completion_format.go @@ -14,9 +14,9 @@ import ( "strings" "golang.org/x/tools/internal/imports" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/snippet" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -196,7 +196,7 @@ func (c *completer) item(cand candidate) (CompletionItem, error) { } hover, err := ident.Hover(c.ctx) if err != nil { - event.Error(c.ctx, "failed to find Hover", err, telemetry.URI.Of(uri)) + event.Error(c.ctx, "failed to find Hover", err, tag.URI.Of(uri)) return item, nil } item.Documentation = hover.Synopsis diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index d308ac3e62..b6ca43c8cd 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -13,8 +13,8 @@ import ( "golang.org/x/mod/modfile" "golang.org/x/tools/go/analysis" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" @@ -128,7 +128,7 @@ func Diagnostics(ctx context.Context, snapshot Snapshot, ph PackageHandle, missi if ctx.Err() != nil { return nil, warn, ctx.Err() } - event.Error(ctx, "failed to run analyses", err, telemetry.Package.Of(ph.ID())) + event.Error(ctx, "failed to run analyses", err, tag.Package.Of(ph.ID())) } } return reports, warn, nil @@ -163,7 +163,7 @@ type diagnosticSet struct { } func diagnostics(ctx context.Context, snapshot Snapshot, reports map[FileIdentity][]Diagnostic, pkg Package, hasMissingDeps bool) (bool, error) { - ctx, done := event.StartSpan(ctx, "source.diagnostics", telemetry.Package.Of(pkg.ID())) + ctx, done := event.StartSpan(ctx, "source.diagnostics", tag.Package.Of(pkg.ID())) _ = ctx // circumvent SA4006 defer done() diff --git a/internal/lsp/symbols.go b/internal/lsp/symbols.go index 5f6824a297..11e89e163a 100644 --- a/internal/lsp/symbols.go +++ b/internal/lsp/symbols.go @@ -7,9 +7,9 @@ package lsp import ( "context" + "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/telemetry/event" ) @@ -23,7 +23,7 @@ func (s *Server) documentSymbol(ctx context.Context, params *protocol.DocumentSy } docSymbols, err := source.DocumentSymbols(ctx, snapshot, fh) if err != nil { - event.Error(ctx, "DocumentSymbols failed", err, telemetry.URI.Of(fh.Identity().URI)) + event.Error(ctx, "DocumentSymbols failed", err, tag.URI.Of(fh.Identity().URI)) return []interface{}{}, nil } // Convert the symbols to an interface array.