diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 476aa65eacc0..c0ba46881ff0 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -27,14 +27,13 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/instrument" sdkmetric "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/metric/views" + "go.opentelemetry.io/otel/sdk/metric/view" "go.opentelemetry.io/otel/sdk/resource" ) var ( lemonsKey = attribute.Key("ex.com/lemons") - // TODO Bring back Global package meterProvider metric.MeterProvider ) @@ -45,20 +44,20 @@ func initMeter() metric.MeterProvider { } sdk := sdkmetric.New( - sdkmetric.WithReader(exporter), sdkmetric.WithResource(resource.NewSchemaless(attribute.String("resource", "etc"))), - sdkmetric.WithViews( - views.New( - views.MatchInstrumentName("ex.com.one"), - views.WithName("example_one"), + sdkmetric.WithReader( + exporter, + view.WithClause( + view.MatchInstrumentName("ex.com.one"), + view.WithName("example_one"), ), - views.New( - views.MatchInstrumentName("ex.com.two"), - views.WithName("example_two"), + view.WithClause( + view.MatchInstrumentName("ex.com.two"), + view.WithName("example_two"), ), - views.New( - views.MatchInstrumentName("ex.com.three"), - views.WithName("example_three"), + view.WithClause( + view.MatchInstrumentName("ex.com.three"), + view.WithName("example_three"), ), ), ) diff --git a/exporters/prometheus/prometheus.go b/exporters/prometheus/prometheus.go index 3b2f40ca6517..9816a411dc06 100644 --- a/exporters/prometheus/prometheus.go +++ b/exporters/prometheus/prometheus.go @@ -28,9 +28,9 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregation" "go.opentelemetry.io/otel/sdk/metric/number" - "go.opentelemetry.io/otel/sdk/metric/reader" "go.opentelemetry.io/otel/sdk/metric/sdkinstrument" "go.opentelemetry.io/otel/sdk/resource" ) @@ -44,10 +44,10 @@ type Exporter struct { gatherer prometheus.Gatherer lock sync.Mutex - producer reader.Producer + producer metric.Producer } -var _ reader.Reader = &Exporter{} +var _ metric.Reader = &Exporter{} var _ http.Handler = &Exporter{} // ErrUnsupportedAggregator is returned for unrepresentable aggregator @@ -109,23 +109,23 @@ func (e *Exporter) String() string { return "prometheus" } -func (e *Exporter) Register(p reader.Producer) { +func (e *Exporter) Register(p metric.Producer) { e.lock.Lock() defer e.lock.Unlock() e.producer = p } -func (e *Exporter) getProducer() reader.Producer { +func (e *Exporter) getProducer() metric.Producer { e.lock.Lock() defer e.lock.Unlock() return e.producer } -func (e *Exporter) Flush(ctx context.Context) error { +func (e *Exporter) ForceFlush(_ context.Context) error { return nil } -func (e *Exporter) Shutdown(ctx context.Context) error { +func (e *Exporter) Shutdown(_ context.Context) error { return nil } diff --git a/sdk/metric/reader.go b/sdk/metric/reader.go index 9acc121cd3f0..c31b08ce2cca 100644 --- a/sdk/metric/reader.go +++ b/sdk/metric/reader.go @@ -20,48 +20,46 @@ import ( "go.opentelemetry.io/otel/sdk/metric/data" ) -type ( - // Reader is the interface used between the SDK and an - // exporter. Control flow is bi-directional through the - // Reader, since the SDK initiates ForceFlush and Shutdown - // while the initiates collection. The Register() method here - // informs the Reader that it can begin reading, signaling the - // start of bi-directional control flow. - // - // Typically, push-based exporters that are periodic will - // implement PeroidicExporter themselves and construct a - // PeriodicReader to satisfy this interface. - // - // Pull-based exporters will typically implement Register - // themselves, since they read on demand. - Reader interface { - // String describes this reader. - String() string +// Reader is the interface used between the SDK and an +// exporter. Control flow is bi-directional through the +// Reader, since the SDK initiates ForceFlush and Shutdown +// while the initiates collection. The Register() method here +// informs the Reader that it can begin reading, signaling the +// start of bi-directional control flow. +// +// Typically, push-based exporters that are periodic will +// implement PeroidicExporter themselves and construct a +// PeriodicReader to satisfy this interface. +// +// Pull-based exporters will typically implement Register +// themselves, since they read on demand. +type Reader interface { + // String describes this reader. + String() string - // Register is called when the SDK is fully - // configured. The Producer passed allows the - // Reader to begin collecting metrics using its - // Produce() method. - Register(Producer) + // Register is called when the SDK is fully + // configured. The Producer passed allows the + // Reader to begin collecting metrics using its + // Produce() method. + Register(Producer) - // ForceFlush is called when MeterProvider.ForceFlush() is called. - ForceFlush(context.Context) error + // ForceFlush is called when MeterProvider.ForceFlush() is called. + ForceFlush(context.Context) error - // Shutdown is called when MeterProvider.Shutdown() is called. - Shutdown(context.Context) error - } + // Shutdown is called when MeterProvider.Shutdown() is called. + Shutdown(context.Context) error +} - // Producer is the interface used to perform collection by the reader. - Producer interface { - // Produce returns metrics from a single collection. - // - // Produce may be called concurrently, - // - // The `in` parameter supports re-use of memory from - // one collection to the next. Callers that pass `in` - // will write metrics into the same slices and structs. - // - // When `in` is nil, a new Metrics object is returned. - Produce(in *data.Metrics) data.Metrics - } -) +// Producer is the interface used to perform collection by the reader. +type Producer interface { + // Produce returns metrics from a single collection. + // + // Produce may be called concurrently, + // + // The `in` parameter supports re-use of memory from + // one collection to the next. Callers that pass `in` + // will write metrics into the same slices and structs. + // + // When `in` is nil, a new Metrics object is returned. + Produce(in *data.Metrics) data.Metrics +}