1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:44:49 -07:00
go/internal/telemetry/export/multi.go
Ian Cottrell 5b08f89bfc internal/telemetry: clean up the exporter api
this shuffles things so there a single exporter API rather than an observer
It also removes most of the globals.
per telemetry type.

Change-Id: Iaa82abe2ded1fff9df8e067ed4a55bcbd9d9591f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190405
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-15 23:56:12 +00:00

51 lines
1.0 KiB
Go

// 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 export
import (
"context"
"golang.org/x/tools/internal/telemetry"
)
// Multi returns an exporter that invokes all the exporters given to it in order.
func Multi(e ...Exporter) Exporter {
a := make(multi, 0, len(e))
for _, i := range e {
if i == nil {
continue
}
if i, ok := i.(multi); ok {
a = append(a, i...)
continue
}
a = append(a, i)
}
return a
}
type multi []Exporter
func (m multi) StartSpan(ctx context.Context, span *telemetry.Span) {
for _, o := range m {
o.StartSpan(ctx, span)
}
}
func (m multi) FinishSpan(ctx context.Context, span *telemetry.Span) {
for _, o := range m {
o.FinishSpan(ctx, span)
}
}
func (m multi) Log(ctx context.Context, event telemetry.Event) {
for _, o := range m {
o.Log(ctx, event)
}
}
func (m multi) Metric(ctx context.Context, data telemetry.MetricData) {
for _, o := range m {
o.Metric(ctx, data)
}
}