From f8d2b29fe96f3a8a8acdbe0fc55c83ee607d85f3 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 15 Jul 2022 14:07:40 -0700 Subject: [PATCH] Fix missing message data (#2399) --- .../agent/internal/legacysdk/BytecodeUtilImpl.java | 2 +- .../exporter/implementation/LogDataMapper.java | 6 +----- .../implementation/builders/MessageTelemetryBuilder.java | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/legacysdk/BytecodeUtilImpl.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/legacysdk/BytecodeUtilImpl.java index 05722ae070d..6270c796ab3 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/legacysdk/BytecodeUtilImpl.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/legacysdk/BytecodeUtilImpl.java @@ -257,7 +257,7 @@ public void trackTrace( Map properties, Map tags, @Nullable String instrumentationKey) { - if (Strings.isNullOrEmpty(message)) { + if (message == null) { return; } MessageTelemetryBuilder telemetryBuilder = diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/LogDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/LogDataMapper.java index 9dc6b4e7053..b33389020cf 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/LogDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/LogDataMapper.java @@ -83,11 +83,7 @@ private TelemetryItem createMessageTelemetryItem(LogData log) { setExtraAttributes(telemetryBuilder, attributes); telemetryBuilder.setSeverityLevel(toSeverityLevel(log.getSeverity())); - String body = log.getBody().asString(); - if (body.isEmpty()) { - body = "n/a"; // breeze doesn't accept empty log messages - } - telemetryBuilder.setMessage(body); + telemetryBuilder.setMessage(log.getBody().asString()); // set message-specific properties setLoggerProperties( diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/builders/MessageTelemetryBuilder.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/builders/MessageTelemetryBuilder.java index 5dc3cbe7c5b..96adaedf5be 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/builders/MessageTelemetryBuilder.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/builders/MessageTelemetryBuilder.java @@ -45,6 +45,10 @@ private MessageTelemetryBuilder(MessageData data) { } public void setMessage(String message) { + if (message.trim().isEmpty()) { + // breeze doesn't accept message that is empty after trimming + message = "n/a"; + } data.setMessage(truncateTelemetry(message, MAX_MESSAGE_LENGTH, "Message.message")); }