Skip to content

Commit

Permalink
use delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Mar 16, 2021
1 parent 0132d1a commit f0cc87d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
32 changes: 12 additions & 20 deletions exporter/googlecloudexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,30 @@ var once sync.Once

// NewFactory creates a factory for the googlecloud exporter
func NewFactory() component.ExporterFactory {
return NewFactoryWithTypeStr(typeStr)
}

// creates a factory for the googlecloud exporter, overriding the type string
// used in config
func NewFactoryWithTypeStr(ts string) component.ExporterFactory {
// register view for self-observability
once.Do(func() {
view.Register(viewPointCount)
})

return exporterhelper.NewFactory(
configmodels.Type(ts),
createDefaultConfigWithTypeStr(ts),
typeStr,
createDefaultConfig,
exporterhelper.WithTraces(createTraceExporter),
exporterhelper.WithMetrics(createMetricsExporter),
)
}

// createDefaultConfig creates the default configuration for exporter.
func createDefaultConfigWithTypeStr(ts string) exporterhelper.CreateDefaultConfig {
return func() configmodels.Exporter {
return &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(ts),
NameVal: ts,
},
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
UserAgent: "opentelemetry-collector-contrib {{version}}",
}
func createDefaultConfig() configmodels.Exporter {
return &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
},
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
UserAgent: "opentelemetry-collector-contrib {{version}}",
}
}

Expand Down
43 changes: 42 additions & 1 deletion exporter/stackdriverexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,58 @@
package stackdriverexporter

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter"
)

type factory struct {
delegate component.ExporterFactory
}

const (
// The value of "type" key in configuration.
typeStr = "stackdriver"
)

// NewFactory creates a factory for the stackdriver exporter
func NewFactory() component.ExporterFactory {
return googlecloudexporter.NewFactoryWithTypeStr(typeStr)
return &factory{delegate: googlecloudexporter.NewFactory()}
}

func (*factory) Type() configmodels.Type {
return configmodels.Type(typeStr)
}

func (f *factory) CreateDefaultConfig() configmodels.Exporter {
cfg := f.delegate.CreateDefaultConfig()
cfg.(*googlecloudexporter.Config).TypeVal = f.Type()
return cfg
}

func (f *factory) CreateTracesExporter(
ctx context.Context,
params component.ExporterCreateParams,
cfg configmodels.Exporter,
) (component.TracesExporter, error) {
return f.delegate.CreateTracesExporter(ctx, params, cfg)
}

func (f *factory) CreateMetricsExporter(
ctx context.Context,
params component.ExporterCreateParams,
cfg configmodels.Exporter,
) (component.MetricsExporter, error) {
return f.delegate.CreateMetricsExporter(ctx, params, cfg)
}

func (f *factory) CreateLogsExporter(
ctx context.Context,
params component.ExporterCreateParams,
cfg configmodels.Exporter,
) (component.LogsExporter, error) {
return f.delegate.CreateLogsExporter(ctx, params, cfg)
}

0 comments on commit f0cc87d

Please sign in to comment.