forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi.go
55 lines (49 loc) · 1.1 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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"
"github.com/jackie-feng/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)
}
}
func (m multi) Flush() {
for _, o := range m {
o.Flush()
}
}