Skip to content

Commit bcf0b52

Browse files
committed
removing unnecessary lines
1 parent 45de24d commit bcf0b52

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcSpanDecorator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.grpc.Metadata.Key;
2222
import io.opentelemetry.api.common.AttributeKey;
2323
import io.opentelemetry.api.trace.Span;
24-
import io.opentelemetry.javaagent.instrumentation.hypertrace.com.google.protobuf.util.JsonFormat;
2524
import io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.GrpcSemanticAttributes;
2625
import java.util.LinkedHashMap;
2726
import java.util.Map;
@@ -35,16 +34,17 @@ public class GrpcSpanDecorator {
3534
private GrpcSpanDecorator() {}
3635

3736
private static final Logger log = LoggerFactory.getLogger(GrpcSpanDecorator.class);
38-
private static final JsonFormat.Printer PRINTER = JsonFormat.printer();
3937

4038
public static void addMessageAttribute(Object message, Span span, AttributeKey<String> key) {
4139
if (message instanceof Message) {
4240
Message mb = (Message) message;
4341
try {
4442
String jsonOutput = ProtobufMessageConverter.getMessage(mb);
45-
span.setAttribute(key, jsonOutput);
43+
if (jsonOutput != null && !jsonOutput.isEmpty()) {
44+
span.setAttribute(key, jsonOutput);
45+
}
4646
} catch (Exception e) {
47-
log.debug("Failed to decode message as JSON", e);
47+
log.debug("Failed to decode message as JSON: {}", e.getMessage(), e);
4848
}
4949
} else {
5050
log.debug("message is not an instance of com.google.protobuf.Message");

instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/ProtobufMessageConverter.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,21 @@ private static FileDescriptor processFileDescriptorWithDependencies(
165165
* the relocated JsonFormat
166166
*
167167
* @param message The incoming (unrelocated) protobuf message.
168+
* @return JSON string representation of the message
169+
* @throws Exception if conversion fails
168170
*/
169-
public static String getMessage(Message message) {
171+
public static String getMessage(Message message) throws Exception {
170172
if (message == null) {
171173
log.debug("Cannot convert null message to JSON");
172174
return "";
173175
}
174176

175-
try {
176-
// Convert the unrelocated message into a relocated DynamicMessage.
177-
DynamicMessage relocatedMessage = convertToRelocatedDynamicMessage(message);
177+
// Convert the unrelocated message into a relocated DynamicMessage.
178+
DynamicMessage relocatedMessage = convertToRelocatedDynamicMessage(message);
178179

179-
// Use the relocated JsonFormat to print the message as JSON.
180-
JsonFormat.Printer relocatedPrinter =
181-
JsonFormat.printer().includingDefaultValueFields().preservingProtoFieldNames();
182-
return relocatedPrinter.print(relocatedMessage);
183-
} catch (Exception e) {
184-
log.error("Failed to convert message to JSON: {}", e.getMessage(), e);
185-
if (log.isDebugEnabled()) {
186-
log.debug("Message type: {}", message.getClass().getName());
187-
log.debug("Message descriptor: {}", message.getDescriptorForType().getFullName());
188-
}
189-
}
190-
return "";
180+
// Use the relocated JsonFormat to print the message as JSON.
181+
JsonFormat.Printer relocatedPrinter =
182+
JsonFormat.printer().includingDefaultValueFields().preservingProtoFieldNames();
183+
return relocatedPrinter.print(relocatedMessage);
191184
}
192185
}

0 commit comments

Comments
 (0)