Search in sources :

Example 1 with Sum

use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.

the class OtlpExporterIntegrationTest method testMetricExport.

private static void testMetricExport(MetricExporter metricExporter) {
    MetricReaderFactory reader = PeriodicMetricReader.builder(metricExporter).setInterval(Duration.ofSeconds(5)).newMetricReaderFactory();
    SdkMeterProvider meterProvider = SdkMeterProvider.builder().setResource(RESOURCE).registerMetricReader(reader).build();
    Meter meter = meterProvider.meterBuilder(OtlpExporterIntegrationTest.class.getName()).build();
    LongCounter longCounter = meter.counterBuilder("my-counter").build();
    longCounter.add(100, Attributes.builder().put("key", "value").build());
    try {
        await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> assertThat(grpcServer.metricRequests).hasSize(1));
    } finally {
        meterProvider.close();
    }
    ExportMetricsServiceRequest request = grpcServer.metricRequests.get(0);
    assertThat(request.getResourceMetricsCount()).isEqualTo(1);
    ResourceMetrics resourceMetrics = request.getResourceMetrics(0);
    assertThat(resourceMetrics.getResource().getAttributesList()).contains(KeyValue.newBuilder().setKey(ResourceAttributes.SERVICE_NAME.getKey()).setValue(AnyValue.newBuilder().setStringValue("integration test").build()).build());
    assertThat(resourceMetrics.getInstrumentationLibraryMetricsCount()).isEqualTo(1);
    InstrumentationLibraryMetrics ilMetrics = resourceMetrics.getInstrumentationLibraryMetrics(0);
    assertThat(ilMetrics.getInstrumentationLibrary().getName()).isEqualTo(OtlpExporterIntegrationTest.class.getName());
    assertThat(ilMetrics.getMetricsCount()).isEqualTo(1);
    Metric metric = ilMetrics.getMetrics(0);
    assertThat(metric.getName()).isEqualTo("my-counter");
    assertThat(metric.getDataCase()).isEqualTo(Metric.DataCase.SUM);
    Sum sum = metric.getSum();
    assertThat(sum.getAggregationTemporality()).isEqualTo(AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE);
    assertThat(sum.getDataPointsCount()).isEqualTo(1);
    NumberDataPoint dataPoint = sum.getDataPoints(0);
    assertThat(dataPoint.getAsInt()).isEqualTo(100);
    assertThat(dataPoint.getAttributesList()).isEqualTo(Collections.singletonList(KeyValue.newBuilder().setKey("key").setValue(AnyValue.newBuilder().setStringValue("value").build()).build()));
}
Also used : ResourceMetrics(io.opentelemetry.proto.metrics.v1.ResourceMetrics) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) Meter(io.opentelemetry.api.metrics.Meter) NumberDataPoint(io.opentelemetry.proto.metrics.v1.NumberDataPoint) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) Metric(io.opentelemetry.proto.metrics.v1.Metric) Sum(io.opentelemetry.proto.metrics.v1.Sum) InstrumentationLibraryMetrics(io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics) LongCounter(io.opentelemetry.api.metrics.LongCounter) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest)

Example 2 with Sum

use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.

the class ExponentialHistogramDataPointMarshaler method calculateSize.

private static int calculateSize(long startTimeUnixNano, long timeUnixNano, int scale, long count, double sum, long zeroCount, ExponentialHistogramBucketsMarshaler positiveBucketMarshaler, ExponentialHistogramBucketsMarshaler negativeBucketMarshaler, ExemplarMarshaler[] exemplarMarshalers, KeyValueMarshaler[] attributesMarshalers) {
    int size = 0;
    size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
    size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
    size += MarshalerUtil.sizeSInt32(ExponentialHistogramDataPoint.SCALE, scale);
    size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.COUNT, count);
    size += MarshalerUtil.sizeDouble(ExponentialHistogramDataPoint.SUM, sum);
    size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.ZERO_COUNT, zeroCount);
    size += MarshalerUtil.sizeMessage(ExponentialHistogramDataPoint.POSITIVE, positiveBucketMarshaler);
    size += MarshalerUtil.sizeMessage(ExponentialHistogramDataPoint.NEGATIVE, negativeBucketMarshaler);
    size += MarshalerUtil.sizeRepeatedMessage(ExponentialHistogramDataPoint.EXEMPLARS, exemplarMarshalers);
    size += MarshalerUtil.sizeRepeatedMessage(ExponentialHistogramDataPoint.ATTRIBUTES, attributesMarshalers);
    return size;
}
Also used : ExponentialHistogramDataPoint(io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogramDataPoint)

