Search in sources :

Example 11 with LongHistogram

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)));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) Duration(java.time.Duration) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) Test(org.junit.jupiter.api.Test)

Example 12 with LongHistogram

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();
    }
}
Also used : BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Aggregations

LongHistogram (io.opentelemetry.api.metrics.LongHistogram)12 Test (org.junit.jupiter.api.Test)12 Meter (io.opentelemetry.api.metrics.Meter)9 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)8 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)8 Attributes (io.opentelemetry.api.common.Attributes)7 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)7 BoundLongHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram)7 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)7 Resource (io.opentelemetry.sdk.resources.Resource)6 TestClock (io.opentelemetry.sdk.testing.time.TestClock)6 Duration (java.time.Duration)6 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)6 LogCapturer (io.github.netmikey.logunit.api.LogCapturer)5 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)5 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)5 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)5 LongCounter (io.opentelemetry.api.metrics.LongCounter)5 LongUpDownCounter (io.opentelemetry.api.metrics.LongUpDownCounter)5 AttributeKey (io.opentelemetry.api.common.AttributeKey)3