From a80d13e96c98b3fbdb749349f1208c82ed7022fc Mon Sep 17 00:00:00 2001 From: Piotr WOLSKI Date: Wed, 16 Oct 2024 14:11:43 -0600 Subject: [PATCH] remove dependency on abstract message in schema extractor (#7260) --- .../protobuf_java/AbstractMessageInstrumentation.java | 6 +++++- .../protobuf_java/AbstractParserInstrumentation.java | 4 +++- .../instrumentation/protobuf_java/SchemaExtractor.java | 8 -------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractMessageInstrumentation.java b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractMessageInstrumentation.java index 8d6f6083dd6..0aee173f7c4 100644 --- a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractMessageInstrumentation.java +++ b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractMessageInstrumentation.java @@ -63,7 +63,11 @@ public static void onEnter(@Advice.This AbstractMessage message) { if (callDepth > 0) { return; } - SchemaExtractor.attachSchemaOnSpan(message, activeSpan(), SchemaExtractor.serialization); + if (message == null) { + return; + } + SchemaExtractor.attachSchemaOnSpan( + message.getDescriptorForType(), activeSpan(), SchemaExtractor.serialization); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) diff --git a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractParserInstrumentation.java b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractParserInstrumentation.java index d9e90df2a5f..d926af59379 100644 --- a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractParserInstrumentation.java +++ b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/AbstractParserInstrumentation.java @@ -80,7 +80,9 @@ public static void stopSpan( } if (message instanceof AbstractMessage) { SchemaExtractor.attachSchemaOnSpan( - (AbstractMessage) message, span, SchemaExtractor.deserialization); + ((AbstractMessage) message).getDescriptorForType(), + span, + SchemaExtractor.deserialization); } } } diff --git a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/SchemaExtractor.java b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/SchemaExtractor.java index 12bf3b100bc..2ecef72a699 100644 --- a/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/SchemaExtractor.java +++ b/dd-java-agent/instrumentation/protobuf/src/main/java/datadog/trace/instrumentation/protobuf_java/SchemaExtractor.java @@ -1,6 +1,5 @@ package datadog.trace.instrumentation.protobuf_java; -import com.google.protobuf.AbstractMessage; import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; @@ -170,13 +169,6 @@ public void iterateOverSchema(SchemaBuilder builder) { extractSchema(descriptor, builder, 0); } - public static void attachSchemaOnSpan(AbstractMessage message, AgentSpan span, String operation) { - if (message == null) { - return; - } - attachSchemaOnSpan(message.getDescriptorForType(), span, operation); - } - public static void attachSchemaOnSpan( Descriptors.Descriptor descriptor, AgentSpan span, String operation) { if (descriptor == null || span == null) {