mirror of
https://github.com/golang/go
synced 2024-09-30 20:28:32 -06:00
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 <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
9dec35b5f8
commit
04208b9e8a
6
internal/lsp/cache/analysis.go
vendored
6
internal/lsp/cache/analysis.go
vendored
@ -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)
|
||||
|
8
internal/lsp/cache/check.go
vendored
8
internal/lsp/cache/check.go
vendored
@ -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)
|
||||
|
6
internal/lsp/cache/errors.go
vendored
6
internal/lsp/cache/errors.go
vendored
@ -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:
|
||||
|
4
internal/lsp/cache/external.go
vendored
4
internal/lsp/cache/external.go
vendored
@ -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()
|
||||
|
||||
|
4
internal/lsp/cache/load.go
vendored
4
internal/lsp/cache/load.go
vendored
@ -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)
|
||||
|
6
internal/lsp/cache/mod.go
vendored
6
internal/lsp/cache/mod.go
vendored
@ -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)
|
||||
|
4
internal/lsp/cache/parse.go
vendored
4
internal/lsp/cache/parse.go
vendored
@ -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 {
|
||||
|
4
internal/lsp/cache/snapshot.go
vendored
4
internal/lsp/cache/snapshot.go
vendored
@ -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
|
||||
|
4
internal/lsp/cache/view.go
vendored
4
internal/lsp/cache/view.go
vendored
@ -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
|
||||
|
@ -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)...)
|
||||
|
@ -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)
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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"
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 = "???"
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user