1616import io .opentelemetry .sdk .metrics .SdkMeterProviderBuilder ;
1717import io .opentelemetry .sdk .metrics .export .PeriodicMetricReader ;
1818import io .opentelemetry .sdk .resources .Resource ;
19+ import org .HdrHistogram .AtomicHistogram ;
1920import org .HdrHistogram .Histogram ;
2021
2122/**
@@ -112,7 +113,7 @@ private Metrics(
112113 this .pendingOperations = pendingOperations ;
113114 }
114115
115- /**
116+ /*
116117 * Builds a {@code Metrics} instance configured to push OTLP metrics every
117118 * second to the endpoint from {@code config.otlpEndpoint()}. If the
118119 * endpoint is empty, all metrics are still observable in-process but never
@@ -232,7 +233,7 @@ private static String metricsEndpoint(String otlpEndpoint) {
232233 return trimmed + "/v1/metrics" ;
233234 }
234235
235- /**
236+ /*
236237 * Records a started operation and returns a span used to record the
237238 * outcome.
238239 */
@@ -286,9 +287,7 @@ private void recordOutcome(
286287 if (status == OperationStatus .SUCCESS ) {
287288 Histogram histogram = histograms .computeIfAbsent (type , k -> newHistogram ());
288289 long clamped = Math .max (HDR_MIN_MICROS , Math .min (HDR_MAX_MICROS , latencyMicros ));
289- synchronized (histogram ) {
290- histogram .recordValue (clamped );
291- }
290+ histogram .recordValue (clamped );
292291 } else {
293292 errorsTotal .add (1 , Attributes .of (
294293 ATTR_REF , ref ,
@@ -319,15 +318,13 @@ private static void observeAndResetPercentiles(
319318 long p50Micros ;
320319 long p95Micros ;
321320 long p99Micros ;
322- synchronized (histogram ) {
323- if (histogram .getTotalCount () == 0 ) {
324- continue ;
325- }
326- p50Micros = histogram .getValueAtPercentile (50.0 );
327- p95Micros = histogram .getValueAtPercentile (95.0 );
328- p99Micros = histogram .getValueAtPercentile (99.0 );
329- histogram .reset ();
321+ if (histogram .getTotalCount () == 0 ) {
322+ continue ;
330323 }
324+ p50Micros = histogram .getValueAtPercentile (50.0 );
325+ p95Micros = histogram .getValueAtPercentile (95.0 );
326+ p99Micros = histogram .getValueAtPercentile (99.0 );
327+ histogram .reset ();
331328
332329 // Percentile gauges are always tagged with operation_status="success"
333330 // because we only record successful samples (see recordOutcome).
@@ -345,7 +342,7 @@ private static void observeAndResetPercentiles(
345342 }
346343
347344 private static Histogram newHistogram () {
348- return new Histogram (HDR_MIN_MICROS , HDR_MAX_MICROS , HDR_SIGNIFICANT_DIGITS );
345+ return new AtomicHistogram (HDR_MIN_MICROS , HDR_MAX_MICROS , HDR_SIGNIFICANT_DIGITS );
349346 }
350347
351348 /**
0 commit comments