Example 3 with Sum

use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.

the class SummaryDataPointMarshaler method calculateSize.

private static int calculateSize(long startTimeUnixNano, long timeUnixNano, long count, double sum, ValueAtQuantileMarshaler[] quantileValues, KeyValueMarshaler[] attributes) {
    int size = 0;
    size += MarshalerUtil.sizeFixed64(SummaryDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
    size += MarshalerUtil.sizeFixed64(SummaryDataPoint.TIME_UNIX_NANO, timeUnixNano);
    size += MarshalerUtil.sizeFixed64(SummaryDataPoint.COUNT, count);
    size += MarshalerUtil.sizeDouble(SummaryDataPoint.SUM, sum);
    size += MarshalerUtil.sizeRepeatedMessage(SummaryDataPoint.QUANTILE_VALUES, quantileValues);
    size += MarshalerUtil.sizeRepeatedMessage(SummaryDataPoint.ATTRIBUTES, attributes);
    return size;
}
Also used : SummaryDataPoint(io.opentelemetry.proto.metrics.v1.internal.SummaryDataPoint)

Example 4 with Sum

use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.

the class HistogramDataPointMarshaler method calculateSize.

private static int calculateSize(long startTimeUnixNano, long timeUnixNano, long count, double sum, List<Long> bucketCounts, List<Double> explicitBounds, ExemplarMarshaler[] exemplars, KeyValueMarshaler[] attributes) {
    int size = 0;
    size += MarshalerUtil.sizeFixed64(HistogramDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
    size += MarshalerUtil.sizeFixed64(HistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
    size += MarshalerUtil.sizeFixed64(HistogramDataPoint.COUNT, count);
    size += MarshalerUtil.sizeDouble(HistogramDataPoint.SUM, sum);
    size += MarshalerUtil.sizeRepeatedFixed64(HistogramDataPoint.BUCKET_COUNTS, bucketCounts);
    size += MarshalerUtil.sizeRepeatedDouble(HistogramDataPoint.EXPLICIT_BOUNDS, explicitBounds);
    size += MarshalerUtil.sizeRepeatedMessage(HistogramDataPoint.EXEMPLARS, exemplars);
    size += MarshalerUtil.sizeRepeatedMessage(HistogramDataPoint.ATTRIBUTES, attributes);
    return size;
}
Also used : HistogramDataPoint(io.opentelemetry.proto.metrics.v1.internal.HistogramDataPoint)

Aggregations

LongCounter (io.opentelemetry.api.metrics.LongCounter)1 Meter (io.opentelemetry.api.metrics.Meter)1 ExportMetricsServiceRequest (io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest)1 InstrumentationLibraryMetrics (io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics)1 Metric (io.opentelemetry.proto.metrics.v1.Metric)1 NumberDataPoint (io.opentelemetry.proto.metrics.v1.NumberDataPoint)1 ResourceMetrics (io.opentelemetry.proto.metrics.v1.ResourceMetrics)1 Sum (io.opentelemetry.proto.metrics.v1.Sum)1 ExponentialHistogramDataPoint (io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogramDataPoint)1 HistogramDataPoint (io.opentelemetry.proto.metrics.v1.internal.HistogramDataPoint)1 SummaryDataPoint (io.opentelemetry.proto.metrics.v1.internal.SummaryDataPoint)1 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)1 MetricReaderFactory (io.opentelemetry.sdk.metrics.export.MetricReaderFactory)1