From b25409ba2cbce2172d2843329978d8f01eeeb174 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 10 Aug 2023 13:41:43 -0700 Subject: [PATCH] Do not use sdk/metric/aggregation in stdoutmetric exporter --- exporters/stdout/stdoutmetric/config.go | 19 +------------------ exporters/stdout/stdoutmetric/exporter.go | 3 +-- .../stdout/stdoutmetric/exporter_test.go | 7 +++---- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/exporters/stdout/stdoutmetric/config.go b/exporters/stdout/stdoutmetric/config.go index 9b62bde5083f..6189c019f371 100644 --- a/exporters/stdout/stdoutmetric/config.go +++ b/exporters/stdout/stdoutmetric/config.go @@ -17,9 +17,7 @@ import ( "encoding/json" "os" - "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/metric/aggregation" ) // config contains options for the exporter. @@ -100,22 +98,7 @@ func (t temporalitySelectorOption) apply(c config) config { // package or the aggregation explicitly passed for a view matching an // instrument. func WithAggregationSelector(selector metric.AggregationSelector) Option { - // Deep copy and validate before using. - wrapped := func(ik metric.InstrumentKind) aggregation.Aggregation { - a := selector(ik) - cpA := a.Copy() - if err := cpA.Err(); err != nil { - cpA = metric.DefaultAggregationSelector(ik) - global.Error( - err, "using default aggregation instead", - "aggregation", a, - "replacement", cpA, - ) - } - return cpA - } - - return aggregationSelectorOption{selector: wrapped} + return aggregationSelectorOption{selector: selector} } type aggregationSelectorOption struct { diff --git a/exporters/stdout/stdoutmetric/exporter.go b/exporters/stdout/stdoutmetric/exporter.go index e3d867e00dc8..c223a84da59c 100644 --- a/exporters/stdout/stdoutmetric/exporter.go +++ b/exporters/stdout/stdoutmetric/exporter.go @@ -23,7 +23,6 @@ import ( "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/metricdata" ) @@ -58,7 +57,7 @@ func (e *exporter) Temporality(k metric.InstrumentKind) metricdata.Temporality { return e.temporalitySelector(k) } -func (e *exporter) Aggregation(k metric.InstrumentKind) aggregation.Aggregation { +func (e *exporter) Aggregation(k metric.InstrumentKind) metric.Aggregation { return e.aggregationSelector(k) } diff --git a/exporters/stdout/stdoutmetric/exporter_test.go b/exporters/stdout/stdoutmetric/exporter_test.go index 72feb08c2fbc..71679d623a1f 100644 --- a/exporters/stdout/stdoutmetric/exporter_test.go +++ b/exporters/stdout/stdoutmetric/exporter_test.go @@ -26,7 +26,6 @@ import ( "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/metricdata" ) @@ -115,8 +114,8 @@ func TestTemporalitySelector(t *testing.T) { assert.Equal(t, metricdata.DeltaTemporality, exp.Temporality(unknownKind)) } -func dropSelector(metric.InstrumentKind) aggregation.Aggregation { - return aggregation.Drop{} +func dropSelector(metric.InstrumentKind) metric.Aggregation { + return metric.AggregationDrop{} } func TestAggregationSelector(t *testing.T) { @@ -127,5 +126,5 @@ func TestAggregationSelector(t *testing.T) { require.NoError(t, err) var unknownKind metric.InstrumentKind - assert.Equal(t, aggregation.Drop{}, exp.Aggregation(unknownKind)) + assert.Equal(t, metric.AggregationDrop{}, exp.Aggregation(unknownKind)) }