Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exporter creation functions #1985

Merged
merged 14 commits into from
Jun 10, 2021
Merged
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `Get` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931)
- The `Insert` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a pair of `string`s instead of an `attribute.KeyValue` type. (#1931)
- The `Delete` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931)
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/stdout` package. (#1985)
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/metric/prometheus` package. (#1985)
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/trace/jaeger` package. (#1985)
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/trace/zipkin` package. (#1985)
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/otlp` package. (#1985)
- Rename `NewUnstartedExporter` to `NewUnstarted` in the `go.opentelemetry.io/otel/exporters/otlp` package. (#1985)

### Deprecated

Expand All @@ -96,6 +102,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `IsEmpty` method of the `TraceState` type in the `go.opentelemetry.io/otel/trace` package is removed in favor of using the added `TraceState.Len` method. (#1931)
- The `Set`, `Value`, `ContextWithValue`, `ContextWithoutValue`, and `ContextWithEmpty` functions in the `go.opentelemetry.io/otel/baggage` package are removed.
Handling of baggage is now done using the added `Baggage` type and related context functions (`ContextWithBaggage`, `ContextWithoutBaggage`, and `FromContext`) in that package. (TBD)
- The `InstallNewPipeline` and `NewExportPipeline` creation functions in all the exporters (prometheus, otlp, stdout, jaeger, and zipkin) have been removed.
These functions were deemed premature attempts to provide convenience that did not achieve this aim. (#1985)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import (
// import logexporter "go.opencensus.io/examples/exporter"
// exporter, _ := logexporter.NewLogExporter(logexporter.Options{})
// Instead, we can create an equivalent using the OpenTelemetry stdout exporter:
openTelemetryExporter, _ := stdout.NewExporter(stdout.WithPrettyPrint())
openTelemetryExporter, _ := stdout.New(stdout.WithPrettyPrint())
exporter := opencensus.NewMetricExporter(openTelemetryExporter)

// Use the wrapped OpenTelemetry exporter like you normally would with OpenCensus
Expand Down
2 changes: 1 addition & 1 deletion example/jaeger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
// about the application.
func tracerProvider(url string) (*tracesdk.TracerProvider, error) {
// Create the Jaeger exporter
exp, err := jaeger.NewRawExporter(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion example/namedtracer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var tp *sdktrace.TracerProvider
// initTracer creates and registers trace provider instance.
func initTracer() {
var err error
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
exp, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
return
Expand Down
2 changes: 1 addition & 1 deletion example/opencensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (

func main() {
log.Println("Using OpenTelemetry stdout exporter.")
otExporter, err := stdout.NewExporter(stdout.WithPrettyPrint())
otExporter, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example/otel-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func initProvider() func() {
otlpgrpc.WithEndpoint("localhost:30080"),
otlpgrpc.WithDialOption(grpc.WithBlock()), // useful for testing
)
exp, err := otlp.NewExporter(ctx, driver)
exp, err := otlp.New(ctx, driver)
handleErr(err, "failed to create exporter")

res, err := resource.New(ctx,
Expand Down
2 changes: 1 addition & 1 deletion example/passthrough/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ But the following will propagate context _and_ create new, potentially recorded

```golang
// Setup SDK
exp, _ := stdout.NewExporter(stdout.WithPrettyPrint())
exp, _ := stdout.New(stdout.WithPrettyPrint())
tp = sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exp),
)
Expand Down
2 changes: 1 addition & 1 deletion example/passthrough/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func initPassthroughGlobals() {
// set it as the global tracer provider
func nonGlobalTracer() *sdktrace.TracerProvider {
var err error
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
exp, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions example/prom-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func initMeter() {
otlpgrpc.WithEndpoint("localhost:30080"),
otlpgrpc.WithDialOption(grpc.WithBlock()), // useful for testing
)
otlpExporter, err := otlp.NewExporter(ctx, driver)
otlpExporter, err := otlp.New(ctx, driver)

if err != nil {
log.Fatal("could not initialize OTLP:", err)
Expand All @@ -76,7 +76,7 @@ func initMeter() {
log.Fatal("could not start controller:", err)
}

promExporter, err := prometheus.NewExporter(prometheus.Config{}, cont)
promExporter, err := prometheus.New(prometheus.Config{}, cont)
if err != nil {
log.Fatal("could not initialize prometheus:", err)
}
Expand Down
2 changes: 2 additions & 0 deletions example/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require (
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/exporters/metric/prometheus v0.20.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
go.opentelemetry.io/otel/sdk/metric v0.20.0
)

replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus
Expand Down
19 changes: 18 additions & 1 deletion example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,34 @@ import (
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
)

var (
lemonsKey = attribute.Key("ex.com/lemons")
)

func initMeter() {
exporter, err := prometheus.InstallNewPipeline(prometheus.Config{})
config := prometheus.Config{}
c := controller.New(
processor.New(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
processor.WithMemory(true),
),
)
exporter, err := prometheus.New(config, c)
if err != nil {
log.Panicf("failed to initialize prometheus exporter %v", err)
}
global.SetMeterProvider(exporter.MeterProvider())

http.HandleFunc("/", exporter.ServeHTTP)
go func() {
_ = http.ListenAndServe(":2222", nil)
Expand Down
2 changes: 1 addition & 1 deletion example/zipkin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func initTracer(url string) func() {
// For demoing purposes, always sample. In a production application, you should
// configure the sampler to a trace.ParentBased(trace.TraceIDRatioBased) set at the desired
// ratio.
exporter, err := zipkin.NewRawExporter(
exporter, err := zipkin.New(
url,
zipkin.WithLogger(logger),
zipkin.WithSDKOptions(sdktrace.WithSampler(sdktrace.AlwaysSample())),
Expand Down
114 changes: 0 additions & 114 deletions exporters/metric/prometheus/example_test.go

This file was deleted.

41 changes: 3 additions & 38 deletions exporters/metric/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
)

// Exporter supports Prometheus pulls. It does not implement the
Expand Down Expand Up @@ -89,9 +85,9 @@ type Config struct {
DefaultHistogramBoundaries []float64
}

// NewExporter returns a new Prometheus exporter using the configured
// metric controller. See controller.New().
func NewExporter(config Config, controller *controller.Controller) (*Exporter, error) {
// New returns a new Prometheus exporter using the configured metric
// controller. See controller.New().
func New(config Config, controller *controller.Controller) (*Exporter, error) {
if config.Registry == nil {
config.Registry = prometheus.NewRegistry()
}
Expand Down Expand Up @@ -121,37 +117,6 @@ func NewExporter(config Config, controller *controller.Controller) (*Exporter, e
return e, nil
}

// NewExportPipeline sets up a complete export pipeline with the recommended setup,
// using the recommended selector and standard processor. See the controller.Options.
func NewExportPipeline(config Config, options ...controller.Option) (*Exporter, error) {
return NewExporter(config, defaultController(config, options...))
}

// InstallNewPipeline instantiates a NewExportPipeline and registers it globally.
func InstallNewPipeline(config Config, options ...controller.Option) (*Exporter, error) {
exp, err := NewExportPipeline(config, options...)
if err != nil {
return nil, err
}
global.SetMeterProvider(exp.MeterProvider())
return exp, nil
}

// defaultController returns a standard *controller.Controller for use
// with Prometheus.
func defaultController(config Config, options ...controller.Option) *controller.Controller {
return controller.New(
processor.New(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
processor.WithMemory(true),
),
options...,
)
}

// MeterProvider returns the MeterProvider of this exporter.
func (e *Exporter) MeterProvider() metric.MeterProvider {
return e.controller.MeterProvider()
Expand Down
22 changes: 20 additions & 2 deletions exporters/metric/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/metric"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/resource"
)

Expand Down Expand Up @@ -78,8 +82,22 @@ func expectHistogram(name string, values ...string) expectedMetric {
}
}

func newPipeline(config prometheus.Config, options ...controller.Option) (*prometheus.Exporter, error) {
c := controller.New(
processor.New(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
processor.WithMemory(true),
),
options...,
)
return prometheus.New(config, c)
}

func TestPrometheusExporter(t *testing.T) {
exporter, err := prometheus.NewExportPipeline(
exporter, err := newPipeline(
prometheus.Config{
DefaultHistogramBoundaries: []float64{-0.5, 1},
},
Expand Down Expand Up @@ -155,7 +173,7 @@ func compareExport(t *testing.T, exporter *prometheus.Exporter, expected []expec

func TestPrometheusStatefulness(t *testing.T) {
// Create a meter
exporter, err := prometheus.NewExportPipeline(
exporter, err := newPipeline(
prometheus.Config{},
controller.WithCollectPeriod(0),
controller.WithResource(resource.Empty()),
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ The exporter can be installed using standard `go` functionality.
go get -u go.opentelemetry.io/otel/exporters/otlp
```

A new exporter can be created using the `NewExporter` function.
A new exporter can be created using the `New` function.
Loading