observer/pkg/combined_exporter/combined_exporter.go

41 lines
803 B
Go

package combined_exporter
import (
"context"
"fmt"
"go.opentelemetry.io/otel/sdk/trace"
)
type Exporter struct {
exporters []trace.SpanExporter
}
func NewExporter(exporters ...trace.SpanExporter) trace.SpanExporter {
return &Exporter{
exporters: exporters,
}
}
// Implements [trace.SpanExporter]
func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) error {
for _, exp := range e.exporters {
exp.ExportSpans(ctx, spans)
}
return nil
}
// Implements [trace.SpanExporter]
func (e *Exporter) Shutdown(ctx context.Context) error {
var errs []error
for _, exp := range e.exporters {
err := exp.Shutdown(ctx)
if err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
return fmt.Errorf("multiple erros have occured: %#v", errs)
}
return nil
}