use of io.opentelemetry.sdk.metrics.data.AggregationTemporality in project opentelemetry-java by open-telemetry.
the class DefaultSynchronousMetricStorage method collectAndReset.
@Override
public MetricData collectAndReset(CollectionInfo collectionInfo, Resource resource, InstrumentationLibraryInfo instrumentationLibraryInfo, long startEpochNanos, long epochNanos, boolean suppressSynchronousCollection) {
AggregationTemporality temporality = TemporalityUtils.resolveTemporality(collectionInfo.getPreferredAggregation());
Map<Attributes, T> result = deltaMetricStorage.collectFor(collectionInfo.getCollector(), collectionInfo.getAllCollectors(), suppressSynchronousCollection);
return temporalMetricStorage.buildMetricFor(collectionInfo.getCollector(), resource, instrumentationLibraryInfo, getMetricDescriptor(), temporality, result, startEpochNanos, epochNanos);
}
use of io.opentelemetry.sdk.metrics.data.AggregationTemporality in project opentelemetry-java by open-telemetry.
the class DoubleSumAggregatorTest method mergeAndDiff.
@Test
void mergeAndDiff() {
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));
for (InstrumentType instrumentType : InstrumentType.values()) {
for (AggregationTemporality temporality : AggregationTemporality.values()) {
DoubleSumAggregator aggregator = new DoubleSumAggregator(InstrumentDescriptor.create("name", "description", "unit", instrumentType, InstrumentValueType.LONG), ExemplarReservoir::noSamples);
DoubleAccumulation merged = aggregator.merge(DoubleAccumulation.create(1.0d, previousExemplars), DoubleAccumulation.create(2.0d, exemplars));
assertThat(merged.getValue()).withFailMessage("Invalid merge result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(3.0d);
assertThat(merged.getExemplars()).containsExactly(exemplar);
DoubleAccumulation diffed = aggregator.diff(DoubleAccumulation.create(1d), DoubleAccumulation.create(2d, exemplars));
assertThat(diffed.getValue()).withFailMessage("Invalid diff result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(1d);
assertThat(diffed.getExemplars()).containsExactly(exemplar);
}
}
}
use of io.opentelemetry.sdk.metrics.data.AggregationTemporality in project opentelemetry-java by open-telemetry.
the class TemporalMetricStorageTest method asynchronousDelta_diffsLastTimestamp.
@Test
void asynchronousDelta_diffsLastTimestamp() {
AggregationTemporality temporality = AggregationTemporality.DELTA;
TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(ASYNC_SUM, /* isSynchronous= */
false);
// Send in new measurement at time 10 for collector 1
assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 10)).hasDoubleSum().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(10).hasValue(3));
// Send in new measurement at time 30 for collector 1
assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 30)).hasDoubleSum().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(10).hasEpochNanos(30).hasValue(0));
// Send in new measurement at time 40 for collector 2
assertThat(storage.buildMetricFor(collector2, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(4), 0, 60)).hasDoubleSum().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(60).hasValue(4));
// Send in new measurement at time 35 for collector 1
assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(2), 0, 35)).hasDoubleSum().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(30).hasEpochNanos(35).hasValue(-1));
}
use of io.opentelemetry.sdk.metrics.data.AggregationTemporality in project opentelemetry-java by open-telemetry.
the class OtlpConfigUtil method configureOtlpAggregationTemporality.
static void configureOtlpAggregationTemporality(ConfigProperties config, Consumer<AggregationTemporality> setAggregationTemporality) {
String temporalityStr = config.getString("otel.exporter.otlp.metrics.temporality");
if (temporalityStr == null) {
return;
}
AggregationTemporality temporality;
try {
temporality = AggregationTemporality.valueOf(temporalityStr.toUpperCase());
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Unrecognized aggregation temporality: " + temporalityStr, e);
}
setAggregationTemporality.accept(temporality);
}
use of io.opentelemetry.sdk.metrics.data.AggregationTemporality in project opentelemetry-java by open-telemetry.
the class AsynchronousMetricStorage method collectAndReset.
@Override
public MetricData collectAndReset(CollectionInfo collectionInfo, Resource resource, InstrumentationLibraryInfo instrumentationLibraryInfo, long startEpochNanos, long epochNanos, boolean suppressSynchronousCollection) {
AggregationTemporality temporality = TemporalityUtils.resolveTemporality(collectionInfo.getPreferredAggregation());
collectLock.lock();
try {
try {
boolean empty = true;
for (Consumer<O> callback : callbacks) {
empty = false;
callback.accept(measurement);
}
if (empty) {
return EmptyMetricData.getInstance();
}
} catch (Throwable e) {
propagateIfFatal(e);
throttlingLogger.log(Level.WARNING, "An exception occurred invoking callback for instrument " + getMetricDescriptor().getName() + ".", e);
return EmptyMetricData.getInstance();
}
return storage.buildMetricFor(collectionInfo.getCollector(), resource, instrumentationLibraryInfo, getMetricDescriptor(), temporality, accumulator.collectAndReset(), startEpochNanos, epochNanos);
} finally {
collectLock.unlock();
}
}
Aggregations