Skip to content

Commit

Permalink
Document the split driver
Browse files Browse the repository at this point in the history
  • Loading branch information
krnowak committed Dec 22, 2020
1 parent 2b3b1f5 commit 3a0b0c5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion exporters/otlp/protocoldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ type ProtocolDriver interface {
ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error
}

// SplitConfig is used to configure a split driver.
type SplitConfig struct {
// ForMetrics driver will be used for sending metrics to the
// collector.
ForMetrics ProtocolDriver
ForTraces ProtocolDriver
// ForTraces driver will be used for sending spans to the
// collector.
ForTraces ProtocolDriver
}

type splitDriver struct {
Expand All @@ -73,6 +78,8 @@ func NewSplitDriver(cfg SplitConfig) ProtocolDriver {
}
}

// Start implements ProtocolDriver. It starts both drivers at the same
// time.
func (d *splitDriver) Start(ctx context.Context) error {
wg := sync.WaitGroup{}
wg.Add(2)
Expand All @@ -98,6 +105,8 @@ func (d *splitDriver) Start(ctx context.Context) error {
return nil
}

// Stop implements ProtocolDriver. It stops both drivers at the same
// time.
func (d *splitDriver) Stop(ctx context.Context) error {
wg := sync.WaitGroup{}
wg.Add(2)
Expand All @@ -123,10 +132,14 @@ func (d *splitDriver) Stop(ctx context.Context) error {
return nil
}

// ExportMetrics implements ProtocolDriver. It forwards the call to
// the driver used for sending metrics.
func (d *splitDriver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
return d.metric.ExportMetrics(ctx, cps, selector)
}

// ExportTraces implements ProtocolDriver. It forwards the call to the
// driver used for sending spans.
func (d *splitDriver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
return d.trace.ExportTraces(ctx, ss)
}

0 comments on commit 3a0b0c5

Please sign in to comment.