Skip to content

Commit a61b54a

Browse files
committed
gopls: additional instrumentation during goimports
Add some visibility into goimports operations, by instrumenting spans in top-level imports and gocommand operations. This may be the first time we instrument non-gopls code in this way, but it should be safe as other build targets (e.g. the goimports or gopackages commands) do not set a global exporter, and therefore the cost of event instrumentation should be minimal. For golang/go#59216 Change-Id: Id2f8fe05d6b61e96cdd2d41cc43b3d4c3cf39e21 Reviewed-on: https://go-review.googlesource.com/c/tools/+/494095 Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent c8f294d commit a61b54a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/gocommand/invoke.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424
exec "golang.org/x/sys/execabs"
2525

2626
"github.com/apstndb/gotoolsdiff/internal/event"
27+
"github.com/apstndb/gotoolsdiff/internal/event/keys"
28+
"github.com/apstndb/gotoolsdiff/internal/event/label"
29+
"github.com/apstndb/gotoolsdiff/internal/event/tag"
2730
)
2831

2932
// An Runner will run go command invocations and serialize
@@ -53,23 +56,38 @@ func (runner *Runner) initialize() {
5356
// 1.14: go: updating go.mod: existing contents have changed since last read
5457
var modConcurrencyError = regexp.MustCompile(`go:.*go.mod.*contents have changed`)
5558

59+
// verb is an event label for the go command verb.
60+
var verb = keys.NewString("verb", "go command verb")
61+
62+
func invLabels(inv Invocation) []label.Label {
63+
return []label.Label{verb.Of(inv.Verb), tag.Directory.Of(inv.WorkingDir)}
64+
}
65+
5666
// Run is a convenience wrapper around RunRaw.
5767
// It returns only stdout and a "friendly" error.
5868
func (runner *Runner) Run(ctx context.Context, inv Invocation) (*bytes.Buffer, error) {
69+
ctx, done := event.Start(ctx, "gocommand.Runner.Run", invLabels(inv)...)
70+
defer done()
71+
5972
stdout, _, friendly, _ := runner.RunRaw(ctx, inv)
6073
return stdout, friendly
6174
}
6275

6376
// RunPiped runs the invocation serially, always waiting for any concurrent
6477
// invocations to complete first.
6578
func (runner *Runner) RunPiped(ctx context.Context, inv Invocation, stdout, stderr io.Writer) error {
79+
ctx, done := event.Start(ctx, "gocommand.Runner.RunPiped", invLabels(inv)...)
80+
defer done()
81+
6682
_, err := runner.runPiped(ctx, inv, stdout, stderr)
6783
return err
6884
}
6985

7086
// RunRaw runs the invocation, serializing requests only if they fight over
7187
// go.mod changes.
7288
func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
89+
ctx, done := event.Start(ctx, "gocommand.Runner.RunRaw", invLabels(inv)...)
90+
defer done()
7391
// Make sure the runner is always initialized.
7492
runner.initialize()
7593

0 commit comments

Comments
 (0)