1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package export 6 7import ( 8 "context" 9 10 "golang.org/x/tools/internal/telemetry" 11) 12 13// Multi returns an exporter that invokes all the exporters given to it in order. 14func Multi(e ...Exporter) Exporter { 15 a := make(multi, 0, len(e)) 16 for _, i := range e { 17 if i == nil { 18 continue 19 } 20 if i, ok := i.(multi); ok { 21 a = append(a, i...) 22 continue 23 } 24 a = append(a, i) 25 } 26 return a 27} 28 29type multi []Exporter 30 31func (m multi) StartSpan(ctx context.Context, span *telemetry.Span) { 32 for _, o := range m { 33 o.StartSpan(ctx, span) 34 } 35} 36func (m multi) FinishSpan(ctx context.Context, span *telemetry.Span) { 37 for _, o := range m { 38 o.FinishSpan(ctx, span) 39 } 40} 41func (m multi) Log(ctx context.Context, event telemetry.Event) { 42 for _, o := range m { 43 o.Log(ctx, event) 44 } 45} 46func (m multi) Metric(ctx context.Context, data telemetry.MetricData) { 47 for _, o := range m { 48 o.Metric(ctx, data) 49 } 50} 51func (m multi) Flush() { 52 for _, o := range m { 53 o.Flush() 54 } 55} 56