Skip to content

Commit

Permalink
attempt to add temporality preference
Browse files Browse the repository at this point in the history
  • Loading branch information
pirgeo committed Jul 29, 2024
1 parent b058429 commit fbc2531
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/sdk/instrumentation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
)

Expand Down Expand Up @@ -166,6 +167,21 @@ func otlpHTTPMetricExporter(ctx context.Context, otlpConfig *OTLPMetric) (sdkmet
if len(otlpConfig.Headers) > 0 {
opts = append(opts, otlpmetrichttp.WithHeaders(otlpConfig.Headers))
}
if otlpConfig.TemporalityPreference != nil {
switch *otlpConfig.TemporalityPreference {
case "cumulative":
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(func(ik sdkmetric.InstrumentKind) metricdata.Temporality { return metricdata.CumulativeTemporality }))

case "delta":
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(func(ik sdkmetric.InstrumentKind) metricdata.Temporality { return metricdata.DeltaTemporality }))

// TODO what about 'lowmemory' (stateless) temporality?

default:
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(sdkmetric.DefaultTemporalitySelector))
}

}

return otlpmetrichttp.New(ctx, opts...)
}
Expand Down

0 comments on commit fbc2531

Please sign in to comment.