Search in sources :

Example 1 with Marshaler

use of io.opentelemetry.exporter.internal.marshal.Marshaler in project opentelemetry-java by open-telemetry.

the class MetricMarshaler method create.

static Marshaler create(MetricData metric) {
    // TODO(anuraaga): Cache these as they should be effectively singleton.
    byte[] name = MarshalerUtil.toBytes(metric.getName());
    byte[] description = MarshalerUtil.toBytes(metric.getDescription());
    byte[] unit = MarshalerUtil.toBytes(metric.getUnit());
    Marshaler dataMarshaler = null;
    ProtoFieldInfo dataField = null;
    switch(metric.getType()) {
        case LONG_GAUGE:
            dataMarshaler = GaugeMarshaler.create(metric.getLongGaugeData());
            dataField = Metric.GAUGE;
            break;
        case DOUBLE_GAUGE:
            dataMarshaler = GaugeMarshaler.create(metric.getDoubleGaugeData());
            dataField = Metric.GAUGE;
            break;
        case LONG_SUM:
            dataMarshaler = SumMarshaler.create(metric.getLongSumData());
            dataField = Metric.SUM;
            break;
        case DOUBLE_SUM:
            dataMarshaler = SumMarshaler.create(metric.getDoubleSumData());
            dataField = Metric.SUM;
            break;
        case SUMMARY:
            dataMarshaler = SummaryMarshaler.create(metric.getSummaryData());
            dataField = Metric.SUMMARY;
            break;
        case HISTOGRAM:
            dataMarshaler = HistogramMarshaler.create(metric.getHistogramData());
            dataField = Metric.HISTOGRAM;
            break;
        case EXPONENTIAL_HISTOGRAM:
            dataMarshaler = ExponentialHistogramMarshaler.create(ExponentialHistogramData.fromMetricData(metric));
            dataField = Metric.EXPONENTIAL_HISTOGRAM;
    }
    if (dataMarshaler == null || dataField == null) {
        // Someone not using BOM to align versions as we require. Just skip the metric.
        return NoopMarshaler.INSTANCE;
    }
    return new MetricMarshaler(name, description, unit, dataMarshaler, dataField);
}
Also used : Marshaler(io.opentelemetry.exporter.internal.marshal.Marshaler) ProtoFieldInfo(io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo)

Aggregations

Marshaler (io.opentelemetry.exporter.internal.marshal.Marshaler)1 ProtoFieldInfo (io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo)1