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 c90ff9d
Show file tree
Hide file tree
Showing 2 changed files with 21 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
18 changes: 18 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,20 @@ 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 c90ff9d

Please sign in to comment.