internal/telemetry: delay the conversion to wire format
do it just as we are encoding, this is in preparation for making the
encoding faster and cheaper
Change-Id: Ic9715e2750adf276eac152e321d96e249190eacb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207902
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
diff --git a/internal/telemetry/export/ocagent/ocagent.go b/internal/telemetry/export/ocagent/ocagent.go
index cad7e13..eb28d0e 100644
--- a/internal/telemetry/export/ocagent/ocagent.go
+++ b/internal/telemetry/export/ocagent/ocagent.go
@@ -47,7 +47,7 @@
mu sync.Mutex
config Config
node *wire.Node
- spans []*wire.Span
+ spans []*telemetry.Span
metrics []*wire.Metric
}
@@ -106,7 +106,7 @@
func (e *exporter) FinishSpan(ctx context.Context, span *telemetry.Span) {
e.mu.Lock()
defer e.mu.Unlock()
- e.spans = append(e.spans, convertSpan(span))
+ e.spans = append(e.spans, span)
}
func (e *exporter) Log(context.Context, telemetry.Event) {}
@@ -120,7 +120,10 @@
func (e *exporter) Flush() {
e.mu.Lock()
defer e.mu.Unlock()
- spans := e.spans
+ spans := make([]*wire.Span, len(e.spans))
+ for i, s := range e.spans {
+ spans[i] = convertSpan(s)
+ }
e.spans = nil
metrics := e.metrics
e.metrics = nil