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;
}
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))));
}
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;
}
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);
}
}
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));
}
Aggregations