diff --git a/internal/telemetry/bench_test.go b/internal/event/bench_test.go similarity index 76% rename from internal/telemetry/bench_test.go rename to internal/event/bench_test.go index df0f1ea64..f4fc72759 100644 --- a/internal/telemetry/bench_test.go +++ b/internal/event/bench_test.go @@ -1,4 +1,4 @@ -package telemetry_test +package event_test import ( "context" @@ -6,8 +6,9 @@ import ( "log" "testing" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" ) type Hooks struct { @@ -16,12 +17,12 @@ type Hooks struct { } var ( - aValue = event.NewIntKey("a", "") - bValue = event.NewStringKey("b", "") - aCount = event.NewInt64Key("aCount", "Count of time A is called.") - aStat = event.NewIntKey("aValue", "A value.") - bCount = event.NewInt64Key("B", "Count of time B is called.") - bLength = event.NewIntKey("BLen", "B length.") + aValue = core.NewIntKey("a", "") + bValue = core.NewStringKey("b", "") + aCount = core.NewInt64Key("aCount", "Count of time A is called.") + aStat = core.NewIntKey("aValue", "A value.") + bCount = core.NewInt64Key("B", "Count of time B is called.") + bLength = core.NewIntKey("BLen", "B length.") Baseline = Hooks{ A: func(ctx context.Context, a int) (context.Context, func()) { @@ -45,33 +46,33 @@ var ( Log = Hooks{ A: func(ctx context.Context, a int) (context.Context, func()) { - event.Print1(ctx, "A", aValue.Of(a)) + core.Print1(ctx, "A", aValue.Of(a)) return ctx, func() {} }, B: func(ctx context.Context, b string) (context.Context, func()) { - event.Print1(ctx, "B", bValue.Of(b)) + core.Print1(ctx, "B", bValue.Of(b)) return ctx, func() {} }, } Trace = Hooks{ A: func(ctx context.Context, a int) (context.Context, func()) { - return event.StartSpan1(ctx, "A", aValue.Of(a)) + return core.StartSpan1(ctx, "A", aValue.Of(a)) }, B: func(ctx context.Context, b string) (context.Context, func()) { - return event.StartSpan1(ctx, "B", bValue.Of(b)) + return core.StartSpan1(ctx, "B", bValue.Of(b)) }, } Stats = Hooks{ A: func(ctx context.Context, a int) (context.Context, func()) { - event.Record1(ctx, aStat.Of(a)) - event.Record1(ctx, aCount.Of(1)) + core.Record1(ctx, aStat.Of(a)) + core.Record1(ctx, aCount.Of(1)) return ctx, func() {} }, B: func(ctx context.Context, b string) (context.Context, func()) { - event.Record1(ctx, bLength.Of(len(b))) - event.Record1(ctx, bCount.Of(1)) + core.Record1(ctx, bLength.Of(len(b))) + core.Record1(ctx, bCount.Of(1)) return ctx, func() {} }, } @@ -146,6 +147,6 @@ func init() { log.SetOutput(ioutil.Discard) } -func noopExporter(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func noopExporter(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { return ctx } diff --git a/internal/telemetry/event/event.go b/internal/event/core/event.go similarity index 97% rename from internal/telemetry/event/event.go rename to internal/event/core/event.go index 2b990c5c1..ef7276453 100644 --- a/internal/telemetry/event/event.go +++ b/internal/event/core/event.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package event provides support for event based telemetry. -package event +// Package core provides support for event based telemetry. +package core import ( "fmt" diff --git a/internal/telemetry/event/export.go b/internal/event/core/export.go similarity index 99% rename from internal/telemetry/event/export.go rename to internal/event/core/export.go index a2633b602..e4a914106 100644 --- a/internal/telemetry/event/export.go +++ b/internal/event/core/export.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "context" diff --git a/internal/telemetry/event/key.go b/internal/event/core/key.go similarity index 99% rename from internal/telemetry/event/key.go rename to internal/event/core/key.go index acde7511e..6c28fb25c 100644 --- a/internal/telemetry/event/key.go +++ b/internal/event/core/key.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "fmt" diff --git a/internal/telemetry/event/label.go b/internal/event/core/label.go similarity index 98% rename from internal/telemetry/event/label.go rename to internal/event/core/label.go index edd34bb08..45725e7d0 100644 --- a/internal/telemetry/event/label.go +++ b/internal/event/core/label.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "context" diff --git a/internal/telemetry/event/log.go b/internal/event/core/log.go similarity index 99% rename from internal/telemetry/event/log.go rename to internal/event/core/log.go index 8d0a046e7..a6bdac82c 100644 --- a/internal/telemetry/event/log.go +++ b/internal/event/core/log.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "context" diff --git a/internal/telemetry/event/metric.go b/internal/event/core/metric.go similarity index 98% rename from internal/telemetry/event/metric.go rename to internal/event/core/metric.go index e4092bb0d..c75f79b18 100644 --- a/internal/telemetry/event/metric.go +++ b/internal/event/core/metric.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "context" diff --git a/internal/telemetry/event/tag.go b/internal/event/core/tag.go similarity index 99% rename from internal/telemetry/event/tag.go rename to internal/event/core/tag.go index 5230736ef..57de6ba88 100644 --- a/internal/telemetry/event/tag.go +++ b/internal/event/core/tag.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "fmt" diff --git a/internal/telemetry/event/tag_test.go b/internal/event/core/tag_test.go similarity index 60% rename from internal/telemetry/event/tag_test.go rename to internal/event/core/tag_test.go index 3d0832edd..c03b146b5 100644 --- a/internal/telemetry/event/tag_test.go +++ b/internal/event/core/tag_test.go @@ -2,76 +2,76 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event_test +package core_test import ( "bytes" "fmt" "testing" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event/core" ) var ( - AKey = event.NewStringKey("A", "") - BKey = event.NewStringKey("B", "") - CKey = event.NewStringKey("C", "") + AKey = core.NewStringKey("A", "") + BKey = core.NewStringKey("B", "") + CKey = core.NewStringKey("C", "") A = AKey.Of("a") B = BKey.Of("b") C = CKey.Of("c") - all = []event.Tag{A, B, C} + all = []core.Tag{A, B, C} ) func TestTagList(t *testing.T) { for _, test := range []struct { name string - tags []event.Tag + tags []core.Tag expect string }{{ name: "empty", }, { name: "single", - tags: []event.Tag{A}, + tags: []core.Tag{A}, expect: `A="a"`, }, { name: "invalid", - tags: []event.Tag{{}}, + tags: []core.Tag{{}}, expect: ``, }, { name: "two", - tags: []event.Tag{A, B}, + tags: []core.Tag{A, B}, expect: `A="a", B="b"`, }, { name: "three", - tags: []event.Tag{A, B, C}, + tags: []core.Tag{A, B, C}, expect: `A="a", B="b", C="c"`, }, { name: "missing A", - tags: []event.Tag{{}, B, C}, + tags: []core.Tag{{}, B, C}, expect: `B="b", C="c"`, }, { name: "missing B", - tags: []event.Tag{A, {}, C}, + tags: []core.Tag{A, {}, C}, expect: `A="a", C="c"`, }, { name: "missing C", - tags: []event.Tag{A, B, {}}, + tags: []core.Tag{A, B, {}}, expect: `A="a", B="b"`, }, { name: "missing AB", - tags: []event.Tag{{}, {}, C}, + tags: []core.Tag{{}, {}, C}, expect: `C="c"`, }, { name: "missing AC", - tags: []event.Tag{{}, B, {}}, + tags: []core.Tag{{}, B, {}}, expect: `B="b"`, }, { name: "missing BC", - tags: []event.Tag{A, {}, {}}, + tags: []core.Tag{A, {}, {}}, expect: `A="a"`, }} { t.Run(test.name, func(t *testing.T) { - got := printList(event.NewTagList(test.tags...)) + got := printList(core.NewTagList(test.tags...)) if got != test.expect { t.Errorf("got %q want %q", got, test.expect) } @@ -82,8 +82,8 @@ func TestTagList(t *testing.T) { func TestTagFilter(t *testing.T) { for _, test := range []struct { name string - tags []event.Tag - filters []event.Key + tags []core.Tag + filters []core.Key expect string }{{ name: "no filters", @@ -91,32 +91,32 @@ func TestTagFilter(t *testing.T) { expect: `A="a", B="b", C="c"`, }, { name: "no tags", - filters: []event.Key{AKey}, + filters: []core.Key{AKey}, expect: ``, }, { name: "filter A", tags: all, - filters: []event.Key{AKey}, + filters: []core.Key{AKey}, expect: `B="b", C="c"`, }, { name: "filter B", tags: all, - filters: []event.Key{BKey}, + filters: []core.Key{BKey}, expect: `A="a", C="c"`, }, { name: "filter C", tags: all, - filters: []event.Key{CKey}, + filters: []core.Key{CKey}, expect: `A="a", B="b"`, }, { name: "filter AC", tags: all, - filters: []event.Key{AKey, CKey}, + filters: []core.Key{AKey, CKey}, expect: `B="b"`, }} { t.Run(test.name, func(t *testing.T) { - tags := event.NewTagList(test.tags...) - got := printList(event.Filter(tags, test.filters...)) + tags := core.NewTagList(test.tags...) + got := printList(core.Filter(tags, test.filters...)) if got != test.expect { t.Errorf("got %q want %q", got, test.expect) } @@ -127,51 +127,51 @@ func TestTagFilter(t *testing.T) { func TestTagMap(t *testing.T) { for _, test := range []struct { name string - tags []event.Tag - keys []event.Key + tags []core.Tag + keys []core.Key expect string }{{ name: "no tags", - keys: []event.Key{AKey}, + keys: []core.Key{AKey}, expect: `nil`, }, { name: "match A", tags: all, - keys: []event.Key{AKey}, + keys: []core.Key{AKey}, expect: `A="a"`, }, { name: "match B", tags: all, - keys: []event.Key{BKey}, + keys: []core.Key{BKey}, expect: `B="b"`, }, { name: "match C", tags: all, - keys: []event.Key{CKey}, + keys: []core.Key{CKey}, expect: `C="c"`, }, { name: "match ABC", tags: all, - keys: []event.Key{AKey, BKey, CKey}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", C="c"`, }, { name: "missing A", - tags: []event.Tag{{}, B, C}, - keys: []event.Key{AKey, BKey, CKey}, + tags: []core.Tag{{}, B, C}, + keys: []core.Key{AKey, BKey, CKey}, expect: `nil, B="b", C="c"`, }, { name: "missing B", - tags: []event.Tag{A, {}, C}, - keys: []event.Key{AKey, BKey, CKey}, + tags: []core.Tag{A, {}, C}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", nil, C="c"`, }, { name: "missing C", - tags: []event.Tag{A, B, {}}, - keys: []event.Key{AKey, BKey, CKey}, + tags: []core.Tag{A, B, {}}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", nil`, }} { t.Run(test.name, func(t *testing.T) { - tagMap := event.NewTagMap(test.tags...) + tagMap := core.NewTagMap(test.tags...) got := printTagMap(tagMap, test.keys) if got != test.expect { t.Errorf("got %q want %q", got, test.expect) @@ -183,56 +183,56 @@ func TestTagMap(t *testing.T) { func TestTagMapMerge(t *testing.T) { for _, test := range []struct { name string - maps []event.TagMap - keys []event.Key + maps []core.TagMap + keys []core.Key expect string }{{ name: "no maps", - keys: []event.Key{AKey}, + keys: []core.Key{AKey}, expect: `nil`, }, { name: "one map", - maps: []event.TagMap{event.NewTagMap(all...)}, - keys: []event.Key{AKey}, + maps: []core.TagMap{core.NewTagMap(all...)}, + keys: []core.Key{AKey}, expect: `A="a"`, }, { name: "invalid map", - maps: []event.TagMap{event.NewTagMap()}, - keys: []event.Key{AKey}, + maps: []core.TagMap{core.NewTagMap()}, + keys: []core.Key{AKey}, expect: `nil`, }, { name: "two maps", - maps: []event.TagMap{event.NewTagMap(B, C), event.NewTagMap(A)}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(B, C), core.NewTagMap(A)}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", C="c"`, }, { name: "invalid start map", - maps: []event.TagMap{event.NewTagMap(), event.NewTagMap(B, C)}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(), core.NewTagMap(B, C)}, + keys: []core.Key{AKey, BKey, CKey}, expect: `nil, B="b", C="c"`, }, { name: "invalid mid map", - maps: []event.TagMap{event.NewTagMap(A), event.NewTagMap(), event.NewTagMap(C)}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(A), core.NewTagMap(), core.NewTagMap(C)}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", nil, C="c"`, }, { name: "invalid end map", - maps: []event.TagMap{event.NewTagMap(A, B), event.NewTagMap()}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(A, B), core.NewTagMap()}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", nil`, }, { name: "three maps one nil", - maps: []event.TagMap{event.NewTagMap(A), event.NewTagMap(B), nil}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(A), core.NewTagMap(B), nil}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", nil`, }, { name: "two maps one nil", - maps: []event.TagMap{event.NewTagMap(A, B), nil}, - keys: []event.Key{AKey, BKey, CKey}, + maps: []core.TagMap{core.NewTagMap(A, B), nil}, + keys: []core.Key{AKey, BKey, CKey}, expect: `A="a", B="b", nil`, }} { t.Run(test.name, func(t *testing.T) { - tagMap := event.MergeTagMaps(test.maps...) + tagMap := core.MergeTagMaps(test.maps...) got := printTagMap(tagMap, test.keys) if got != test.expect { t.Errorf("got %q want %q", got, test.expect) @@ -241,7 +241,7 @@ func TestTagMapMerge(t *testing.T) { } } -func printList(l event.TagList) string { +func printList(l core.TagList) string { buf := &bytes.Buffer{} for index := 0; l.Valid(index); index++ { tag := l.Tag(index) @@ -256,7 +256,7 @@ func printList(l event.TagList) string { return buf.String() } -func printTagMap(tagMap event.TagMap, keys []event.Key) string { +func printTagMap(tagMap core.TagMap, keys []core.Key) string { buf := &bytes.Buffer{} for _, key := range keys { if buf.Len() > 0 { diff --git a/internal/telemetry/event/trace.go b/internal/event/core/trace.go similarity index 99% rename from internal/telemetry/event/trace.go rename to internal/event/core/trace.go index 2c40341ff..96354c50e 100644 --- a/internal/telemetry/event/trace.go +++ b/internal/event/core/trace.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package event +package core import ( "context" diff --git a/internal/event/doc.go b/internal/event/doc.go new file mode 100644 index 000000000..5dc6e6bab --- /dev/null +++ b/internal/event/doc.go @@ -0,0 +1,7 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package event provides a set of packages that cover the main +// concepts of telemetry in an implementation agnostic way. +package event diff --git a/internal/event/event.go b/internal/event/event.go new file mode 100644 index 000000000..bb950f647 --- /dev/null +++ b/internal/event/event.go @@ -0,0 +1,63 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package event + +import ( + "context" + + "golang.org/x/tools/internal/event/core" +) + +// Exporter is a function that handles events. +// It may return a modified context and event. +type Exporter func(context.Context, core.Event, core.TagMap) context.Context + +// SetExporter sets the global exporter function that handles all events. +// The exporter is called synchronously from the event call site, so it should +// return quickly so as not to hold up user code. +func SetExporter(e Exporter) { + core.SetExporter(core.Exporter(e)) +} + +// Log sends a log event with the supplied tag list to the exporter. +func Log(ctx context.Context, tags ...core.Tag) { + core.Log(ctx, tags...) +} + +// Print takes a message and a tag list and combines them into a single event +// before delivering them to the exporter. +func Print(ctx context.Context, message string, tags ...core.Tag) { + core.Print(ctx, message, tags...) +} + +// Error takes a message and a tag list and combines them into a single event +// before delivering them to the exporter. It captures the error in the +// delivered event. +func Error(ctx context.Context, message string, err error, tags ...core.Tag) { + core.Error(ctx, message, err, tags...) +} + +// Record sends a label event to the exporter with the supplied tags. +func Record(ctx context.Context, tags ...core.Tag) context.Context { + return core.Record(ctx, tags...) +} + +// Label sends a label event to the exporter with the supplied tags. +func Label(ctx context.Context, tags ...core.Tag) context.Context { + return core.Label(ctx, tags...) +} + +// StartSpan sends a span start event with the supplied tag list to the exporter. +// It also returns a function that will end the span, which should normally be +// deferred. +func StartSpan(ctx context.Context, name string, tags ...core.Tag) (context.Context, func()) { + return core.StartSpan(ctx, name, tags...) +} + +// Detach returns a context without an associated span. +// This allows the creation of spans that are not children of the current span. +func Detach(ctx context.Context) context.Context { + return core.Detach(ctx) +} diff --git a/internal/telemetry/export/eventtest/eventtest.go b/internal/event/export/eventtest/eventtest.go similarity index 87% rename from internal/telemetry/export/eventtest/eventtest.go rename to internal/event/export/eventtest/eventtest.go index ae92166d7..d0061f774 100644 --- a/internal/telemetry/export/eventtest/eventtest.go +++ b/internal/event/export/eventtest/eventtest.go @@ -21,8 +21,9 @@ import ( "sync" "testing" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" ) func init() { @@ -47,7 +48,7 @@ type testExporter struct { logger event.Exporter } -func (w *testExporter) processEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func (w *testExporter) processEvent(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { w.mu.Lock() defer w.mu.Unlock() // build our log message in buffer diff --git a/internal/telemetry/export/id.go b/internal/event/export/id.go similarity index 100% rename from internal/telemetry/export/id.go rename to internal/event/export/id.go diff --git a/internal/telemetry/export/log.go b/internal/event/export/log.go similarity index 81% rename from internal/telemetry/export/log.go rename to internal/event/export/log.go index 8bc0360dd..22076aafa 100644 --- a/internal/telemetry/export/log.go +++ b/internal/event/export/log.go @@ -10,7 +10,8 @@ import ( "io" "sync" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" ) // LogWriter returns an Exporter that logs events to the supplied writer. @@ -29,10 +30,10 @@ type logWriter struct { onlyErrors bool } -func (w *logWriter) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func (w *logWriter) ProcessEvent(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { switch { case ev.IsLog(): - if w.onlyErrors && event.Err.Get(tagMap) == nil { + if w.onlyErrors && core.Err.Get(tagMap) == nil { return ctx } w.mu.Lock() @@ -42,15 +43,15 @@ func (w *logWriter) ProcessEvent(ctx context.Context, ev event.Event, tagMap eve if !ev.At.IsZero() { w.writer.Write(ev.At.AppendFormat(buf, "2006/01/02 15:04:05 ")) } - msg := event.Msg.Get(tagMap) + msg := core.Msg.Get(tagMap) io.WriteString(w.writer, msg) - if err := event.Err.Get(tagMap); err != nil { + if err := core.Err.Get(tagMap); err != nil { io.WriteString(w.writer, ": ") io.WriteString(w.writer, err.Error()) } for index := 0; ev.Valid(index); index++ { tag := ev.Tag(index) - if !tag.Valid() || tag.Key() == event.Msg || tag.Key() == event.Err { + if !tag.Valid() || tag.Key() == core.Msg || tag.Key() == core.Err { continue } io.WriteString(w.writer, "\n\t") diff --git a/internal/telemetry/export/log_test.go b/internal/event/export/log_test.go similarity index 71% rename from internal/telemetry/export/log_test.go rename to internal/event/export/log_test.go index 77fa02c7e..0864e9126 100644 --- a/internal/telemetry/export/log_test.go +++ b/internal/event/export/log_test.go @@ -10,15 +10,16 @@ import ( "os" "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" ) func ExampleLog() { ctx := context.Background() event.SetExporter(timeFixer(export.LogWriter(os.Stdout, false))) - anInt := event.NewIntKey("myInt", "an integer") - aString := event.NewStringKey("myString", "a string") + anInt := core.NewIntKey("myInt", "an integer") + aString := core.NewStringKey("myString", "a string") event.Print(ctx, "my event", anInt.Of(6)) event.Error(ctx, "error event", errors.New("an error"), aString.Of("some string value")) // Output: @@ -30,7 +31,7 @@ func ExampleLog() { func timeFixer(output event.Exporter) event.Exporter { at, _ := time.Parse(time.RFC3339Nano, "2020-03-05T14:27:48Z") - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { ev.At = at return output(ctx, ev, tagMap) } diff --git a/internal/telemetry/export/metric/data.go b/internal/event/export/metric/data.go similarity index 74% rename from internal/telemetry/export/metric/data.go rename to internal/event/export/metric/data.go index 33d7bf15a..c9603556b 100644 --- a/internal/telemetry/export/metric/data.go +++ b/internal/event/export/metric/data.go @@ -9,7 +9,7 @@ import ( "sort" "time" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event/core" ) // Data represents a single point in the time series of a metric. @@ -22,7 +22,7 @@ type Data interface { //TODO: rethink the concept of metric handles Handle() string // Groups reports the rows that currently exist for this metric. - Groups() [][]event.Tag + Groups() [][]core.Tag } // Int64Data is a concrete implementation of Data for int64 scalar metrics. @@ -36,8 +36,8 @@ type Int64Data struct { // End is the last time this metric was updated. EndTime time.Time - groups [][]event.Tag - key *event.Int64Key + groups [][]core.Tag + key *core.Int64Key } // Float64Data is a concrete implementation of Data for float64 scalar metrics. @@ -51,8 +51,8 @@ type Float64Data struct { // End is the last time this metric was updated. EndTime time.Time - groups [][]event.Tag - key *event.Float64Key + groups [][]core.Tag + key *core.Float64Key } // HistogramInt64Data is a concrete implementation of Data for int64 histogram metrics. @@ -64,8 +64,8 @@ type HistogramInt64Data struct { // End is the last time this metric was updated. EndTime time.Time - groups [][]event.Tag - key *event.Int64Key + groups [][]core.Tag + key *core.Int64Key } // HistogramInt64Row holds the values for a single row of a HistogramInt64Data. @@ -91,8 +91,8 @@ type HistogramFloat64Data struct { // End is the last time this metric was updated. EndTime time.Time - groups [][]event.Tag - key *event.Float64Key + groups [][]core.Tag + key *core.Float64Key } // HistogramFloat64Row holds the values for a single row of a HistogramFloat64Data. @@ -109,18 +109,18 @@ type HistogramFloat64Row struct { Max float64 } -func tagListEqual(a, b []event.Tag) bool { +func tagListEqual(a, b []core.Tag) bool { //TODO: make this more efficient return fmt.Sprint(a) == fmt.Sprint(b) } -func tagListLess(a, b []event.Tag) bool { +func tagListLess(a, b []core.Tag) bool { //TODO: make this more efficient return fmt.Sprint(a) < fmt.Sprint(b) } -func getGroup(tagMap event.TagMap, g *[][]event.Tag, keys []event.Key) (int, bool) { - group := make([]event.Tag, len(keys)) +func getGroup(tagMap core.TagMap, g *[][]core.Tag, keys []core.Key) (int, bool) { + group := make([]core.Tag, len(keys)) for i, key := range keys { tag := tagMap.Find(key) if tag.Valid() { @@ -135,17 +135,17 @@ func getGroup(tagMap event.TagMap, g *[][]event.Tag, keys []event.Key) (int, boo // not a new group return index, false } - *g = make([][]event.Tag, len(old)+1) + *g = make([][]core.Tag, len(old)+1) copy(*g, old[:index]) copy((*g)[index+1:], old[index:]) (*g)[index] = group return index, true } -func (data *Int64Data) Handle() string { return data.Info.Name } -func (data *Int64Data) Groups() [][]event.Tag { return data.groups } +func (data *Int64Data) Handle() string { return data.Info.Name } +func (data *Int64Data) Groups() [][]core.Tag { return data.groups } -func (data *Int64Data) modify(at time.Time, tagMap event.TagMap, f func(v int64) int64) Data { +func (data *Int64Data) modify(at time.Time, tagMap core.TagMap, f func(v int64) int64) Data { index, insert := getGroup(tagMap, &data.groups, data.Info.Keys) old := data.Rows if insert { @@ -162,28 +162,28 @@ func (data *Int64Data) modify(at time.Time, tagMap event.TagMap, f func(v int64) return &frozen } -func (data *Int64Data) count(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *Int64Data) count(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v int64) int64 { return v + 1 }) } -func (data *Int64Data) sum(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *Int64Data) sum(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v int64) int64 { return v + data.key.From(tag) }) } -func (data *Int64Data) latest(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *Int64Data) latest(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v int64) int64 { return data.key.From(tag) }) } -func (data *Float64Data) Handle() string { return data.Info.Name } -func (data *Float64Data) Groups() [][]event.Tag { return data.groups } +func (data *Float64Data) Handle() string { return data.Info.Name } +func (data *Float64Data) Groups() [][]core.Tag { return data.groups } -func (data *Float64Data) modify(at time.Time, tagMap event.TagMap, f func(v float64) float64) Data { +func (data *Float64Data) modify(at time.Time, tagMap core.TagMap, f func(v float64) float64) Data { index, insert := getGroup(tagMap, &data.groups, data.Info.Keys) old := data.Rows if insert { @@ -200,22 +200,22 @@ func (data *Float64Data) modify(at time.Time, tagMap event.TagMap, f func(v floa return &frozen } -func (data *Float64Data) sum(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *Float64Data) sum(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v float64) float64 { return v + data.key.From(tag) }) } -func (data *Float64Data) latest(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *Float64Data) latest(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v float64) float64 { return data.key.From(tag) }) } -func (data *HistogramInt64Data) Handle() string { return data.Info.Name } -func (data *HistogramInt64Data) Groups() [][]event.Tag { return data.groups } +func (data *HistogramInt64Data) Handle() string { return data.Info.Name } +func (data *HistogramInt64Data) Groups() [][]core.Tag { return data.groups } -func (data *HistogramInt64Data) modify(at time.Time, tagMap event.TagMap, f func(v *HistogramInt64Row)) Data { +func (data *HistogramInt64Data) modify(at time.Time, tagMap core.TagMap, f func(v *HistogramInt64Row)) Data { index, insert := getGroup(tagMap, &data.groups, data.Info.Keys) old := data.Rows var v HistogramInt64Row @@ -238,7 +238,7 @@ func (data *HistogramInt64Data) modify(at time.Time, tagMap event.TagMap, f func return &frozen } -func (data *HistogramInt64Data) record(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *HistogramInt64Data) record(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v *HistogramInt64Row) { value := data.key.From(tag) v.Sum += value @@ -257,10 +257,10 @@ func (data *HistogramInt64Data) record(at time.Time, tagMap event.TagMap, tag ev }) } -func (data *HistogramFloat64Data) Handle() string { return data.Info.Name } -func (data *HistogramFloat64Data) Groups() [][]event.Tag { return data.groups } +func (data *HistogramFloat64Data) Handle() string { return data.Info.Name } +func (data *HistogramFloat64Data) Groups() [][]core.Tag { return data.groups } -func (data *HistogramFloat64Data) modify(at time.Time, tagMap event.TagMap, f func(v *HistogramFloat64Row)) Data { +func (data *HistogramFloat64Data) modify(at time.Time, tagMap core.TagMap, f func(v *HistogramFloat64Row)) Data { index, insert := getGroup(tagMap, &data.groups, data.Info.Keys) old := data.Rows var v HistogramFloat64Row @@ -283,7 +283,7 @@ func (data *HistogramFloat64Data) modify(at time.Time, tagMap event.TagMap, f fu return &frozen } -func (data *HistogramFloat64Data) record(at time.Time, tagMap event.TagMap, tag event.Tag) Data { +func (data *HistogramFloat64Data) record(at time.Time, tagMap core.TagMap, tag core.Tag) Data { return data.modify(at, tagMap, func(v *HistogramFloat64Row) { value := data.key.From(tag) v.Sum += value diff --git a/internal/telemetry/export/metric/exporter.go b/internal/event/export/metric/exporter.go similarity index 69% rename from internal/telemetry/export/metric/exporter.go rename to internal/event/export/metric/exporter.go index ad3552fb4..c3653d98f 100644 --- a/internal/telemetry/export/metric/exporter.go +++ b/internal/event/export/metric/exporter.go @@ -10,18 +10,19 @@ import ( "sync" "time" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" ) -var Entries = event.NewKey("metric_entries", "The set of metrics calculated for an event") +var Entries = core.NewKey("metric_entries", "The set of metrics calculated for an event") type Config struct { subscribers map[interface{}][]subscriber } -type subscriber func(time.Time, event.TagMap, event.Tag) Data +type subscriber func(time.Time, core.TagMap, core.Tag) Data -func (e *Config) subscribe(key event.Key, s subscriber) { +func (e *Config) subscribe(key core.Key, s subscriber) { if e.subscribers == nil { e.subscribers = make(map[interface{}][]subscriber) } @@ -30,7 +31,7 @@ func (e *Config) subscribe(key event.Key, s subscriber) { func (e *Config) Exporter(output event.Exporter) event.Exporter { var mu sync.Mutex - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { if !ev.IsRecord() { return output(ctx, ev, tagMap) } @@ -49,7 +50,7 @@ func (e *Config) Exporter(output event.Exporter) event.Exporter { } } } - tagMap = event.MergeTagMaps(event.NewTagMap(Entries.Of(metrics)), tagMap) + tagMap = core.MergeTagMaps(core.NewTagMap(Entries.Of(metrics)), tagMap) return output(ctx, ev, tagMap) } } diff --git a/internal/telemetry/export/metric/info.go b/internal/event/export/metric/info.go similarity index 85% rename from internal/telemetry/export/metric/info.go rename to internal/event/export/metric/info.go index e2b2bf980..2d423d1f5 100644 --- a/internal/telemetry/export/metric/info.go +++ b/internal/event/export/metric/info.go @@ -4,9 +4,7 @@ package metric -import ( - "golang.org/x/tools/internal/telemetry/event" -) +import "golang.org/x/tools/internal/event/core" // Scalar represents the construction information for a scalar metric. type Scalar struct { @@ -15,7 +13,7 @@ type Scalar struct { // Description can be used by observers to describe the metric to users. Description string // Keys is the set of tags that collectively describe rows of the metric. - Keys []event.Key + Keys []core.Key } // HistogramInt64 represents the construction information for an int64 histogram metric. @@ -25,7 +23,7 @@ type HistogramInt64 struct { // Description can be used by observers to describe the metric to users. Description string // Keys is the set of tags that collectively describe rows of the metric. - Keys []event.Key + Keys []core.Key // Buckets holds the inclusive upper bound of each bucket in the histogram. Buckets []int64 } @@ -37,7 +35,7 @@ type HistogramFloat64 struct { // Description can be used by observers to describe the metric to users. Description string // Keys is the set of tags that collectively describe rows of the metric. - Keys []event.Key + Keys []core.Key // Buckets holds the inclusive upper bound of each bucket in the histogram. Buckets []float64 } @@ -45,7 +43,7 @@ type HistogramFloat64 struct { // Count creates a new metric based on the Scalar information that counts // the number of times the supplied int64 measure is set. // Metrics of this type will use Int64Data. -func (info Scalar) Count(e *Config, key event.Key) { +func (info Scalar) Count(e *Config, key core.Key) { data := &Int64Data{Info: &info, key: nil} e.subscribe(key, data.count) } @@ -53,7 +51,7 @@ func (info Scalar) Count(e *Config, key event.Key) { // SumInt64 creates a new metric based on the Scalar information that sums all // the values recorded on the int64 measure. // Metrics of this type will use Int64Data. -func (info Scalar) SumInt64(e *Config, key *event.Int64Key) { +func (info Scalar) SumInt64(e *Config, key *core.Int64Key) { data := &Int64Data{Info: &info, key: key} e.subscribe(key, data.sum) } @@ -61,7 +59,7 @@ func (info Scalar) SumInt64(e *Config, key *event.Int64Key) { // LatestInt64 creates a new metric based on the Scalar information that tracks // the most recent value recorded on the int64 measure. // Metrics of this type will use Int64Data. -func (info Scalar) LatestInt64(e *Config, key *event.Int64Key) { +func (info Scalar) LatestInt64(e *Config, key *core.Int64Key) { data := &Int64Data{Info: &info, IsGauge: true, key: key} e.subscribe(key, data.latest) } @@ -69,7 +67,7 @@ func (info Scalar) LatestInt64(e *Config, key *event.Int64Key) { // SumFloat64 creates a new metric based on the Scalar information that sums all // the values recorded on the float64 measure. // Metrics of this type will use Float64Data. -func (info Scalar) SumFloat64(e *Config, key *event.Float64Key) { +func (info Scalar) SumFloat64(e *Config, key *core.Float64Key) { data := &Float64Data{Info: &info, key: key} e.subscribe(key, data.sum) } @@ -77,7 +75,7 @@ func (info Scalar) SumFloat64(e *Config, key *event.Float64Key) { // LatestFloat64 creates a new metric based on the Scalar information that tracks // the most recent value recorded on the float64 measure. // Metrics of this type will use Float64Data. -func (info Scalar) LatestFloat64(e *Config, key *event.Float64Key) { +func (info Scalar) LatestFloat64(e *Config, key *core.Float64Key) { data := &Float64Data{Info: &info, IsGauge: true, key: key} e.subscribe(key, data.latest) } @@ -85,7 +83,7 @@ func (info Scalar) LatestFloat64(e *Config, key *event.Float64Key) { // Record creates a new metric based on the HistogramInt64 information that // tracks the bucketized counts of values recorded on the int64 measure. // Metrics of this type will use HistogramInt64Data. -func (info HistogramInt64) Record(e *Config, key *event.Int64Key) { +func (info HistogramInt64) Record(e *Config, key *core.Int64Key) { data := &HistogramInt64Data{Info: &info, key: key} e.subscribe(key, data.record) } @@ -93,7 +91,7 @@ func (info HistogramInt64) Record(e *Config, key *event.Int64Key) { // Record creates a new metric based on the HistogramFloat64 information that // tracks the bucketized counts of values recorded on the float64 measure. // Metrics of this type will use HistogramFloat64Data. -func (info HistogramFloat64) Record(e *Config, key *event.Float64Key) { +func (info HistogramFloat64) Record(e *Config, key *core.Float64Key) { data := &HistogramFloat64Data{Info: &info, key: key} e.subscribe(key, data.record) } diff --git a/internal/telemetry/export/ocagent/README.md b/internal/event/export/ocagent/README.md similarity index 95% rename from internal/telemetry/export/ocagent/README.md rename to internal/event/export/ocagent/README.md index d1d269922..22e8469f0 100644 --- a/internal/telemetry/export/ocagent/README.md +++ b/internal/event/export/ocagent/README.md @@ -37,10 +37,10 @@ import ( "net/http" "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" - "golang.org/x/tools/internal/telemetry/export/metric" - "golang.org/x/tools/internal/telemetry/export/ocagent" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/export" + "golang.org/x/tools/internal/event/export/metric" + "golang.org/x/tools/internal/event/export/ocagent" ) type testExporter struct { diff --git a/internal/telemetry/export/ocagent/metrics.go b/internal/event/export/ocagent/metrics.go similarity index 95% rename from internal/telemetry/export/ocagent/metrics.go rename to internal/event/export/ocagent/metrics.go index 0d0d46453..3250c4f94 100644 --- a/internal/telemetry/export/ocagent/metrics.go +++ b/internal/event/export/ocagent/metrics.go @@ -7,9 +7,9 @@ package ocagent import ( "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export/metric" - "golang.org/x/tools/internal/telemetry/export/ocagent/wire" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export/metric" + "golang.org/x/tools/internal/event/export/ocagent/wire" ) // dataToMetricDescriptor return a *wire.MetricDescriptor based on data. @@ -201,7 +201,7 @@ func distributionToPoints(counts []int64, count int64, sum float64, bucketBounds // infoKeysToLabelKeys returns an array of *wire.LabelKeys containing the // string values of the elements of labelKeys. -func infoKeysToLabelKeys(infoKeys []event.Key) []*wire.LabelKey { +func infoKeysToLabelKeys(infoKeys []core.Key) []*wire.LabelKey { labelKeys := make([]*wire.LabelKey, 0, len(infoKeys)) for _, key := range infoKeys { labelKeys = append(labelKeys, &wire.LabelKey{ diff --git a/internal/telemetry/export/ocagent/metrics_test.go b/internal/event/export/ocagent/metrics_test.go similarity index 94% rename from internal/telemetry/export/ocagent/metrics_test.go rename to internal/event/export/ocagent/metrics_test.go index 0c2165550..84cec6c52 100644 --- a/internal/telemetry/export/ocagent/metrics_test.go +++ b/internal/event/export/ocagent/metrics_test.go @@ -5,7 +5,8 @@ import ( "errors" "testing" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" ) func TestEncodeMetric(t *testing.T) { @@ -23,7 +24,7 @@ func TestEncodeMetric(t *testing.T) { run: func(ctx context.Context) { ctx = event.Label(ctx, keyMethod.Of("godoc.ServeHTTP")) event.Record(ctx, latencyMs.Of(96.58)) - ctx = event.Label(ctx, event.Err.Of(errors.New("panic: fatal signal"))) + ctx = event.Label(ctx, core.Err.Of(errors.New("panic: fatal signal"))) event.Record(ctx, bytesIn.Of(97e2)) }, want: prefix + ` diff --git a/internal/telemetry/export/ocagent/ocagent.go b/internal/event/export/ocagent/ocagent.go similarity index 85% rename from internal/telemetry/export/ocagent/ocagent.go rename to internal/event/export/ocagent/ocagent.go index 0d1af1aa3..0f1059260 100644 --- a/internal/telemetry/export/ocagent/ocagent.go +++ b/internal/event/export/ocagent/ocagent.go @@ -18,10 +18,10 @@ import ( "sync" "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" - "golang.org/x/tools/internal/telemetry/export/metric" - "golang.org/x/tools/internal/telemetry/export/ocagent/wire" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" + "golang.org/x/tools/internal/event/export/metric" + "golang.org/x/tools/internal/event/export/ocagent/wire" ) type Config struct { @@ -85,7 +85,7 @@ func Connect(config *Config) *Exporter { return exporter } -func (e *Exporter) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func (e *Exporter) ProcessEvent(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { switch { case ev.IsEndSpan(): e.mu.Lock() @@ -200,7 +200,7 @@ func convertSpan(span *export.Span) *wire.Span { Kind: wire.UnspecifiedSpanKind, StartTime: convertTimestamp(span.Start().At), EndTime: convertTimestamp(span.Finish().At), - Attributes: convertAttributes(event.Filter(span.Start(), event.Name)), + Attributes: convertAttributes(core.Filter(span.Start(), core.Name)), TimeEvents: convertEvents(span.Events()), SameProcessAsParentSpan: true, //TODO: StackTrace? @@ -227,17 +227,17 @@ func convertMetric(data metric.Data, start time.Time) *wire.Metric { } } -func skipToValidTag(l event.TagList) (int, event.Tag) { +func skipToValidTag(l core.TagList) (int, core.Tag) { // skip to the first valid tag for index := 0; l.Valid(index); index++ { if tag := l.Tag(index); tag.Valid() { return index, tag } } - return -1, event.Tag{} + return -1, core.Tag{} } -func convertAttributes(l event.TagList) *wire.Attributes { +func convertAttributes(l core.TagList) *wire.Attributes { index, tag := skipToValidTag(l) if !tag.Valid() { return nil @@ -255,46 +255,46 @@ func convertAttributes(l event.TagList) *wire.Attributes { } } -func convertAttribute(tag event.Tag) wire.Attribute { +func convertAttribute(tag core.Tag) wire.Attribute { switch key := tag.Key().(type) { - case *event.IntKey: + case *core.IntKey: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.Int8Key: + case *core.Int8Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.Int16Key: + case *core.Int16Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.Int32Key: + case *core.Int32Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.Int64Key: + case *core.Int64Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.UIntKey: + case *core.UIntKey: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.UInt8Key: + case *core.UInt8Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.UInt16Key: + case *core.UInt16Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.UInt32Key: + case *core.UInt32Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.UInt64Key: + case *core.UInt64Key: return wire.IntAttribute{IntValue: int64(key.From(tag))} - case *event.Float32Key: + case *core.Float32Key: return wire.DoubleAttribute{DoubleValue: float64(key.From(tag))} - case *event.Float64Key: + case *core.Float64Key: return wire.DoubleAttribute{DoubleValue: key.From(tag)} - case *event.BooleanKey: + case *core.BooleanKey: return wire.BoolAttribute{BoolValue: key.From(tag)} - case *event.StringKey: + case *core.StringKey: return wire.StringAttribute{StringValue: toTruncatableString(key.From(tag))} - case *event.ErrorKey: + case *core.ErrorKey: return wire.StringAttribute{StringValue: toTruncatableString(key.From(tag).Error())} - case *event.ValueKey: + case *core.ValueKey: return wire.StringAttribute{StringValue: toTruncatableString(fmt.Sprint(key.From(tag)))} default: return wire.StringAttribute{StringValue: toTruncatableString(fmt.Sprintf("%T", key))} } } -func convertEvents(events []event.Event) *wire.TimeEvents { +func convertEvents(events []core.Event) *wire.TimeEvents { //TODO: MessageEvents? result := make([]wire.TimeEvent, len(events)) for i, event := range events { @@ -303,23 +303,23 @@ func convertEvents(events []event.Event) *wire.TimeEvents { return &wire.TimeEvents{TimeEvent: result} } -func convertEvent(ev event.Event) wire.TimeEvent { +func convertEvent(ev core.Event) wire.TimeEvent { return wire.TimeEvent{ Time: convertTimestamp(ev.At), Annotation: convertAnnotation(ev), } } -func convertAnnotation(ev event.Event) *wire.Annotation { +func convertAnnotation(ev core.Event) *wire.Annotation { if _, tag := skipToValidTag(ev); !tag.Valid() { return nil } - tagMap := event.TagMap(ev) - description := event.Msg.Get(tagMap) - tags := event.Filter(ev, event.Msg) + tagMap := core.TagMap(ev) + description := core.Msg.Get(tagMap) + tags := core.Filter(ev, core.Msg) if description == "" { - err := event.Err.Get(tagMap) - tags = event.Filter(tags, event.Err) + err := core.Err.Get(tagMap) + tags = core.Filter(tags, core.Err) if err != nil { description = err.Error() } diff --git a/internal/telemetry/export/ocagent/ocagent_test.go b/internal/event/export/ocagent/ocagent_test.go similarity index 64% rename from internal/telemetry/export/ocagent/ocagent_test.go rename to internal/event/export/ocagent/ocagent_test.go index 36ca0e797..c1f2f959f 100644 --- a/internal/telemetry/export/ocagent/ocagent_test.go +++ b/internal/event/export/ocagent/ocagent_test.go @@ -15,10 +15,11 @@ import ( "testing" "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" - "golang.org/x/tools/internal/telemetry/export/metric" - "golang.org/x/tools/internal/telemetry/export/ocagent" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" + "golang.org/x/tools/internal/event/export/metric" + "golang.org/x/tools/internal/event/export/ocagent" ) const testNodeStr = `{ @@ -39,53 +40,53 @@ const testNodeStr = `{ },` var ( - keyDB = event.NewStringKey("db", "the database name") - keyMethod = event.NewStringKey("method", "a metric grouping key") - keyRoute = event.NewStringKey("route", "another metric grouping key") + keyDB = core.NewStringKey("db", "the database name") + keyMethod = core.NewStringKey("method", "a metric grouping key") + keyRoute = core.NewStringKey("route", "another metric grouping key") - key1DB = event.NewStringKey("1_db", "A test string key") + key1DB = core.NewStringKey("1_db", "A test string key") - key2aAge = event.NewFloat64Key("2a_age", "A test float64 key") - key2bTTL = event.NewFloat32Key("2b_ttl", "A test float32 key") - key2cExpiryMS = event.NewFloat64Key("2c_expiry_ms", "A test float64 key") + key2aAge = core.NewFloat64Key("2a_age", "A test float64 key") + key2bTTL = core.NewFloat32Key("2b_ttl", "A test float32 key") + key2cExpiryMS = core.NewFloat64Key("2c_expiry_ms", "A test float64 key") - key3aRetry = event.NewBooleanKey("3a_retry", "A test boolean key") - key3bStale = event.NewBooleanKey("3b_stale", "Another test boolean key") + key3aRetry = core.NewBooleanKey("3a_retry", "A test boolean key") + key3bStale = core.NewBooleanKey("3b_stale", "Another test boolean key") - key4aMax = event.NewIntKey("4a_max", "A test int key") - key4bOpcode = event.NewInt8Key("4b_opcode", "A test int8 key") - key4cBase = event.NewInt16Key("4c_base", "A test int16 key") - key4eChecksum = event.NewInt32Key("4e_checksum", "A test int32 key") - key4fMode = event.NewInt64Key("4f_mode", "A test int64 key") + key4aMax = core.NewIntKey("4a_max", "A test int key") + key4bOpcode = core.NewInt8Key("4b_opcode", "A test int8 key") + key4cBase = core.NewInt16Key("4c_base", "A test int16 key") + key4eChecksum = core.NewInt32Key("4e_checksum", "A test int32 key") + key4fMode = core.NewInt64Key("4f_mode", "A test int64 key") - key5aMin = event.NewUIntKey("5a_min", "A test uint key") - key5bMix = event.NewUInt8Key("5b_mix", "A test uint8 key") - key5cPort = event.NewUInt16Key("5c_port", "A test uint16 key") - key5dMinHops = event.NewUInt32Key("5d_min_hops", "A test uint32 key") - key5eMaxHops = event.NewUInt64Key("5e_max_hops", "A test uint64 key") + key5aMin = core.NewUIntKey("5a_min", "A test uint key") + key5bMix = core.NewUInt8Key("5b_mix", "A test uint8 key") + key5cPort = core.NewUInt16Key("5c_port", "A test uint16 key") + key5dMinHops = core.NewUInt32Key("5d_min_hops", "A test uint32 key") + key5eMaxHops = core.NewUInt64Key("5e_max_hops", "A test uint64 key") - recursiveCalls = event.NewInt64Key("recursive_calls", "Number of recursive calls") - bytesIn = event.NewInt64Key("bytes_in", "Number of bytes in") //, unit.Bytes) - latencyMs = event.NewFloat64Key("latency", "The latency in milliseconds") //, unit.Milliseconds) + recursiveCalls = core.NewInt64Key("recursive_calls", "Number of recursive calls") + bytesIn = core.NewInt64Key("bytes_in", "Number of bytes in") //, unit.Bytes) + latencyMs = core.NewFloat64Key("latency", "The latency in milliseconds") //, unit.Milliseconds) metricLatency = metric.HistogramFloat64{ Name: "latency_ms", Description: "The latency of calls in milliseconds", - Keys: []event.Key{keyMethod, keyRoute}, + Keys: []core.Key{keyMethod, keyRoute}, Buckets: []float64{0, 5, 10, 25, 50}, } metricBytesIn = metric.HistogramInt64{ Name: "latency_ms", Description: "The latency of calls in milliseconds", - Keys: []event.Key{keyMethod, keyRoute}, + Keys: []core.Key{keyMethod, keyRoute}, Buckets: []int64{0, 10, 50, 100, 500, 1000, 2000}, } metricRecursiveCalls = metric.Scalar{ Name: "latency_ms", Description: "The latency of calls in milliseconds", - Keys: []event.Key{keyMethod, keyRoute}, + Keys: []core.Key{keyMethod, keyRoute}, } ) @@ -124,7 +125,7 @@ func timeFixer(output event.Exporter) event.Exporter { start, _ := time.Parse(time.RFC3339Nano, "1970-01-01T00:00:30Z") at, _ := time.Parse(time.RFC3339Nano, "1970-01-01T00:00:40Z") end, _ := time.Parse(time.RFC3339Nano, "1970-01-01T00:00:50Z") - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { switch { case ev.IsStartSpan(): ev.At = start @@ -138,7 +139,7 @@ func timeFixer(output event.Exporter) event.Exporter { } func spanFixer(output event.Exporter) event.Exporter { - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { if ev.IsStartSpan() { span := export.GetSpan(ctx) span.ID = export.SpanContext{} diff --git a/internal/telemetry/export/ocagent/trace_test.go b/internal/event/export/ocagent/trace_test.go similarity index 98% rename from internal/telemetry/export/ocagent/trace_test.go rename to internal/event/export/ocagent/trace_test.go index f56516885..77df1d7d8 100644 --- a/internal/telemetry/export/ocagent/trace_test.go +++ b/internal/event/export/ocagent/trace_test.go @@ -9,7 +9,7 @@ import ( "errors" "testing" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" ) func TestTrace(t *testing.T) { diff --git a/internal/telemetry/export/ocagent/wire/common.go b/internal/event/export/ocagent/wire/common.go similarity index 100% rename from internal/telemetry/export/ocagent/wire/common.go rename to internal/event/export/ocagent/wire/common.go diff --git a/internal/telemetry/export/ocagent/wire/core.go b/internal/event/export/ocagent/wire/core.go similarity index 100% rename from internal/telemetry/export/ocagent/wire/core.go rename to internal/event/export/ocagent/wire/core.go diff --git a/internal/telemetry/export/ocagent/wire/metrics.go b/internal/event/export/ocagent/wire/metrics.go similarity index 100% rename from internal/telemetry/export/ocagent/wire/metrics.go rename to internal/event/export/ocagent/wire/metrics.go diff --git a/internal/telemetry/export/ocagent/wire/metrics_test.go b/internal/event/export/ocagent/wire/metrics_test.go similarity index 100% rename from internal/telemetry/export/ocagent/wire/metrics_test.go rename to internal/event/export/ocagent/wire/metrics_test.go diff --git a/internal/telemetry/export/ocagent/wire/trace.go b/internal/event/export/ocagent/wire/trace.go similarity index 100% rename from internal/telemetry/export/ocagent/wire/trace.go rename to internal/event/export/ocagent/wire/trace.go diff --git a/internal/telemetry/export/prometheus/prometheus.go b/internal/event/export/prometheus/prometheus.go similarity index 92% rename from internal/telemetry/export/prometheus/prometheus.go rename to internal/event/export/prometheus/prometheus.go index eb644dd1f..129f26076 100644 --- a/internal/telemetry/export/prometheus/prometheus.go +++ b/internal/event/export/prometheus/prometheus.go @@ -12,8 +12,8 @@ import ( "sort" "sync" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export/metric" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export/metric" ) func New() *Exporter { @@ -25,7 +25,7 @@ type Exporter struct { metrics []metric.Data } -func (e *Exporter) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func (e *Exporter) ProcessEvent(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { if !ev.IsRecord() { return ctx } @@ -64,7 +64,7 @@ func (e *Exporter) header(w http.ResponseWriter, name, description string, isGau fmt.Fprintf(w, "# TYPE %s %s\n", name, kind) } -func (e *Exporter) row(w http.ResponseWriter, name string, group []event.Tag, extra string, value interface{}) { +func (e *Exporter) row(w http.ResponseWriter, name string, group []core.Tag, extra string, value interface{}) { fmt.Fprint(w, name) buf := &bytes.Buffer{} fmt.Fprint(buf, group) diff --git a/internal/telemetry/export/tag.go b/internal/event/export/tag.go similarity index 71% rename from internal/telemetry/export/tag.go rename to internal/event/export/tag.go index 7d2952935..bc2ecb4b8 100644 --- a/internal/telemetry/export/tag.go +++ b/internal/event/export/tag.go @@ -7,7 +7,8 @@ package export import ( "context" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" ) // Labels builds an exporter that manipulates the context using the event. @@ -16,20 +17,20 @@ import ( // For all other event types the event tags will be updated with values from the // context if they are missing. func Labels(output event.Exporter) event.Exporter { - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { - stored, _ := ctx.Value(labelContextKey).(event.TagMap) + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { + stored, _ := ctx.Value(labelContextKey).(core.TagMap) if ev.IsLabel() || ev.IsStartSpan() { // update the tag source stored in the context - fromEvent := event.TagMap(ev) + fromEvent := core.TagMap(ev) if stored == nil { stored = fromEvent } else { - stored = event.MergeTagMaps(fromEvent, stored) + stored = core.MergeTagMaps(fromEvent, stored) } ctx = context.WithValue(ctx, labelContextKey, stored) } // add the stored tag context to the tag source - tagMap = event.MergeTagMaps(tagMap, stored) + tagMap = core.MergeTagMaps(tagMap, stored) return output(ctx, ev, tagMap) } } diff --git a/internal/telemetry/export/trace.go b/internal/event/export/trace.go similarity index 85% rename from internal/telemetry/export/trace.go rename to internal/event/export/trace.go index 48e38631e..528fdad82 100644 --- a/internal/telemetry/export/trace.go +++ b/internal/event/export/trace.go @@ -9,7 +9,8 @@ import ( "fmt" "sync" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" ) type SpanContext struct { @@ -22,9 +23,9 @@ type Span struct { ID SpanContext ParentID SpanID mu sync.Mutex - start event.Event - finish event.Event - events []event.Event + start core.Event + finish core.Event + events []core.Event } type contextKeyType int @@ -48,7 +49,7 @@ func GetSpan(ctx context.Context) *Span { // EventLog or EventTag, and closes the span on EventEndSpan. // The span structure can then be used by other exporters. func Spans(output event.Exporter) event.Exporter { - return func(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { switch { case ev.IsLog(), ev.IsLabel(): if span := GetSpan(ctx); span != nil { @@ -58,7 +59,7 @@ func Spans(output event.Exporter) event.Exporter { } case ev.IsStartSpan(): span := &Span{ - Name: event.Name.Get(tagMap), + Name: core.Name.Get(tagMap), start: ev, } if parent := GetSpan(ctx); parent != nil { @@ -86,18 +87,18 @@ func (s *SpanContext) Format(f fmt.State, r rune) { fmt.Fprintf(f, "%v:%v", s.TraceID, s.SpanID) } -func (s *Span) Start() event.Event { +func (s *Span) Start() core.Event { // start never changes after construction, so we dont need to hold the mutex return s.start } -func (s *Span) Finish() event.Event { +func (s *Span) Finish() core.Event { s.mu.Lock() defer s.mu.Unlock() return s.finish } -func (s *Span) Events() []event.Event { +func (s *Span) Events() []core.Event { s.mu.Lock() defer s.mu.Unlock() return s.events diff --git a/internal/gocommand/invoke.go b/internal/gocommand/invoke.go index 19ecaea6f..9aa798456 100644 --- a/internal/gocommand/invoke.go +++ b/internal/gocommand/invoke.go @@ -17,7 +17,7 @@ import ( "sync" "time" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" ) // An Runner will run go command invocations and serialize diff --git a/internal/jsonrpc2/handler.go b/internal/jsonrpc2/handler.go index 0cd106f2c..b861b1251 100644 --- a/internal/jsonrpc2/handler.go +++ b/internal/jsonrpc2/handler.go @@ -9,7 +9,7 @@ import ( "fmt" "sync" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" ) // Handler is invoked to handle incoming requests. diff --git a/internal/jsonrpc2/jsonrpc2.go b/internal/jsonrpc2/jsonrpc2.go index f340dc5c2..5ee2c85a7 100644 --- a/internal/jsonrpc2/jsonrpc2.go +++ b/internal/jsonrpc2/jsonrpc2.go @@ -14,8 +14,9 @@ import ( "sync" "sync/atomic" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" "golang.org/x/tools/internal/lsp/debug/tag" - "golang.org/x/tools/internal/telemetry/event" ) const ( @@ -172,7 +173,7 @@ func (c *Conn) Run(runCtx context.Context, handler Handler) error { } switch msg := msg.(type) { case Request: - tags := []event.Tag{ + tags := []core.Tag{ tag.Method.Of(msg.Method()), tag.RPCDirection.Of(tag.Inbound), {}, // reserved for ID if present diff --git a/internal/jsonrpc2/jsonrpc2_test.go b/internal/jsonrpc2/jsonrpc2_test.go index a73355869..b7232caa7 100644 --- a/internal/jsonrpc2/jsonrpc2_test.go +++ b/internal/jsonrpc2/jsonrpc2_test.go @@ -16,8 +16,8 @@ import ( "sync" "testing" + "golang.org/x/tools/internal/event/export/eventtest" "golang.org/x/tools/internal/jsonrpc2" - "golang.org/x/tools/internal/telemetry/export/eventtest" ) var logRPC = flag.Bool("logrpc", false, "Enable jsonrpc2 communication logging") diff --git a/internal/jsonrpc2/serve.go b/internal/jsonrpc2/serve.go index d3d83709e..6415b0e19 100644 --- a/internal/jsonrpc2/serve.go +++ b/internal/jsonrpc2/serve.go @@ -11,7 +11,7 @@ import ( "os" "time" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event" ) // NOTE: This file provides an experimental API for serving multiple remote diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index 563d3b53b..5868e7386 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -16,10 +16,10 @@ import ( "golang.org/x/sync/errgroup" "golang.org/x/tools/go/analysis" "golang.org/x/tools/internal/analysisinternal" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/memoize" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index d85786b23..bdde37e1e 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -17,11 +17,11 @@ import ( "sync" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go index 40f5596a4..14995b9e9 100644 --- a/internal/lsp/cache/errors.go +++ b/internal/lsp/cache/errors.go @@ -17,11 +17,11 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" "golang.org/x/tools/internal/analysisinternal" + "golang.org/x/tools/internal/event" "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/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/external.go b/internal/lsp/cache/external.go index 806499aab..1c46ea040 100644 --- a/internal/lsp/cache/external.go +++ b/internal/lsp/cache/external.go @@ -9,10 +9,10 @@ import ( "io/ioutil" "os" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 880d6f8a8..c53013747 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -12,11 +12,11 @@ import ( "strings" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/packagesinternal" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go index 461963310..ae3670468 100644 --- a/internal/lsp/cache/mod.go +++ b/internal/lsp/cache/mod.go @@ -15,6 +15,7 @@ import ( "golang.org/x/mod/modfile" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/gocommand" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" @@ -22,7 +23,6 @@ import ( "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/packagesinternal" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go index ca7893565..4f01fcbc9 100644 --- a/internal/lsp/cache/parse.go +++ b/internal/lsp/cache/parse.go @@ -13,12 +13,12 @@ import ( "go/token" "reflect" + "golang.org/x/tools/internal/event" "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/memoize" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 40d8ee785..4f3bffb21 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -11,11 +11,11 @@ import ( "sync" "sync/atomic" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/gocommand" "golang.org/x/tools/internal/lsp/debug" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/xcontext" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 013ba0dd5..0648c80a3 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -17,11 +17,11 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/packagesinternal" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index c9c90d5b5..4a87d8291 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -19,6 +19,8 @@ import ( "sync" "time" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" "golang.org/x/tools/internal/gocommand" "golang.org/x/tools/internal/imports" "golang.org/x/tools/internal/lsp/debug" @@ -26,7 +28,6 @@ import ( "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/memoize" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/xcontext" errors "golang.org/x/xerrors" ) @@ -344,7 +345,7 @@ func (v *view) refreshProcessEnv() { // We don't have a context handy to use for logging, so use the stdlib for now. event.Print(v.baseCtx, "background imports cache refresh starting") err := imports.PrimeCache(context.Background(), env) - event.Print(v.baseCtx, fmt.Sprintf("background refresh finished after %v", time.Since(start)), event.Err.Of(err)) + event.Print(v.baseCtx, fmt.Sprintf("background refresh finished after %v", time.Since(start)), core.Err.Of(err)) v.importsMu.Lock() v.cacheRefreshDuration = time.Since(start) diff --git a/internal/lsp/cmd/serve.go b/internal/lsp/cmd/serve.go index 05fdbb694..97900707e 100644 --- a/internal/lsp/cmd/serve.go +++ b/internal/lsp/cmd/serve.go @@ -12,12 +12,12 @@ import ( "strings" "time" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" "golang.org/x/tools/internal/lsp/cache" "golang.org/x/tools/internal/lsp/debug" "golang.org/x/tools/internal/lsp/lsprpc" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/tool" ) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index edc2b08ba..f6d3049b4 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -9,10 +9,10 @@ import ( "fmt" "strings" + "golang.org/x/tools/internal/event" "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/telemetry/event" ) func (s *Server) completion(ctx context.Context, params *protocol.CompletionParams) (*protocol.CompletionList, error) { diff --git a/internal/lsp/debug/metrics.go b/internal/lsp/debug/metrics.go index 4861b4148..94b582ead 100644 --- a/internal/lsp/debug/metrics.go +++ b/internal/lsp/debug/metrics.go @@ -5,9 +5,9 @@ package debug import ( + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export/metric" "golang.org/x/tools/internal/lsp/debug/tag" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export/metric" ) var ( @@ -18,34 +18,34 @@ var ( receivedBytes = metric.HistogramInt64{ Name: "received_bytes", Description: "Distribution of received bytes, by method.", - Keys: []event.Key{tag.RPCDirection, tag.Method}, + Keys: []core.Key{tag.RPCDirection, tag.Method}, Buckets: bytesDistribution, } sentBytes = metric.HistogramInt64{ Name: "sent_bytes", Description: "Distribution of sent bytes, by method.", - Keys: []event.Key{tag.RPCDirection, tag.Method}, + Keys: []core.Key{tag.RPCDirection, tag.Method}, Buckets: bytesDistribution, } latency = metric.HistogramFloat64{ Name: "latency", Description: "Distribution of latency in milliseconds, by method.", - Keys: []event.Key{tag.RPCDirection, tag.Method}, + Keys: []core.Key{tag.RPCDirection, tag.Method}, Buckets: millisecondsDistribution, } started = metric.Scalar{ Name: "started", Description: "Count of RPCs started by method.", - Keys: []event.Key{tag.RPCDirection, tag.Method}, + Keys: []core.Key{tag.RPCDirection, tag.Method}, } completed = metric.Scalar{ Name: "completed", Description: "Count of RPCs completed by method and status.", - Keys: []event.Key{tag.RPCDirection, tag.Method, tag.StatusCode}, + Keys: []core.Key{tag.RPCDirection, tag.Method, tag.StatusCode}, } ) diff --git a/internal/lsp/debug/rpc.go b/internal/lsp/debug/rpc.go index e1c93e284..4bbca75dd 100644 --- a/internal/lsp/debug/rpc.go +++ b/internal/lsp/debug/rpc.go @@ -13,9 +13,9 @@ import ( "sync" "time" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" "golang.org/x/tools/internal/lsp/debug/tag" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" ) var rpcTmpl = template.Must(template.Must(baseTemplate.Clone()).Parse(` @@ -77,7 +77,7 @@ type rpcCodeBucket struct { Count int64 } -func (r *rpcs) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context { +func (r *rpcs) ProcessEvent(ctx context.Context, ev core.Event, tagMap core.TagMap) context.Context { r.mu.Lock() defer r.mu.Unlock() switch { @@ -103,7 +103,7 @@ func (r *rpcs) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.Ta return ctx } -func endRPC(ctx context.Context, ev event.Event, span *export.Span, stats *rpcStats) { +func endRPC(ctx context.Context, ev core.Event, span *export.Span, stats *rpcStats) { // update the basic counts stats.Completed++ @@ -150,7 +150,7 @@ func endRPC(ctx context.Context, ev event.Event, span *export.Span, stats *rpcSt } } -func (r *rpcs) getRPCSpan(ctx context.Context, ev event.Event) (*export.Span, *rpcStats) { +func (r *rpcs) getRPCSpan(ctx context.Context, ev core.Event) (*export.Span, *rpcStats) { // get the span span := export.GetSpan(ctx) if span == nil { @@ -161,7 +161,7 @@ func (r *rpcs) getRPCSpan(ctx context.Context, ev event.Event) (*export.Span, *r return span, r.getRPCStats(span.Start()) } -func (r *rpcs) getRPCStats(tagMap event.TagMap) *rpcStats { +func (r *rpcs) getRPCStats(tagMap core.TagMap) *rpcStats { method := tag.Method.Get(tagMap) if method == "" { return nil diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go index c5781e507..2a1c73614 100644 --- a/internal/lsp/debug/serve.go +++ b/internal/lsp/debug/serve.go @@ -26,14 +26,15 @@ import ( "sync" "time" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" + "golang.org/x/tools/internal/event/export/metric" + "golang.org/x/tools/internal/event/export/ocagent" + "golang.org/x/tools/internal/event/export/prometheus" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" - "golang.org/x/tools/internal/telemetry/export/metric" - "golang.org/x/tools/internal/telemetry/export/ocagent" - "golang.org/x/tools/internal/telemetry/export/prometheus" "golang.org/x/xerrors" ) @@ -542,12 +543,12 @@ func (i *Instance) writeMemoryDebug(threshold uint64) error { } func makeGlobalExporter(stderr io.Writer) event.Exporter { - return func(ctx context.Context, ev event.Event, tags event.TagMap) context.Context { + return func(ctx context.Context, ev core.Event, tags core.TagMap) context.Context { i := GetInstance(ctx) if ev.IsLog() { // Don't log context cancellation errors. - if err := event.Err.Get(ev); xerrors.Is(err, context.Canceled) { + if err := core.Err.Get(ev); xerrors.Is(err, context.Canceled) { return ctx } // Make sure any log messages without an instance go to stderr. @@ -564,7 +565,7 @@ func makeGlobalExporter(stderr io.Writer) event.Exporter { } func makeInstanceExporter(i *Instance) event.Exporter { - exporter := func(ctx context.Context, ev event.Event, tags event.TagMap) context.Context { + exporter := func(ctx context.Context, ev core.Event, tags core.TagMap) context.Context { if i.ocagent != nil { ctx = i.ocagent.ProcessEvent(ctx, ev, tags) } diff --git a/internal/lsp/debug/tag/tag.go b/internal/lsp/debug/tag/tag.go index 22f1b237f..4250a1c7b 100644 --- a/internal/lsp/debug/tag/tag.go +++ b/internal/lsp/debug/tag/tag.go @@ -6,40 +6,40 @@ package tag import ( - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event/core" ) var ( // create the tag keys we use - Method = event.NewStringKey("method", "") - StatusCode = event.NewStringKey("status.code", "") - StatusMessage = event.NewStringKey("status.message", "") - RPCID = event.NewStringKey("id", "") - RPCDirection = event.NewStringKey("direction", "") - File = event.NewStringKey("file", "") - Directory = event.NewKey("directory", "") - URI = event.NewKey("URI", "") - Package = event.NewStringKey("package", "") - PackagePath = event.NewStringKey("package_path", "") - Query = event.NewKey("query", "") - Snapshot = event.NewUInt64Key("snapshot", "") - Operation = event.NewStringKey("operation", "") + Method = core.NewStringKey("method", "") + StatusCode = core.NewStringKey("status.code", "") + StatusMessage = core.NewStringKey("status.message", "") + RPCID = core.NewStringKey("id", "") + RPCDirection = core.NewStringKey("direction", "") + File = core.NewStringKey("file", "") + Directory = core.NewKey("directory", "") + URI = core.NewKey("URI", "") + Package = core.NewStringKey("package", "") + PackagePath = core.NewStringKey("package_path", "") + Query = core.NewKey("query", "") + Snapshot = core.NewUInt64Key("snapshot", "") + Operation = core.NewStringKey("operation", "") - Position = event.NewKey("position", "") - Category = event.NewStringKey("category", "") - PackageCount = event.NewIntKey("packages", "") - Files = event.NewKey("files", "") - Port = event.NewIntKey("port", "") - Type = event.NewKey("type", "") - HoverKind = event.NewStringKey("hoverkind", "") + Position = core.NewKey("position", "") + Category = core.NewStringKey("category", "") + PackageCount = core.NewIntKey("packages", "") + Files = core.NewKey("files", "") + Port = core.NewIntKey("port", "") + Type = core.NewKey("type", "") + HoverKind = core.NewStringKey("hoverkind", "") ) var ( // create the stats we measure - Started = event.NewInt64Key("started", "Count of started RPCs.") - ReceivedBytes = event.NewInt64Key("received_bytes", "Bytes received.") //, unit.Bytes) - SentBytes = event.NewInt64Key("sent_bytes", "Bytes sent.") //, unit.Bytes) - Latency = event.NewFloat64Key("latency_ms", "Elapsed time in milliseconds") //, unit.Milliseconds) + Started = core.NewInt64Key("started", "Count of started RPCs.") + ReceivedBytes = core.NewInt64Key("received_bytes", "Bytes received.") //, unit.Bytes) + SentBytes = core.NewInt64Key("sent_bytes", "Bytes sent.") //, unit.Bytes) + Latency = core.NewFloat64Key("latency_ms", "Elapsed time in milliseconds") //, unit.Milliseconds) ) const ( diff --git a/internal/lsp/debug/trace.go b/internal/lsp/debug/trace.go index 0ae32c941..2ad2cda7d 100644 --- a/internal/lsp/debug/trace.go +++ b/internal/lsp/debug/trace.go @@ -15,8 +15,8 @@ import ( "sync" "time" - "golang.org/x/tools/internal/telemetry/event" - "golang.org/x/tools/internal/telemetry/export" + "golang.org/x/tools/internal/event/core" + "golang.org/x/tools/internal/event/export" ) var traceTmpl = template.Must(template.Must(baseTemplate.Clone()).Parse(` @@ -73,7 +73,7 @@ type traceEvent struct { Tags string } -func (t *traces) ProcessEvent(ctx context.Context, ev event.Event, tags event.TagMap) context.Context { +func (t *traces) ProcessEvent(ctx context.Context, ev core.Event, tags core.TagMap) context.Context { t.mu.Lock() defer t.mu.Unlock() span := export.GetSpan(ctx) @@ -170,7 +170,7 @@ func fillOffsets(td *traceData, start time.Time) { } } -func renderTags(tags event.TagList) string { +func renderTags(tags core.TagList) string { buf := &bytes.Buffer{} for index := 0; tags.Valid(index); index++ { if tag := tags.Tag(index); tag.Valid() { diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index 94592be3c..14ad61d34 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -9,11 +9,11 @@ import ( "strings" "sync" + "golang.org/x/tools/internal/event" "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/telemetry/event" "golang.org/x/tools/internal/xcontext" ) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index 6e136707c..296966bd0 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -12,13 +12,13 @@ import ( "os" "path" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" "golang.org/x/tools/internal/lsp/debug" "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/span" - "golang.org/x/tools/internal/telemetry/event" ) func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitialize) (*protocol.InitializeResult, error) { diff --git a/internal/lsp/generate.go b/internal/lsp/generate.go index 2bcd037c3..054b7653a 100644 --- a/internal/lsp/generate.go +++ b/internal/lsp/generate.go @@ -10,10 +10,10 @@ import ( "math/rand" "strconv" + "golang.org/x/tools/internal/event" "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/telemetry/event" "golang.org/x/xerrors" ) diff --git a/internal/lsp/highlight.go b/internal/lsp/highlight.go index 9ff37e99f..ef72c5498 100644 --- a/internal/lsp/highlight.go +++ b/internal/lsp/highlight.go @@ -7,10 +7,10 @@ package lsp import ( "context" + "golang.org/x/tools/internal/event" "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/telemetry/event" ) func (s *Server) documentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) { diff --git a/internal/lsp/link.go b/internal/lsp/link.go index 2003ba437..ddb4e768f 100644 --- a/internal/lsp/link.go +++ b/internal/lsp/link.go @@ -17,11 +17,11 @@ import ( "sync" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/event" "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/span" - "golang.org/x/tools/internal/telemetry/event" ) func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLinkParams) (links []protocol.DocumentLink, err error) { diff --git a/internal/lsp/lsprpc/lsprpc.go b/internal/lsp/lsprpc/lsprpc.go index 5662591d5..89cf894c7 100644 --- a/internal/lsp/lsprpc/lsprpc.go +++ b/internal/lsp/lsprpc/lsprpc.go @@ -18,12 +18,12 @@ import ( "time" "golang.org/x/sync/errgroup" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" "golang.org/x/tools/internal/lsp" "golang.org/x/tools/internal/lsp/cache" "golang.org/x/tools/internal/lsp/debug" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" ) // AutoNetwork is the pseudo network type used to signal that gopls should use diff --git a/internal/lsp/lsprpc/lsprpc_test.go b/internal/lsp/lsprpc/lsprpc_test.go index 67db2145e..cc2a40fd6 100644 --- a/internal/lsp/lsprpc/lsprpc_test.go +++ b/internal/lsp/lsprpc/lsprpc_test.go @@ -11,13 +11,13 @@ import ( "testing" "time" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" "golang.org/x/tools/internal/jsonrpc2/servertest" "golang.org/x/tools/internal/lsp/cache" "golang.org/x/tools/internal/lsp/debug" "golang.org/x/tools/internal/lsp/fake" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" ) type fakeClient struct { diff --git a/internal/lsp/mod/code_lens.go b/internal/lsp/mod/code_lens.go index c07fc0db2..096bfba1f 100644 --- a/internal/lsp/mod/code_lens.go +++ b/internal/lsp/mod/code_lens.go @@ -6,11 +6,11 @@ import ( "strings" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/event" "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/span" - "golang.org/x/tools/internal/telemetry/event" ) func CodeLens(ctx context.Context, snapshot source.Snapshot, uri span.URI) ([]protocol.CodeLens, error) { diff --git a/internal/lsp/mod/diagnostics.go b/internal/lsp/mod/diagnostics.go index df407ee3c..5b64fa900 100644 --- a/internal/lsp/mod/diagnostics.go +++ b/internal/lsp/mod/diagnostics.go @@ -10,10 +10,10 @@ import ( "context" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/event" "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/telemetry/event" ) func Diagnostics(ctx context.Context, snapshot source.Snapshot) (map[source.FileIdentity][]*source.Diagnostic, map[string]*modfile.Require, error) { diff --git a/internal/lsp/mod/format.go b/internal/lsp/mod/format.go index 4f97ce46c..060877f09 100644 --- a/internal/lsp/mod/format.go +++ b/internal/lsp/mod/format.go @@ -3,9 +3,9 @@ package mod import ( "context" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/telemetry/event" ) func Format(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle) ([]protocol.TextEdit, error) { diff --git a/internal/lsp/mod/hover.go b/internal/lsp/mod/hover.go index 4e2609643..bab9f5f00 100644 --- a/internal/lsp/mod/hover.go +++ b/internal/lsp/mod/hover.go @@ -8,10 +8,10 @@ import ( "strings" "golang.org/x/mod/modfile" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" ) func Hover(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle, position protocol.Position) (*protocol.Hover, error) { diff --git a/internal/lsp/protocol/context.go b/internal/lsp/protocol/context.go index 560de4dbd..d526e2cf0 100644 --- a/internal/lsp/protocol/context.go +++ b/internal/lsp/protocol/context.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "golang.org/x/tools/internal/telemetry/event" + "golang.org/x/tools/internal/event/core" "golang.org/x/tools/internal/xcontext" ) @@ -18,7 +18,7 @@ func WithClient(ctx context.Context, client Client) context.Context { return context.WithValue(ctx, clientKey, client) } -func LogEvent(ctx context.Context, ev event.Event, tags event.TagMap) context.Context { +func LogEvent(ctx context.Context, ev core.Event, tags core.TagMap) context.Context { if !ev.IsLog() { return ctx } @@ -27,7 +27,7 @@ func LogEvent(ctx context.Context, ev event.Event, tags event.TagMap) context.Co return ctx } msg := &LogMessageParams{Type: Info, Message: fmt.Sprint(ev)} - if event.Err.Get(tags) != nil { + if core.Err.Get(tags) != nil { msg.Type = Error } go client.LogMessage(xcontext.Detach(ctx), msg) diff --git a/internal/lsp/protocol/protocol.go b/internal/lsp/protocol/protocol.go index 8dded0526..18e9181ae 100644 --- a/internal/lsp/protocol/protocol.go +++ b/internal/lsp/protocol/protocol.go @@ -9,8 +9,8 @@ import ( "encoding/json" "fmt" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/xcontext" ) diff --git a/internal/lsp/signature_help.go b/internal/lsp/signature_help.go index 8bf43f694..fad317d14 100644 --- a/internal/lsp/signature_help.go +++ b/internal/lsp/signature_help.go @@ -7,10 +7,11 @@ package lsp import ( "context" + "golang.org/x/tools/internal/event" + "golang.org/x/tools/internal/event/core" "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/telemetry/event" ) func (s *Server) signatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) { @@ -20,7 +21,7 @@ func (s *Server) signatureHelp(ctx context.Context, params *protocol.SignatureHe } info, activeParameter, err := source.SignatureHelp(ctx, snapshot, fh, params.Position) if err != nil { - event.Print(ctx, "no signature help", tag.Position.Of(params.Position), event.Err.Of(err)) + event.Print(ctx, "no signature help", tag.Position.Of(params.Position), core.Err.Of(err)) return nil, nil } return &protocol.SignatureHelp{ diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index e3defa233..39a757638 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -20,11 +20,11 @@ import ( "time" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/imports" "golang.org/x/tools/internal/lsp/fuzzy" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/snippet" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/completion_format.go b/internal/lsp/source/completion_format.go index 88ff10299..9b2c0c760 100644 --- a/internal/lsp/source/completion_format.go +++ b/internal/lsp/source/completion_format.go @@ -11,12 +11,12 @@ import ( "go/types" "strings" + "golang.org/x/tools/internal/event" "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/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/completion_literal.go b/internal/lsp/source/completion_literal.go index fa6c71ada..381c4c4c5 100644 --- a/internal/lsp/source/completion_literal.go +++ b/internal/lsp/source/completion_literal.go @@ -12,10 +12,10 @@ import ( "strings" "unicode" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/diff" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/snippet" - "golang.org/x/tools/internal/telemetry/event" ) // literal generates composite literal, function literal, and make() diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index 67fbe7505..869167439 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -13,10 +13,10 @@ import ( "golang.org/x/mod/modfile" "golang.org/x/tools/go/analysis" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/debug/tag" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go index c6c96fd4d..5b92ab6bf 100644 --- a/internal/lsp/source/format.go +++ b/internal/lsp/source/format.go @@ -14,11 +14,11 @@ import ( "go/scanner" "go/token" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/imports" "golang.org/x/tools/internal/lsp/diff" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/highlight.go b/internal/lsp/source/highlight.go index 5b92a26b0..0917aeea2 100644 --- a/internal/lsp/source/highlight.go +++ b/internal/lsp/source/highlight.go @@ -13,8 +13,8 @@ import ( "strings" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go index b15cccbb1..9b85b6610 100644 --- a/internal/lsp/source/hover.go +++ b/internal/lsp/source/hover.go @@ -14,8 +14,8 @@ import ( "go/types" "strings" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/identifier.go b/internal/lsp/source/identifier.go index f6e79072f..f11c4e561 100644 --- a/internal/lsp/source/identifier.go +++ b/internal/lsp/source/identifier.go @@ -13,8 +13,8 @@ import ( "strconv" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/implementation.go b/internal/lsp/source/implementation.go index 29da25f87..ddebb487d 100644 --- a/internal/lsp/source/implementation.go +++ b/internal/lsp/source/implementation.go @@ -12,8 +12,8 @@ import ( "go/token" "go/types" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" ) func Implementation(ctx context.Context, s Snapshot, f FileHandle, pp protocol.Position) ([]protocol.Location, error) { diff --git a/internal/lsp/source/references.go b/internal/lsp/source/references.go index a6d35e8f8..0cc492233 100644 --- a/internal/lsp/source/references.go +++ b/internal/lsp/source/references.go @@ -10,8 +10,8 @@ import ( "go/token" "go/types" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/rename.go b/internal/lsp/source/rename.go index 6f79e2654..c0026b653 100644 --- a/internal/lsp/source/rename.go +++ b/internal/lsp/source/rename.go @@ -14,10 +14,10 @@ import ( "regexp" "golang.org/x/tools/go/types/typeutil" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/diff" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/refactor/satisfy" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/signature_help.go b/internal/lsp/source/signature_help.go index 20d2431a3..e6584929f 100644 --- a/internal/lsp/source/signature_help.go +++ b/internal/lsp/source/signature_help.go @@ -13,8 +13,8 @@ import ( "go/types" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" errors "golang.org/x/xerrors" ) diff --git a/internal/lsp/source/symbols.go b/internal/lsp/source/symbols.go index 8b09f81dc..bc4e2b70f 100644 --- a/internal/lsp/source/symbols.go +++ b/internal/lsp/source/symbols.go @@ -10,8 +10,8 @@ import ( "go/ast" "go/types" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" ) func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]protocol.DocumentSymbol, error) { diff --git a/internal/lsp/source/workspace_symbol.go b/internal/lsp/source/workspace_symbol.go index 5d458a5ce..70f730a1f 100644 --- a/internal/lsp/source/workspace_symbol.go +++ b/internal/lsp/source/workspace_symbol.go @@ -11,9 +11,9 @@ import ( "go/types" "strings" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/fuzzy" "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/telemetry/event" ) const maxSymbols = 100 diff --git a/internal/lsp/symbols.go b/internal/lsp/symbols.go index 11e89e163..59eb52cfe 100644 --- a/internal/lsp/symbols.go +++ b/internal/lsp/symbols.go @@ -7,10 +7,10 @@ package lsp import ( "context" + "golang.org/x/tools/internal/event" "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/telemetry/event" ) func (s *Server) documentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]interface{}, error) { diff --git a/internal/lsp/workspace_symbol.go b/internal/lsp/workspace_symbol.go index d26a507d7..07718f992 100644 --- a/internal/lsp/workspace_symbol.go +++ b/internal/lsp/workspace_symbol.go @@ -7,9 +7,9 @@ package lsp import ( "context" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/telemetry/event" ) func (s *Server) symbol(ctx context.Context, params *protocol.WorkspaceSymbolParams) ([]protocol.SymbolInformation, error) { diff --git a/internal/telemetry/doc.go b/internal/telemetry/doc.go deleted file mode 100644 index 2e388865e..000000000 --- a/internal/telemetry/doc.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package telemetry provides a set of packages that cover the main -// concepts of telemetry in an implementation agnostic way. -// The interface for libraries that want to expose telemetry is the event -// package. -// As a binary author you might look at exporter for methods of exporting the -// telemetry to external tools. -package telemetry