File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
doc-snippets/prometheus-migration/src/main/java/otel Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1+ package otel ;
2+
3+ import io .opentelemetry .api .OpenTelemetry ;
4+ import io .opentelemetry .api .common .AttributeKey ;
5+ import io .opentelemetry .api .common .Attributes ;
6+ import io .opentelemetry .api .metrics .DoubleHistogram ;
7+ import io .opentelemetry .api .metrics .Meter ;
8+ import java .util .List ;
9+
10+ public class OtelHistogramAsSummary {
11+ private static final AttributeKey <String > DEVICE_TYPE = AttributeKey .stringKey ("device_type" );
12+ private static final Attributes THERMOSTAT = Attributes .of (DEVICE_TYPE , "thermostat" );
13+ private static final Attributes LOCK = Attributes .of (DEVICE_TYPE , "lock" );
14+
15+ public static void summaryReplacement (OpenTelemetry openTelemetry ) {
16+ Meter meter = openTelemetry .getMeter ("smart.home" );
17+ // No explicit bucket boundaries: captures count and sum, a good stand-in for most
18+ // Summary use cases. For quantile estimation, add boundaries that bracket your thresholds.
19+ DoubleHistogram deviceCommandDuration =
20+ meter
21+ .histogramBuilder ("device.command.duration" )
22+ .setDescription ("Time to receive acknowledgment from a smart home device" )
23+ .setUnit ("s" )
24+ .setExplicitBucketBoundariesAdvice (List .of ())
25+ .build ();
26+
27+ deviceCommandDuration .record (0.35 , THERMOSTAT );
28+ deviceCommandDuration .record (0.85 , LOCK );
29+ }
30+ }
Original file line number Diff line number Diff line change 33import io .opentelemetry .exporter .otlp .http .metrics .OtlpHttpMetricExporter ;
44import io .opentelemetry .sdk .metrics .Aggregation ;
55import io .opentelemetry .sdk .metrics .InstrumentType ;
6+ import io .opentelemetry .sdk .metrics .export .DefaultAggregationSelector ;
67
78public class OtelHistogramExponentialExporter {
89 static OtlpHttpMetricExporter createExporter () {
@@ -11,10 +12,8 @@ static OtlpHttpMetricExporter createExporter() {
1112 return OtlpHttpMetricExporter .builder ()
1213 .setEndpoint ("http://localhost:4318" )
1314 .setDefaultAggregationSelector (
14- type ->
15- type == InstrumentType .HISTOGRAM
16- ? Aggregation .base2ExponentialBucketHistogram ()
17- : Aggregation .defaultAggregation ())
15+ DefaultAggregationSelector .getDefault ()
16+ .with (InstrumentType .HISTOGRAM , Aggregation .base2ExponentialBucketHistogram ()))
1817 .build ();
1918 }
2019}
You can’t perform that action at this time.
0 commit comments