Skip to content

Commit

Permalink
Move stackdriver trace exporter to new interface and pdata (#486)
Browse files Browse the repository at this point in the history
* initial changes

* implement factory and fix bugs

* add translation for attributes, links, and events

* update go.mod and go.sum

* initial changes

* implement factory and fix bugs

* add translation for attributes, links, and events

* update go.mod and go.sum

* reset unwanted changes to go.mod and go.sum

* implement MetricExporter

* remove cloud logging

* cleanup

* update factory test under new exporter implementation

* update stackdriver test to use pdata

* add check for null status

* fix bug in stackdriver test

* test for pdata to OT span data conversion

* revert port change in stackdriver test

* update go.mod and go.sum for OT Go stackdriver exporter

* fix import order

* uncapitalize error

* lint and dependencies

* fix mistake in factory test

* pr comments

* gofmt

* Create new context in pushTraces

Co-authored-by: Nail Islamov <[email protected]>

* gofmt

* use factory helpers

* go.sum

* use stackdriverexporter.NewFactory() in components.go

* use latest ot stackdriver exporter

Co-authored-by: Nail Islamov <[email protected]>
  • Loading branch information
stevencl1013 and nilebox authored Aug 6, 2020
1 parent 24c9bcb commit 80509d6
Show file tree
Hide file tree
Showing 12 changed files with 581 additions and 472 deletions.
2 changes: 1 addition & 1 deletion cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func components() (component.Factories, error) {
}

exporters := []component.ExporterFactoryBase{
&stackdriverexporter.Factory{},
stackdriverexporter.NewFactory(),
&azuremonitorexporter.Factory{},
&signalfxexporter.Factory{},
sapmexporter.NewFactory(),
Expand Down
2 changes: 1 addition & 1 deletion exporter/stackdriverexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestLoadConfig(t *testing.T) {
factories, err := componenttest.ExampleComponents()
assert.Nil(t, err)

factory := &Factory{}
factory := NewFactory()
factories.Exporters[configmodels.Type(typeStr)] = factory
cfg, err := configtest.LoadConfigFile(
t, path.Join(".", "testdata", "config.yaml"), factories,
Expand Down
37 changes: 23 additions & 14 deletions exporter/stackdriverexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@
package stackdriverexporter

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.uber.org/zap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

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

// Factory is the factory for Stackdriver exporter.
type Factory struct {
}

// Type gets the type of the Exporter config created by this factory.
func (f *Factory) Type() configmodels.Type {
return configmodels.Type(typeStr)
// NewFactory creates a factory for the stackdriver exporter
func NewFactory() component.ExporterFactory {
return exporterhelper.NewFactory(
typeStr,
createDefaultConfig,
exporterhelper.WithTraces(createTraceExporter),
exporterhelper.WithMetrics(createMetricsExporter),
)
}

// CreateDefaultConfig creates the default configuration for exporter.
func (f *Factory) CreateDefaultConfig() configmodels.Exporter {
// createDefaultConfig creates the default configuration for exporter.
func createDefaultConfig() configmodels.Exporter {
return &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
Expand All @@ -44,14 +47,20 @@ func (f *Factory) CreateDefaultConfig() configmodels.Exporter {
}
}

// CreateTraceExporter creates a trace exporter based on this config.
func (f *Factory) CreateTraceExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.TraceExporterOld, error) {
// createTraceExporter creates a trace exporter based on this config.
func createTraceExporter(
_ context.Context,
_ component.ExporterCreateParams,
cfg configmodels.Exporter) (component.TraceExporter, error) {
eCfg := cfg.(*Config)
return newStackdriverTraceExporter(eCfg)
}

// CreateMetricsExporter creates a metrics exporter based on this config.
func (f *Factory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.MetricsExporterOld, error) {
// createMetricsExporter creates a metrics exporter based on this config.
func createMetricsExporter(
_ context.Context,
_ component.ExporterCreateParams,
cfg configmodels.Exporter) (component.MetricsExporter, error) {
eCfg := cfg.(*Config)
return newStackdriverMetricsExporter(eCfg)
}
15 changes: 11 additions & 4 deletions exporter/stackdriverexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
package stackdriverexporter

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configcheck"
"go.uber.org/zap"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := Factory{}
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, configcheck.ValidateConfig(cfg))
Expand All @@ -34,16 +36,21 @@ func TestCreateExporter(t *testing.T) {
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
t.Skip("Default credentials not set, skip creating Stackdriver exporter")
}
factory := Factory{}
ctx := context.Background()
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
eCfg := cfg.(*Config)
eCfg.ProjectID = "test"

te, err := factory.CreateTraceExporter(zap.NewNop(), eCfg)
te, err := factory.CreateTraceExporter(ctx, component.ExporterCreateParams{
Logger: zap.NewNop(),
}, eCfg)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")

me, err := factory.CreateMetricsExporter(zap.NewNop(), eCfg)
me, err := factory.CreateMetricsExporter(ctx, component.ExporterCreateParams{
Logger: zap.NewNop(),
}, eCfg)
assert.Nil(t, err)
assert.NotNil(t, me, "failed to create metrics exporter")
}
2 changes: 2 additions & 0 deletions exporter/stackdriverexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ go 1.14

require (
contrib.go.opencensus.io/exporter/stackdriver v0.13.1
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v0.2.2-0.20200728233621-2752da7eaab7
github.com/census-instrumentation/opencensus-proto v0.3.0
github.com/golang/protobuf v1.4.2
github.com/stretchr/testify v1.6.1
go.opencensus.io v0.22.4
go.opentelemetry.io/collector v0.7.0
go.opentelemetry.io/otel v0.9.0
go.uber.org/zap v1.15.0
google.golang.org/api v0.29.0
google.golang.org/genproto v0.0.0-20200624020401-64a14ca9d1ad
Expand Down
Loading

0 comments on commit 80509d6

Please sign in to comment.