зеркало из https://github.com/golang/tools.git
internal/telemetry: renaming to internal/event
internal/telemetry/event was renamed to internal/event/core Some things were partly moved from internal/telemetry/event straight to internal/event to minimize churn in the following restructuring. Change-Id: I8511241c68d2d05f64c52dbe04748086dd325158 Reviewed-on: https://go-review.googlesource.com/c/tools/+/229237 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Родитель
72e4a01eba
Коммит
cf0cb92717
|
@ -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
|
||||
}
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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 {
|
|
@ -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"
|
|
@ -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
|
|
@ -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)
|
||||
}
|
|
@ -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
|
|
@ -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")
|
|
@ -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)
|
||||
}
|
|
@ -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
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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 {
|
|
@ -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{
|
|
@ -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 + `
|
|
@ -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()
|
||||
}
|
|
@ -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{}
|
|
@ -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) {
|
|
@ -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)
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче