Configure duration metrics export as histograms to dogfood in preparation of SDK 1.5.0
MODIFY
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/OpenTelemetryInstaller.java
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/OpenTelemetryInstaller.java
@@ -13,8 +13,15 @@ import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.javaagent.instrumentation.api.OpenTelemetrySdkAccess;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration;
+import io.opentelemetry.sdk.autoconfigure.spi.SdkMeterProviderConfigurer;
import io.opentelemetry.sdk.common.CompletableResultCode;
+import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
+import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
+import io.opentelemetry.sdk.metrics.common.InstrumentType;
+import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.export.IntervalMetricReader;
+import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
+import io.opentelemetry.sdk.metrics.view.View;
import java.util.Arrays;
import java.util.Map;
import org.slf4j.Logger;
@@ -84,4 +91,27 @@ public class OpenTelemetryInstaller implements AgentListener {
}
});
}
+
+ // Configure histogram metrics similarly to how the SDK will default in 1.5.0 for early feedback.
+ @AutoService(SdkMeterProviderConfigurer.class)
+ public static final class OpenTelemetryMetricsConfigurer implements SdkMeterProviderConfigurer {
+
+ @Override
+ public void configure(SdkMeterProviderBuilder sdkMeterProviderBuilder) {
+ sdkMeterProviderBuilder.registerView(
+ InstrumentSelector.builder()
+ .setInstrumentNameRegex(".*duration")
+ .setInstrumentType(InstrumentType.VALUE_RECORDER)
+ .build(),
+ // Histogram buckets the same as the metrics prototype/prometheus.
+ View.builder()
+ .setAggregatorFactory(
+ AggregatorFactory.histogram(
+ Arrays.asList(
+ 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 750d, 1_000d, 2_500d, 5_000d,
+ 7_500d, 10_000d),
+ AggregationTemporality.CUMULATIVE))
+ .build());
+ }
+ }
}

Configure duration metrics export as histograms to dogfood in preparation of SDK 1.5.0 (#3597)