diff --git a/exporters/autoexport/metrics.go b/exporters/autoexport/metrics.go index 2d5e3190f04..3636f706db0 100644 --- a/exporters/autoexport/metrics.go +++ b/exporters/autoexport/metrics.go @@ -206,6 +206,9 @@ func init() { RegisterMetricProducer("prometheus", func(ctx context.Context) (metric.Producer, error) { return prometheusbridge.NewMetricProducer(), nil }) + RegisterMetricProducer("none", func(ctx context.Context) (metric.Producer, error) { + return newNoopMetricProducer(), nil + }) } type readerWithServer struct { diff --git a/exporters/autoexport/noop.go b/exporters/autoexport/noop.go index c0921941d87..9d5750165e6 100644 --- a/exporters/autoexport/noop.go +++ b/exporters/autoexport/noop.go @@ -7,6 +7,7 @@ import ( "context" "go.opentelemetry.io/otel/sdk/metric" + "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/trace" ) @@ -46,3 +47,21 @@ func IsNoneMetricReader(e metric.Reader) bool { _, ok := e.(noopMetricReader) return ok } + +type noopMetricProducer struct { +} + +func (e noopMetricProducer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, error) { + return nil, nil +} + +func newNoopMetricProducer() noopMetricProducer { + return noopMetricProducer{} +} + +// IsNoneMetricReader returns true for the exporter returned by [NewMetricReader] +// when OTEL_METRICS_PRODUCERS environment variable is set to "none". +func IsNoneMetricProducer(e metric.Producer) bool { + _, ok := e.(noopMetricProducer) + return ok +}