Skip to content

Commit

Permalink
Using constant in SemanticAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-ai committed Sep 21, 2022
1 parent 78be71a commit 123d662
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.SocketAddress;
import javax.annotation.Nullable;
import org.apache.rocketmq.common.message.MessageExt;
Expand All @@ -17,8 +18,6 @@ enum RocketMqConsumerExperimentalAttributeExtractor
implements AttributesExtractor<MessageExt, Void> {
INSTANCE;

private static final AttributeKey<String> MESSAGING_ROCKETMQ_MESSAGE_TAG =
AttributeKey.stringKey("messaging.rocketmq.message_tag");
private static final AttributeKey<Long> MESSAGING_ROCKETMQ_QUEUE_ID =
AttributeKey.longKey("messaging.rocketmq.queue_id");
private static final AttributeKey<Long> MESSAGING_ROCKETMQ_QUEUE_OFFSET =
Expand All @@ -30,7 +29,7 @@ enum RocketMqConsumerExperimentalAttributeExtractor
public void onStart(AttributesBuilder attributes, Context parentContext, MessageExt msg) {
String tags = msg.getTags();
if (tags != null) {
attributes.put(MESSAGING_ROCKETMQ_MESSAGE_TAG, tags);
attributes.put(SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG, tags);
}
attributes.put(MESSAGING_ROCKETMQ_QUEUE_ID, msg.getQueueId());
attributes.put(MESSAGING_ROCKETMQ_QUEUE_OFFSET, msg.getQueueOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable;
import org.apache.rocketmq.client.hook.SendMessageContext;

enum RocketMqProducerExperimentalAttributeExtractor
implements AttributesExtractor<SendMessageContext, Void> {
INSTANCE;

private static final AttributeKey<String> MESSAGING_ROCKETMQ_MESSAGE_TAG =
AttributeKey.stringKey("messaging.rocketmq.message_tag");
private static final AttributeKey<String> MESSAGING_ROCKETMQ_BROKER_ADDRESS =
AttributeKey.stringKey("messaging.rocketmq.broker_address");
private static final AttributeKey<String> MESSAGING_ROCKETMQ_SEND_RESULT =
Expand All @@ -29,7 +28,7 @@ public void onStart(
if (request.getMessage() != null) {
String tags = request.getMessage().getTags();
if (tags != null) {
attributes.put(MESSAGING_ROCKETMQ_MESSAGE_TAG, tags);
attributes.put(SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG, tags);
}
}
String brokerAddr = request.getBrokerAddr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_DESTINATION" sharedTopic
"$SemanticAttributes.MESSAGING_DESTINATION_KIND" "topic"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.send_result" "SEND_OK"
}
Expand All @@ -118,7 +118,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES" Long
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.queue_id" Long
"messaging.rocketmq.queue_offset" Long
Expand Down Expand Up @@ -158,7 +158,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_DESTINATION" sharedTopic
"$SemanticAttributes.MESSAGING_DESTINATION_KIND" "topic"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.send_result" "SEND_OK"
}
Expand All @@ -174,7 +174,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES" Long
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.queue_id" Long
"messaging.rocketmq.queue_offset" Long
Expand Down Expand Up @@ -261,7 +261,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES" Long
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.queue_id" Long
"messaging.rocketmq.queue_offset" Long
Expand All @@ -279,7 +279,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES" Long
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagB"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagB"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.queue_id" Long
"messaging.rocketmq.queue_offset" Long
Expand Down Expand Up @@ -323,7 +323,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_DESTINATION" sharedTopic
"$SemanticAttributes.MESSAGING_DESTINATION_KIND" "topic"
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.send_result" "SEND_OK"
"messaging.header.test_message_header" { it == ["test"] }
Expand All @@ -340,7 +340,7 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
"$SemanticAttributes.MESSAGING_OPERATION" "process"
"$SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES" Long
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
"messaging.rocketmq.message_tag" "TagA"
"$SemanticAttributes.MESSAGING_ROCKETMQ_MESSAGE_TAG" "TagA"
"messaging.rocketmq.broker_address" String
"messaging.rocketmq.queue_id" Long
"messaging.rocketmq.queue_offset" Long
Expand Down

0 comments on commit 123d662

Please sign in to comment.