Search in sources :

Example 1 with MetricData

use of io.opentelemetry.sdk.metrics.data.MetricData in project opentelemetry-java by open-telemetry.

the class MeterSharedState method collectAll.

/**
 * Collects all accumulated metric stream points.
 */
public List<MetricData> collectAll(CollectionInfo collectionInfo, MeterProviderSharedState meterProviderSharedState, long epochNanos, boolean suppressSynchronousCollection) {
    Collection<MetricStorage> metrics = getMetricStorageRegistry().getMetrics();
    List<MetricData> result = new ArrayList<>(metrics.size());
    for (MetricStorage metric : metrics) {
        MetricData current = metric.collectAndReset(collectionInfo, meterProviderSharedState.getResource(), getInstrumentationLibraryInfo(), meterProviderSharedState.getStartEpochNanos(), epochNanos, suppressSynchronousCollection);
        // Aggregation#drop()
        if (!current.isEmpty()) {
            result.add(current);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MetricData(io.opentelemetry.sdk.metrics.data.MetricData)

Example 2 with MetricData

use of io.opentelemetry.sdk.metrics.data.MetricData in project opentelemetry-java by open-telemetry.

the class MetricAdapterTest method toMetricFamilySamples.

@Test
void toMetricFamilySamples() {
    MetricData metricData = MONOTONIC_CUMULATIVE_DOUBLE_SUM;
    assertThat(MetricAdapter.toMetricFamilySamples(metricData)).isEqualTo(new MetricFamilySamples("instrument_name", Collector.Type.COUNTER, metricData.getDescription(), ImmutableList.of(new Sample("instrument_name", ImmutableList.of("kp"), ImmutableList.of("vp"), 5, null, 1633950672000L))));
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Test(org.junit.jupiter.api.Test)

Example 3 with MetricData

use of io.opentelemetry.sdk.metrics.data.MetricData in project opentelemetry-java by open-telemetry.

the class BatchSpanProcessorMetrics method getMetric.

private long getMetric(boolean dropped) {
    String labelValue = String.valueOf(dropped);
    OptionalLong value = allMetrics.stream().filter(metricData -> metricData.getName().equals("processedSpans")).filter(metricData -> !metricData.isEmpty()).map(metricData -> metricData.getLongSumData().getPoints()).flatMap(Collection::stream).filter(point -> labelValue.equals(point.getAttributes().get(stringKey("dropped")))).mapToLong(LongPointData::getValue).findFirst();
    return value.isPresent() ? value.getAsLong() : 0;
}
Also used : LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) OptionalLong(java.util.OptionalLong) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) Collection(java.util.Collection) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) OptionalLong(java.util.OptionalLong)

Example 4 with MetricData

use of io.opentelemetry.sdk.metrics.data.MetricData in project opentelemetry-java by open-telemetry.

the class OpenTelemetryMetricsExporter method export.

@Override
public void export(Collection<Metric> metrics) {
    List<MetricData> metricData = new ArrayList<>();
    Set<MetricDescriptor.Type> unsupportedTypes = new HashSet<>();
    for (Metric metric : metrics) {
        metricData.add(MetricAdapter.convert(resource, metric));
    }
    if (!unsupportedTypes.isEmpty()) {
        LOGGER.warning(Joiner.on(",").join(unsupportedTypes) + " not supported by OpenCensus to OpenTelemetry migrator.");
    }
    if (!metricData.isEmpty()) {
        otelExporter.export(metricData);
    }
}
Also used : ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) HashSet(java.util.HashSet)

Example 5 with MetricData

use of io.opentelemetry.sdk.metrics.data.MetricData in project opentelemetry-java by open-telemetry.

the class DoubleSumAggregatorTest method toMetricData.

@Test
@SuppressWarnings("unchecked")
void toMetricData() {
    AggregatorHandle<DoubleAccumulation> aggregatorHandle = aggregator.createHandle();
    aggregatorHandle.recordDouble(10);
    MetricData metricData = aggregator.toMetricData(resource, library, metricDescriptor, Collections.singletonMap(Attributes.empty(), aggregatorHandle.accumulateThenReset(Attributes.empty())), AggregationTemporality.CUMULATIVE, 0, 10, 100);
    assertThat(metricData).hasName("name").hasDescription("description").hasUnit("unit").hasDoubleSum().isCumulative().isMonotonic().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(100).hasAttributes(Attributes.empty()).hasValue(10));
}
Also used : MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Test(org.junit.jupiter.api.Test)

Aggregations

MetricData (io.opentelemetry.sdk.metrics.data.MetricData)24 Test (org.junit.jupiter.api.Test)16 Attributes (io.opentelemetry.api.common.Attributes)9 LongPointData (io.opentelemetry.sdk.metrics.data.LongPointData)7 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)5 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)5 Resource (io.opentelemetry.sdk.resources.Resource)5 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)5 TimeUnit (java.util.concurrent.TimeUnit)5 LongCounter (io.opentelemetry.api.metrics.LongCounter)4 Meter (io.opentelemetry.api.metrics.Meter)4 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)4 TestClock (io.opentelemetry.sdk.testing.time.TestClock)4 Duration (java.time.Duration)4 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 Baggage (io.opentelemetry.api.baggage.Baggage)3 AttributeKey (io.opentelemetry.api.common.AttributeKey)3 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)3 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)3