start reworking exporters to be more composable
This commit is contained in:
40
pkg/combined_exporter/combined_exporter.go
Normal file
40
pkg/combined_exporter/combined_exporter.go
Normal file
@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user