use of io.opentelemetry.api.metrics.ObservableLongCounter in project opentelemetry-java by open-telemetry.
the class SdkMeterProviderTest method removeAsyncInstrument.
@Test
void removeAsyncInstrument() {
InMemoryMetricReader reader = InMemoryMetricReader.create();
Meter meter = sdkMeterProviderBuilder.registerMetricReader(reader).build().get(getClass().getName());
ObservableLongCounter observableCounter1 = meter.counterBuilder("foo").buildWithCallback(measurement -> measurement.record(10, Attributes.builder().put("callback", "one").build()));
ObservableLongCounter observableCounter2 = meter.counterBuilder("foo").buildWithCallback(measurement -> measurement.record(10, Attributes.builder().put("callback", "two").build()));
assertThat(reader.collectAllMetrics()).hasSize(1).satisfiesExactly(metricData -> assertThat(metricData).hasLongSum().points().hasSize(2).satisfiesExactlyInAnyOrder(pointData -> assertThat(pointData).hasAttributes(Attributes.builder().put("callback", "one").build()), (Consumer<LongPointData>) longPointData -> assertThat(longPointData).hasAttributes(Attributes.builder().put("callback", "two").build())));
observableCounter1.close();
assertThat(reader.collectAllMetrics()).hasSize(1).satisfiesExactly(metricData -> assertThat(metricData).hasLongSum().points().hasSize(1).satisfiesExactlyInAnyOrder((Consumer<LongPointData>) longPointData -> assertThat(longPointData).hasAttributes(Attributes.builder().put("callback", "two").build())));
observableCounter2.close();
assertThat(reader.collectAllMetrics()).hasSize(0);
}
use of io.opentelemetry.api.metrics.ObservableLongCounter in project opentelemetry-java by open-telemetry.
the class SdkObservableLongCounterTest method removeCallback.
@Test
void removeCallback() {
InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.create();
ObservableLongCounter counter = sdkMeterProviderBuilder.registerMetricReader(sdkMeterReader).build().get(getClass().getName()).counterBuilder("testCounter").buildWithCallback(measurement -> measurement.record(10));
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasName("testCounter").hasLongSum().points().hasSize(1));
counter.close();
assertThat(sdkMeterReader.collectAllMetrics()).hasSize(0);
}
Aggregations