1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:14:43 -07:00

internal/lsp: build the wire.Node lazily

this is needed to move to a model where we do not need to have
the wire form at all

Change-Id: I3b3693e027b568de4e8b4d10f7d5dd022a616e2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208958
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Cottrell 2019-11-26 13:47:17 -05:00
parent 69a79c76c7
commit 9fe613bd66

View File

@ -46,7 +46,6 @@ func Discover() *Config {
type exporter struct {
mu sync.Mutex
config Config
node *wire.Node
spans []*telemetry.Span
metrics []telemetry.MetricData
}
@ -78,21 +77,6 @@ func Connect(config *Config) export.Exporter {
if exporter.config.Rate == 0 {
exporter.config.Rate = 2 * time.Second
}
exporter.node = &wire.Node{
Identifier: &wire.ProcessIdentifier{
HostName: exporter.config.Host,
Pid: exporter.config.Process,
StartTimestamp: convertTimestamp(exporter.config.Start),
},
LibraryInfo: &wire.LibraryInfo{
Language: wire.LanguageGo,
ExporterVersion: "0.0.1",
CoreLibraryVersion: "x/tools",
},
ServiceInfo: &wire.ServiceInfo{
Name: exporter.config.Service,
},
}
go func() {
for _ = range time.Tick(exporter.config.Rate) {
exporter.Flush()
@ -133,20 +117,38 @@ func (e *exporter) Flush() {
if len(spans) > 0 {
e.send("/v1/trace", &wire.ExportTraceServiceRequest{
Node: e.node,
Node: e.buildNode(),
Spans: spans,
//TODO: Resource?
})
}
if len(metrics) > 0 {
e.send("/v1/metrics", &wire.ExportMetricsServiceRequest{
Node: e.node,
Node: e.buildNode(),
Metrics: metrics,
//TODO: Resource?
})
}
}
func (e *exporter) buildNode() *wire.Node {
return &wire.Node{
Identifier: &wire.ProcessIdentifier{
HostName: e.config.Host,
Pid: e.config.Process,
StartTimestamp: convertTimestamp(e.config.Start),
},
LibraryInfo: &wire.LibraryInfo{
Language: wire.LanguageGo,
ExporterVersion: "0.0.1",
CoreLibraryVersion: "x/tools",
},
ServiceInfo: &wire.ServiceInfo{
Name: e.config.Service,
},
}
}
func EncodeAnnotation(a telemetry.Event) ([]byte, error) {
return json.Marshal(convertAnnotation(a))
}