Search in sources :

Example 1 with AggregationTemporality

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);
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality)

Example 2 with AggregationTemporality

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);
        }
    }
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) InstrumentType(io.opentelemetry.sdk.metrics.common.InstrumentType) ExemplarReservoir(io.opentelemetry.sdk.metrics.exemplar.ExemplarReservoir) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) Test(org.junit.jupiter.api.Test)

Example 3 with AggregationTemporality

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));
}
Also used : DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) Test(org.junit.jupiter.api.Test)

Example 4 with AggregationTemporality

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);
}
Also used : ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality)

Example 5 with AggregationTemporality

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();
    }
}
Also used : AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality)

Aggregations

AggregationTemporality (io.opentelemetry.sdk.metrics.data.AggregationTemporality)9 Test (org.junit.jupiter.api.Test)6 DoubleAccumulation (io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation)4 Attributes (io.opentelemetry.api.common.Attributes)2 InstrumentType (io.opentelemetry.sdk.metrics.common.InstrumentType)2 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)2 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)2 ExemplarReservoir (io.opentelemetry.sdk.metrics.exemplar.ExemplarReservoir)2 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)1