Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.azure.monitor.opentelemetry.exporter.implementation.pipeline;

import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
import com.azure.json.JsonProviders;
import com.azure.json.JsonWriter;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder;
Expand All @@ -16,6 +18,7 @@
import io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes;

import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -37,6 +40,8 @@ public class TelemetryItemExporter {

private static final String _OTELRESOURCE_ = "_OTELRESOURCE_";

private static final ClientLogger logger = new ClientLogger(TelemetryItemExporter.class);

private static final OperationLogger operationLogger = new OperationLogger(TelemetryItemExporter.class,
"Put export into the background (don't wait for it to return)");

Expand Down Expand Up @@ -125,6 +130,21 @@ CompletableResultCode internalSendByBatch(TelemetryItemBatchKey telemetryItemBat
// serialize an array of TelemetryItems to an array of byte buffers
private static List<ByteBuffer> serialize(List<TelemetryItem> telemetryItems) {
try {
if (logger.canLogAtLevel(LogLevel.VERBOSE)) {
try (StringWriter debug = new StringWriter()) {
for (int i = 0; i < telemetryItems.size(); i++) {
JsonWriter jsonWriter = JsonProviders.createWriter(debug);
telemetryItems.get(i).toJson(jsonWriter);
jsonWriter.flush();

if (i < telemetryItems.size() - 1) {
debug.write('\n');
}
}
logger.verbose("sending telemetry to ingestion service:{}{}", System.lineSeparator(), debug);
}
}

ByteBufferOutputStream out = writeTelemetryItemsAsByteBufferOutputStream(telemetryItems);
out.close(); // closing ByteBufferOutputStream is a no-op, but this line makes LGTM happy
List<ByteBuffer> byteBuffers = out.getByteBuffers();
Expand Down