From 68241aff1da6635ff2491f036aafd471a2bd27c8 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 9 Oct 2023 10:04:32 -0400 Subject: [PATCH] opencensus.NewMetricProducer returns a struct instead of the metric.Producer (#4583) --- CHANGELOG.md | 4 ++++ bridge/opencensus/metric.go | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5516792..94870c638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Deprecate `go.opentelemetry.io/otel/bridge/opencensus.NewTracer` in favor of `opencensus.InstallTraceBridge`. (#4567) +### Changed + +- `go.opentelemetry.io/otel/bridge/opencensus.NewMetricProducer` returns a `*MetricProducer` struct instead of the metric.Producer interface. (#4583) + ## [1.19.0/0.42.0/0.0.7] 2023-09-28 This release contains the first stable release of the OpenTelemetry Go [metric SDK]. diff --git a/bridge/opencensus/metric.go b/bridge/opencensus/metric.go index d11b1de21..577c311f3 100644 --- a/bridge/opencensus/metric.go +++ b/bridge/opencensus/metric.go @@ -26,19 +26,25 @@ import ( "go.opentelemetry.io/otel/sdk/metric/metricdata" ) -type producer struct { +// MetricProducer implements the [go.opentelemetry.io/otel/sdk/metric.Producer] to provide metrics +// from OpenCensus to the OpenTelemetry SDK. +type MetricProducer struct { manager *metricproducer.Manager } // NewMetricProducer returns a metric.Producer that fetches metrics from // OpenCensus. -func NewMetricProducer(opts ...MetricOption) metric.Producer { - return &producer{ +func NewMetricProducer(opts ...MetricOption) *MetricProducer { + return &MetricProducer{ manager: metricproducer.GlobalManager(), } } -func (p *producer) Produce(context.Context) ([]metricdata.ScopeMetrics, error) { +var _ metric.Producer = (*MetricProducer)(nil) + +// Produce fetches metrics from the OpenCensus manager, +// translates them to OpenTelemetry's data model, and returns them. +func (p *MetricProducer) Produce(context.Context) ([]metricdata.ScopeMetrics, error) { producers := p.manager.GetAll() data := []*ocmetricdata.Metric{} for _, ocProducer := range producers {