Search in sources :

Example 1 with ResourceMetricsMarshaler

use of io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler in project opentelemetry-java by open-telemetry.

the class OtlpJsonLoggingMetricExporter method export.

@Override
public CompletableResultCode export(Collection<MetricData> metrics) {
    ResourceMetricsMarshaler[] allResourceMetrics = ResourceMetricsMarshaler.create(metrics);
    for (ResourceMetricsMarshaler resourceMetrics : allResourceMetrics) {
        SegmentedStringWriter sw = new SegmentedStringWriter(JSON_FACTORY._getBufferRecycler());
        try (JsonGenerator gen = JsonUtil.create(sw)) {
            resourceMetrics.writeJsonTo(gen);
        } catch (IOException e) {
            // Shouldn't happen in practice, just skip it.
            continue;
        }
        logger.log(Level.INFO, sw.getAndClear());
    }
    return CompletableResultCode.ofSuccess();
}
Also used : ResourceMetricsMarshaler(io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) SegmentedStringWriter(com.fasterxml.jackson.core.io.SegmentedStringWriter)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 SegmentedStringWriter (com.fasterxml.jackson.core.io.SegmentedStringWriter)1 ResourceMetricsMarshaler (io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsMarshaler)1 IOException (java.io.IOException)1