Skip to content

Commit 391dce2

Browse files
authored
Restore missing diagnostic logging (#42451)
1 parent 53268ef commit 391dce2

File tree

1 file changed

+20
-0
lines changed
  • sdk/monitor/azure-monitor-opentelemetry-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/pipeline

1 file changed

+20
-0
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/pipeline/TelemetryItemExporter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

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

1820
import java.io.IOException;
21+
import java.io.StringWriter;
1922
import java.nio.ByteBuffer;
2023
import java.util.ArrayList;
2124
import java.util.Collections;
@@ -37,6 +40,8 @@ public class TelemetryItemExporter {
3740

3841
private static final String _OTELRESOURCE_ = "_OTELRESOURCE_";
3942

43+
private static final ClientLogger logger = new ClientLogger(TelemetryItemExporter.class);
44+
4045
private static final OperationLogger operationLogger = new OperationLogger(TelemetryItemExporter.class,
4146
"Put export into the background (don't wait for it to return)");
4247

@@ -125,6 +130,21 @@ CompletableResultCode internalSendByBatch(TelemetryItemBatchKey telemetryItemBat
125130
// serialize an array of TelemetryItems to an array of byte buffers
126131
private static List<ByteBuffer> serialize(List<TelemetryItem> telemetryItems) {
127132
try {
133+
if (logger.canLogAtLevel(LogLevel.VERBOSE)) {
134+
try (StringWriter debug = new StringWriter()) {
135+
for (int i = 0; i < telemetryItems.size(); i++) {
136+
JsonWriter jsonWriter = JsonProviders.createWriter(debug);
137+
telemetryItems.get(i).toJson(jsonWriter);
138+
jsonWriter.flush();
139+
140+
if (i < telemetryItems.size() - 1) {
141+
debug.write('\n');
142+
}
143+
}
144+
logger.verbose("sending telemetry to ingestion service:{}{}", System.lineSeparator(), debug);
145+
}
146+
}
147+
128148
ByteBufferOutputStream out = writeTelemetryItemsAsByteBufferOutputStream(telemetryItems);
129149
out.close(); // closing ByteBufferOutputStream is a no-op, but this line makes LGTM happy
130150
List<ByteBuffer> byteBuffers = out.getByteBuffers();

0 commit comments

Comments
 (0)