mirror of
https://github.com/docker/compose.git
synced 2025-09-21 16:57:51 +02:00
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 <github@gone.nl>
This commit is contained in:
parent
93dd1a4558
commit
5165b0f814
@ -18,8 +18,9 @@ package tracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,23 +29,45 @@ type MuxExporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m MuxExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
|
func (m MuxExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
|
||||||
var eg multierror.Group
|
var (
|
||||||
for i := range m.exporters {
|
wg sync.WaitGroup
|
||||||
exporter := m.exporters[i]
|
errMu sync.Mutex
|
||||||
eg.Go(func() error {
|
errs = make([]error, 0, len(m.exporters))
|
||||||
return exporter.ExportSpans(ctx, spans)
|
)
|
||||||
})
|
|
||||||
|
for _, exporter := range m.exporters {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := exporter.ExportSpans(ctx, spans); err != nil {
|
||||||
|
errMu.Lock()
|
||||||
|
errs = append(errs, err)
|
||||||
|
errMu.Unlock()
|
||||||
}
|
}
|
||||||
return eg.Wait()
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MuxExporter) Shutdown(ctx context.Context) error {
|
func (m MuxExporter) Shutdown(ctx context.Context) error {
|
||||||
var eg multierror.Group
|
var (
|
||||||
for i := range m.exporters {
|
wg sync.WaitGroup
|
||||||
exporter := m.exporters[i]
|
errMu sync.Mutex
|
||||||
eg.Go(func() error {
|
errs = make([]error, 0, len(m.exporters))
|
||||||
return exporter.Shutdown(ctx)
|
)
|
||||||
})
|
|
||||||
|
for _, exporter := range m.exporters {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := exporter.Shutdown(ctx); err != nil {
|
||||||
|
errMu.Lock()
|
||||||
|
errs = append(errs, err)
|
||||||
|
errMu.Unlock()
|
||||||
}
|
}
|
||||||
return eg.Wait()
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user