Search in sources :

Example 1 with ResourceSpansMarshaler

use of io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler in project opentelemetry-java by open-telemetry.

the class OtlpJsonLoggingSpanExporter method export.

@Override
public CompletableResultCode export(Collection<SpanData> spans) {
    ResourceSpansMarshaler[] allResourceSpans = ResourceSpansMarshaler.create(spans);
    for (ResourceSpansMarshaler resourceSpans : allResourceSpans) {
        SegmentedStringWriter sw = new SegmentedStringWriter(JsonUtil.JSON_FACTORY._getBufferRecycler());
        try (JsonGenerator gen = JsonUtil.create(sw)) {
            resourceSpans.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 : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) ResourceSpansMarshaler(io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler) SegmentedStringWriter(com.fasterxml.jackson.core.io.SegmentedStringWriter)

Aggregations

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