use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class SdkObservableLongCounterTest method collectMetrics_DeltaSumAggregator.
@Test
void collectMetrics_DeltaSumAggregator() {
InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.createDelta();
SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.registerMetricReader(sdkMeterReader).registerView(InstrumentSelector.builder().setType(InstrumentType.OBSERVABLE_COUNTER).build(), View.builder().setAggregation(Aggregation.sum()).build()).build();
sdkMeterProvider.get(getClass().getName()).counterBuilder("testObserver").buildWithCallback(result -> result.record(12, Attributes.builder().put("k", "v").build()));
testClock.advance(Duration.ofNanos(SECOND_NANOS));
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testObserver").hasLongSum().isMonotonic().isDelta().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasValue(12).attributes().hasSize(1).containsEntry("k", "v")));
testClock.advance(Duration.ofNanos(SECOND_NANOS));
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testObserver").hasLongSum().isMonotonic().isDelta().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasValue(0).attributes().hasSize(1).containsEntry("k", "v")));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class FixedSizeExemplarReservoirTest method oneMeasurement_includesTraceAndSpanIds.
@Test
public void oneMeasurement_includesTraceAndSpanIds() {
Attributes all = Attributes.builder().put("one", 1).put("two", "two").put("three", true).build();
Context context = Context.root().with(Span.wrap(SpanContext.createFromRemoteParent(TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())));
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new FixedSizeExemplarReservoir(clock, 1, RandomSupplier.platformDefault());
reservoir.offerMeasurement(1L, all, context);
assertThat(reservoir.collectAndReset(Attributes.empty())).satisfiesExactly(exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasValue(1).hasFilteredAttributes(all).hasTraceId(TRACE_ID).hasSpanId(SPAN_ID));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class SdkObservableLongUpDownCounterTest method collectMetrics_DeltaSumAggregator.
@Test
void collectMetrics_DeltaSumAggregator() {
InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.createDelta();
SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.registerMetricReader(sdkMeterReader).registerView(InstrumentSelector.builder().setType(InstrumentType.OBSERVABLE_UP_DOWN_COUNTER).build(), View.builder().setAggregation(Aggregation.sum()).build()).build();
sdkMeterProvider.get(getClass().getName()).upDownCounterBuilder("testObserver").buildWithCallback(result -> result.record(12, Attributes.builder().put("k", "v").build()));
testClock.advance(Duration.ofNanos(SECOND_NANOS));
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testObserver").hasLongSum().isNotMonotonic().isDelta().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasValue(12).attributes().hasSize(1).containsEntry("k", "v")));
testClock.advance(Duration.ofNanos(SECOND_NANOS));
assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testObserver").hasLongSum().isNotMonotonic().isDelta().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasValue(0).attributes().hasSize(1).containsEntry("k", "v")));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class AggregatorHandleTest method testOfferMeasurementLongToExemplar.
@Test
void testOfferMeasurementLongToExemplar() {
TestAggregatorHandle testAggregator = new TestAggregatorHandle(reservoir);
Attributes attributes = Attributes.builder().put("test", "value").build();
Context context = Context.root();
testAggregator.recordLong(1L, attributes, context);
Mockito.verify(reservoir).offerMeasurement(1L, attributes, context);
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class DoubleLastValueAggregatorTest method mergeAccumulation.
@Test
void mergeAccumulation() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
DoubleAccumulation result = aggregator.merge(DoubleAccumulation.create(1, previousExemplars), DoubleAccumulation.create(2, exemplars));
// Assert that latest measurement is kept.
assertThat(result).isEqualTo(DoubleAccumulation.create(2, exemplars));
}
Aggregations