From c001e47e7f00e86e2589be2312a5f197de244238 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Tue, 9 Jul 2019 20:16:21 -0400 Subject: [PATCH] internal/lsp: extra telemetry tagging of files and packages Change-Id: Ia9a8fb5dcfb74e86b9366849810dd3edc1f898dd Reviewed-on: https://go-review.googlesource.com/c/tools/+/186918 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/cache/check.go | 2 +- internal/lsp/cache/external.go | 3 ++- internal/lsp/cache/load.go | 3 +++ internal/lsp/cache/parse.go | 3 ++- internal/lsp/cmd/serve.go | 18 ++++++++++++------ internal/lsp/source/diagnostics.go | 6 +++++- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 67e29a9289..f2f5a4c30f 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -95,7 +95,7 @@ func (imp *importer) getPkg(ctx context.Context, id packageID) (*pkg, error) { } func (imp *importer) typeCheck(ctx context.Context, id packageID) (*pkg, error) { - ctx, done := trace.StartSpan(ctx, "cache.importer.typeCheck") + ctx, done := trace.StartSpan(ctx, "cache.importer.typeCheck", telemetry.Package.Of(id)) defer done() meta, ok := imp.view.mcache.packages[id] if !ok { diff --git a/internal/lsp/cache/external.go b/internal/lsp/cache/external.go index 357a1dad9d..b52899ba7f 100644 --- a/internal/lsp/cache/external.go +++ b/internal/lsp/cache/external.go @@ -10,6 +10,7 @@ import ( "os" "golang.org/x/tools/internal/lsp/source" + "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/lsp/telemetry/trace" "golang.org/x/tools/internal/span" ) @@ -51,7 +52,7 @@ func (h *nativeFileHandle) Kind() source.FileKind { } func (h *nativeFileHandle) Read(ctx context.Context) ([]byte, string, error) { - ctx, done := trace.StartSpan(ctx, "cache.nativeFileHandle.Read") + ctx, done := trace.StartSpan(ctx, "cache.nativeFileHandle.Read", telemetry.File.Of(h.identity.URI.Filename())) defer done() //TODO: this should fail if the version is not the same as the handle data, err := ioutil.ReadFile(h.identity.URI.Filename()) diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 614c9d6bbd..cde9e67cf4 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -13,6 +13,7 @@ import ( "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/lsp/telemetry/log" "golang.org/x/tools/internal/lsp/telemetry/tag" + "golang.org/x/tools/internal/lsp/telemetry/trace" "golang.org/x/tools/internal/span" ) @@ -87,6 +88,8 @@ func (v *view) checkMetadata(ctx context.Context, f *goFile) (map[packageID]*met return nil, nil, ctx.Err() } + ctx, done := trace.StartSpan(ctx, "packages.Load", telemetry.File.Of(f.filename())) + defer done() pkgs, err := packages.Load(v.Config(ctx), fmt.Sprintf("file=%s", f.filename())) if len(pkgs) == 0 { if err == nil { diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go index 6895ab61a1..5be9c55bf8 100644 --- a/internal/lsp/cache/parse.go +++ b/internal/lsp/cache/parse.go @@ -13,6 +13,7 @@ import ( "go/token" "golang.org/x/tools/internal/lsp/source" + "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/lsp/telemetry/trace" "golang.org/x/tools/internal/memoize" ) @@ -74,7 +75,7 @@ func (h *parseGoHandle) Parse(ctx context.Context) (*ast.File, error) { } func parseGo(ctx context.Context, c *cache, fh source.FileHandle, mode source.ParseMode) (*ast.File, error) { - ctx, done := trace.StartSpan(ctx, "cache.parseGo") + ctx, done := trace.StartSpan(ctx, "cache.parseGo", telemetry.File.Of(fh.Identity().URI.Filename())) defer done() buf, _, err := fh.Read(ctx) if err != nil { diff --git a/internal/lsp/cmd/serve.go b/internal/lsp/cmd/serve.go index 39cf087eda..86739ede77 100644 --- a/internal/lsp/cmd/serve.go +++ b/internal/lsp/cmd/serve.go @@ -124,12 +124,13 @@ type handler struct { } type rpcStats struct { - method string - direction jsonrpc2.Direction - id *jsonrpc2.ID - payload *json.RawMessage - start time.Time - close func() + method string + direction jsonrpc2.Direction + id *jsonrpc2.ID + payload *json.RawMessage + start time.Time + delivering func() + close func() } type statsKeyType int @@ -137,6 +138,10 @@ type statsKeyType int const statsKey = statsKeyType(0) func (h *handler) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool { + stats := h.getStats(ctx) + if stats != nil { + stats.delivering() + } return false } @@ -165,6 +170,7 @@ func (h *handler) Request(ctx context.Context, direction jsonrpc2.Direction, r * tag.Tag{Key: telemetry.RPCID, Value: r.ID}, ) telemetry.Started.Record(ctx, 1) + _, stats.delivering = trace.StartSpan(ctx, "queued") return ctx } diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index befbf85111..121d6c11f0 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -36,6 +36,7 @@ import ( "golang.org/x/tools/go/packages" "golang.org/x/tools/internal/lsp/telemetry" "golang.org/x/tools/internal/lsp/telemetry/log" + "golang.org/x/tools/internal/lsp/telemetry/trace" "golang.org/x/tools/internal/span" ) @@ -61,7 +62,8 @@ const ( ) func Diagnostics(ctx context.Context, view View, f GoFile, disabledAnalyses map[string]struct{}) (map[span.URI][]Diagnostic, error) { - ctx = telemetry.File.With(ctx, f.URI()) + ctx, done := trace.StartSpan(ctx, "source.Diagnostics", telemetry.File.Of(f.URI())) + defer done() pkg := f.GetPackage(ctx) if pkg == nil { return singleDiagnostic(f.URI(), "%s is not part of a package", f.URI()), nil @@ -107,6 +109,8 @@ type diagnosticSet struct { } func diagnostics(ctx context.Context, v View, pkg Package, reports map[span.URI][]Diagnostic) bool { + ctx, done := trace.StartSpan(ctx, "source.diagnostics", telemetry.Package.Of(pkg.ID())) + defer done() diagSets := make(map[span.URI]*diagnosticSet) for _, err := range pkg.GetErrors() { diag := Diagnostic{