Search in sources :

Example 11 with DoubleCounter

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

the class MeterTest method doubleCounter.

@Test
void doubleCounter() {
    DoubleCounter instrument = meter.counterBuilder("test").ofDoubles().setDescription("d").setUnit("u").build();
    instrument.add(5.5, Attributes.of(AttributeKey.stringKey("q"), "r"));
    instrument.add(6.6, Attributes.of(AttributeKey.stringKey("q"), "r"));
    testing.waitAndAssertMetrics(instrumentationName, "test", metrics -> metrics.anySatisfy(metric -> assertThat(metric).hasDescription("d").hasUnit("u").hasInstrumentationLibrary(InstrumentationLibraryInfo.create(instrumentationName, "1.2.3")).hasDoubleSum().isMonotonic().points().satisfiesExactly(point -> assertThat(point).hasValue(12.1).attributes().containsOnly(attributeEntry("q", "r")))));
}
Also used : OpenTelemetryAssertions.attributeEntry(io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry) LongCounter(io.opentelemetry.api.metrics.LongCounter) AgentInstrumentationExtension(io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension) BeforeEach(org.junit.jupiter.api.BeforeEach) DoubleUpDownCounter(io.opentelemetry.api.metrics.DoubleUpDownCounter) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) Attributes(io.opentelemetry.api.common.Attributes) TestInfo(org.junit.jupiter.api.TestInfo) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) Test(org.junit.jupiter.api.Test) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) DoubleCounter(io.opentelemetry.api.metrics.DoubleCounter) AttributeKey(io.opentelemetry.api.common.AttributeKey) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) Assertions(org.assertj.core.api.Assertions) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) LongUpDownCounter(io.opentelemetry.api.metrics.LongUpDownCounter) DoubleCounter(io.opentelemetry.api.metrics.DoubleCounter) Test(org.junit.jupiter.api.Test)

Aggregations

DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)11 Test (org.junit.jupiter.api.Test)11 Meter (io.opentelemetry.api.metrics.Meter)8 Attributes (io.opentelemetry.api.common.Attributes)7 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)7 BoundDoubleCounter (io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleCounter)7 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)7 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)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 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)4 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)4 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)4 LongCounter (io.opentelemetry.api.metrics.LongCounter)4 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)4 LongUpDownCounter (io.opentelemetry.api.metrics.LongUpDownCounter)4 OperationUpdater (io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater)4