Skip to content

Commit

Permalink
Do not use sdk/metric/aggregation in stdoutmetric exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 10, 2023
1 parent 38420d7 commit b25409b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
19 changes: 1 addition & 18 deletions exporters/stdout/stdoutmetric/config.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions exporters/stdout/stdoutmetric/exporter.go
Expand Up @@ -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"
)

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

Expand Down
7 changes: 3 additions & 4 deletions exporters/stdout/stdoutmetric/exporter_test.go
Expand Up @@ -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"
)

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

0 comments on commit b25409b

Please sign in to comment.