Skip to content

Commit 5165b0f

Browse files
thaJeztahndeloof
authored andcommitted
internal/tracing: replace go-multierror.Group with sync.WaitGroup
The go-multierror Group is just a shallow wrapper around sync.WaitGroup; https://github.com/hashicorp/go-multierror/blob/v1.1.1/group.go#L5-L38 This patch replaces the go-multierror.Group for a sync.WaitGroup (we probably don't need to limit concurrency for this one) and stdlib multi- errors. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 93dd1a4 commit 5165b0f

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

internal/tracing/mux.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ package tracing
1818

1919
import (
2020
"context"
21+
"errors"
22+
"sync"
2123

22-
"github.com/hashicorp/go-multierror"
2324
sdktrace "go.opentelemetry.io/otel/sdk/trace"
2425
)
2526

@@ -28,23 +29,45 @@ type MuxExporter struct {
2829
}
2930

3031
func (m MuxExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
31-
var eg multierror.Group
32-
for i := range m.exporters {
33-
exporter := m.exporters[i]
34-
eg.Go(func() error {
35-
return exporter.ExportSpans(ctx, spans)
36-
})
32+
var (
33+
wg sync.WaitGroup
34+
errMu sync.Mutex
35+
errs = make([]error, 0, len(m.exporters))
36+
)
37+
38+
for _, exporter := range m.exporters {
39+
wg.Add(1)
40+
go func() {
41+
defer wg.Done()
42+
if err := exporter.ExportSpans(ctx, spans); err != nil {
43+
errMu.Lock()
44+
errs = append(errs, err)
45+
errMu.Unlock()
46+
}
47+
}()
3748
}
38-
return eg.Wait()
49+
wg.Wait()
50+
return errors.Join(errs...)
3951
}
4052

4153
func (m MuxExporter) Shutdown(ctx context.Context) error {
42-
var eg multierror.Group
43-
for i := range m.exporters {
44-
exporter := m.exporters[i]
45-
eg.Go(func() error {
46-
return exporter.Shutdown(ctx)
47-
})
54+
var (
55+
wg sync.WaitGroup
56+
errMu sync.Mutex
57+
errs = make([]error, 0, len(m.exporters))
58+
)
59+
60+
for _, exporter := range m.exporters {
61+
wg.Add(1)
62+
go func() {
63+
defer wg.Done()
64+
if err := exporter.Shutdown(ctx); err != nil {
65+
errMu.Lock()
66+
errs = append(errs, err)
67+
errMu.Unlock()
68+
}
69+
}()
4870
}
49-
return eg.Wait()
71+
wg.Wait()
72+
return errors.Join(errs...)
5073
}

0 commit comments

Comments
 (0)