From fbc25317f822e4f585c7b3bf6fcd6986adb0e7a0 Mon Sep 17 00:00:00 2001 From: Georg P Date: Mon, 29 Jul 2024 17:33:09 +0200 Subject: [PATCH] attempt to add temporality preference --- config/metric.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/metric.go b/config/metric.go index 6c6b34e9f59..a04717e9148 100644 --- a/config/metric.go +++ b/config/metric.go @@ -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" ) @@ -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...) }