Skip to content

Commit

Permalink
Add none option for metrics producers
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham <[email protected]>
  • Loading branch information
gouthamve committed Apr 24, 2024
1 parent c317395 commit c6e6648
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions exporters/autoexport/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions exporters/autoexport/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

0 comments on commit c6e6648

Please sign in to comment.