diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerAttributeExtractor.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerAttributeExtractor.java index 717ce86ceecc..002f34a2ca73 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerAttributeExtractor.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerAttributeExtractor.java @@ -61,9 +61,11 @@ protected String conversationId(MessageExt request) { return null; } + @Nullable @Override protected Long messagePayloadSize(MessageExt request) { - return (long) request.getBody().length; + byte[] body = request.getBody(); + return body == null ? null : (long) body.length; } @Nullable diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerAttributeExtractor.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerAttributeExtractor.java index 06ddc4fd4e31..f6c6b9069074 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerAttributeExtractor.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerAttributeExtractor.java @@ -10,6 +10,8 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; import org.apache.rocketmq.client.hook.SendMessageContext; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.common.message.Message; class RockerMqProducerAttributeExtractor extends MessagingAttributesExtractor { @@ -28,9 +30,11 @@ protected String destinationKind(SendMessageContext sendMessageContext) { return SemanticAttributes.MessagingDestinationKindValues.TOPIC; } + @Nullable @Override protected String destination(SendMessageContext sendMessageContext) { - return sendMessageContext.getMessage().getTopic(); + Message message = sendMessageContext.getMessage(); + return message == null ? null : message.getTopic(); } @Override @@ -77,6 +81,7 @@ protected Long messagePayloadCompressedSize(SendMessageContext sendMessageContex @Nullable @Override protected String messageId(SendMessageContext request, @Nullable Void unused) { - return request.getSendResult().getMsgId(); + SendResult sendResult = request.getSendResult(); + return sendResult == null ? null : sendResult.getMsgId(); } } diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java index 50c9c7e2cd7b..3578cebbbc3f 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java @@ -22,7 +22,9 @@ class RockerMqProducerExperimentalAttributeExtractor @Override public void onStart(AttributesBuilder attributes, SendMessageContext request) { - set(attributes, MESSAGING_ROCKETMQ_TAGS, request.getMessage().getTags()); + if (request.getMessage() != null) { + set(attributes, MESSAGING_ROCKETMQ_TAGS, request.getMessage().getTags()); + } set(attributes, MESSAGING_ROCKETMQ_BROKER_ADDRESS, request.getBrokerAddr()); } diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/TracingSendMessageHookImpl.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/TracingSendMessageHookImpl.java index ad34c45bf03a..9d027d7c3dac 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/TracingSendMessageHookImpl.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/TracingSendMessageHookImpl.java @@ -40,9 +40,10 @@ public void sendMessageAfter(SendMessageContext context) { if (context == null) { return; } - if (context.getMqTraceContext() instanceof Context) { + if (context.getMqTraceContext() instanceof Context + && (context.getSendResult() != null || context.getException() != null)) { Context otelContext = (Context) context.getMqTraceContext(); - instrumenter.end(otelContext, context, null, null); + instrumenter.end(otelContext, context, null, context.getException()); } } }