use of io.opentelemetry.api.metrics.LongHistogram in project opentelemetry-java by open-telemetry.
the class SdkLongHistogramTest method collectMetrics_WithEmptyAttributes.
@Test
void collectMetrics_WithEmptyAttributes() {
LongHistogram longRecorder = sdkMeter.histogramBuilder("testRecorder").ofLongs().setDescription("description").setUnit("By").build();
testClock.advance(Duration.ofNanos(SECOND_NANOS));
longRecorder.record(12, Attributes.empty());
longRecorder.record(12);
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testRecorder").hasDescription("description").hasUnit("By").hasDoubleHistogram().isCumulative().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasAttributes(Attributes.empty()).hasCount(2).hasSum(24).hasBucketBoundaries(5, 10, 25, 50, 75, 100, 250, 500, 750, 1_000, 2_500, 5_000, 7_500, 10_000).hasBucketCounts(0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
}
use of io.opentelemetry.api.metrics.LongHistogram in project opentelemetry-java by open-telemetry.
the class SdkLongHistogramTest method boundLongHistogramRecord_MonotonicityCheck.
@Test
@SuppressLogger(SdkLongHistogram.class)
void boundLongHistogramRecord_MonotonicityCheck() {
LongHistogram histogram = sdkMeter.histogramBuilder("testHistogram").ofLongs().build();
BoundLongHistogram bound = ((SdkLongHistogram) histogram).bind(Attributes.empty());
try {
bound.record(-9);
assertThat(sdkMeterReader.collectAllMetrics()).hasSize(0);
logs.assertContains("Histograms can only record non-negative values. Instrument testHistogram has recorded a negative value.");
} finally {
bound.unbind();
}
}
Aggregations