Search in sources :

Example 21 with LongCounter

use of io.opentelemetry.api.metrics.LongCounter in project opentelemetry-java by open-telemetry.

the class SdkMeterRegistryTest method metricProducer_GetAllMetrics.

@Test
void metricProducer_GetAllMetrics() {
    Meter sdkMeter1 = meterProvider.get("io.opentelemetry.sdk.metrics.MeterSdkRegistryTest_1");
    LongCounter longCounter1 = sdkMeter1.counterBuilder("testLongCounter").build();
    longCounter1.add(10, Attributes.empty());
    Meter sdkMeter2 = meterProvider.get("io.opentelemetry.sdk.metrics.MeterSdkRegistryTest_2");
    LongCounter longCounter2 = sdkMeter2.counterBuilder("testLongCounter").build();
    longCounter2.add(10, Attributes.empty());
    assertThat(sdkMeterReader.collectAllMetrics()).allSatisfy(metric -> assertThat(metric).hasName("testLongCounter").hasLongSum().isCumulative().isMonotonic().points().satisfiesExactlyInAnyOrder(point -> assertThat(point).hasValue(10).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()))).extracting(MetricData::getInstrumentationLibraryInfo).containsExactlyInAnyOrder(toInstrumentationLibraryInfo(((SdkMeter) sdkMeter1).getInstrumentationScopeInfo()), toInstrumentationLibraryInfo(((SdkMeter) sdkMeter2).getInstrumentationScopeInfo()));
}
Also used : LongCounter(io.opentelemetry.api.metrics.LongCounter) Clock(io.opentelemetry.sdk.common.Clock) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) InstrumentationScopeUtil.toInstrumentationLibraryInfo(io.opentelemetry.sdk.internal.InstrumentationScopeUtil.toInstrumentationLibraryInfo) Mockito.mock(org.mockito.Mockito.mock) Meter(io.opentelemetry.api.metrics.Meter) LongCounter(io.opentelemetry.api.metrics.LongCounter) Test(org.junit.jupiter.api.Test)

Aggregations

LongCounter (io.opentelemetry.api.metrics.LongCounter)21 Test (org.junit.jupiter.api.Test)19 Meter (io.opentelemetry.api.metrics.Meter)16 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)13 Attributes (io.opentelemetry.api.common.Attributes)12 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)12 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)11 Resource (io.opentelemetry.sdk.resources.Resource)11 TestClock (io.opentelemetry.sdk.testing.time.TestClock)11 Duration (java.time.Duration)10 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)9 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)9 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)9 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)9 LongUpDownCounter (io.opentelemetry.api.metrics.LongUpDownCounter)9 AttributeKey (io.opentelemetry.api.common.AttributeKey)7 MetricData (io.opentelemetry.sdk.metrics.data.MetricData)7 BoundLongCounter (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter)7 Baggage (io.opentelemetry.api.baggage.Baggage)6 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)6