Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Semantic conventions in RabbitMQ #3425

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public Context startGetSpan(
spanBuilder.setAttribute(
SemanticAttributes.MESSAGING_DESTINATION,
normalizeExchangeName(response.getEnvelope().getExchange()));
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
spanBuilder.setAttribute("rabbitmq.routing_key", response.getEnvelope().getRoutingKey());
}
spanBuilder.setAttribute(
SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY,
response.getEnvelope().getRoutingKey());
spanBuilder.setAttribute(
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES,
(long) response.getBody().length);
Expand Down Expand Up @@ -113,16 +113,12 @@ public Context startDeliverySpan(
public void onPublish(Span span, String exchange, String routingKey) {
String exchangeName = normalizeExchangeName(exchange);
span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION, exchangeName);
String routing =
routingKey == null || routingKey.isEmpty()
? "<all>"
: routingKey.startsWith("amq.gen-") ? "<generated>" : routingKey;
span.updateName(exchangeName + " -> " + routing + " send");
span.updateName(exchangeName + " send");
if (routingKey != null && !routingKey.isEmpty()) {
span.setAttribute(SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY, routingKey);
}
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
span.setAttribute("rabbitmq.command", "basic.publish");
if (routingKey != null && !routingKey.isEmpty()) {
span.setAttribute("rabbitmq.routing_key", routingKey);
}
}
}

Expand Down Expand Up @@ -164,11 +160,9 @@ public void onDeliver(Span span, Envelope envelope) {
if (envelope != null) {
String exchange = envelope.getExchange();
span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION, normalizeExchangeName(exchange));
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
String routingKey = envelope.getRoutingKey();
if (routingKey != null && !routingKey.isEmpty()) {
span.setAttribute("rabbitmq.routing_key", routingKey);
}
String routingKey = envelope.getRoutingKey();
if (routingKey != null && !routingKey.isEmpty()) {
span.setAttribute(SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY, routingKey);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
rabbitSpan(it, 1, null, null, null, "exchange.declare", span(0))
rabbitSpan(it, 2, null, null, null, "queue.declare", span(0))
rabbitSpan(it, 3, null, null, null, "queue.bind", span(0))
rabbitSpan(it, 4, exchangeName, routingKey, "send", "$exchangeName -> $routingKey", span(0))
rabbitSpan(it, 4, exchangeName, routingKey, "send", "$exchangeName", span(0))
rabbitSpan(it, 5, exchangeName, routingKey, "receive", "<generated>", span(0))
}
}
Expand All @@ -100,7 +100,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
rabbitSpan(it, 0, null, null, null, "queue.declare")
}
trace(1, 1) {
rabbitSpan(it, 0, "<default>", null, "send", "<default> -> <generated>")
rabbitSpan(it, 0, "<default>", null, "send", "<default>")
}
trace(2, 1) {
rabbitSpan(it, 0, "<default>", null, "receive", "<generated>", null)
Expand Down Expand Up @@ -154,7 +154,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
}
(1..messageCount).each {
trace(3 + it, 2) {
rabbitSpan(it, 0, exchangeName, null, "send", "$exchangeName -> <all>")
rabbitSpan(it, 0, exchangeName, null, "send", "$exchangeName")
rabbitSpan(it, 1, exchangeName, null, "process", resource, span(0), null, null, null, setTimestamp)
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
rabbitSpan(it, null, null, null, "basic.consume")
}
trace(4, 2) {
rabbitSpan(it, 0, exchangeName, null, "send", "$exchangeName -> <all>")
rabbitSpan(it, 0, exchangeName, null, "send", "$exchangeName")
rabbitSpan(it, 1, exchangeName, null, "process", "<generated>", span(0), null, error, error.message)
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
rabbitSpan(it, null, null, null, "queue.declare")
}
trace(1, 1) {
rabbitSpan(it, 0, "<default>", "some-routing-queue", "send", "<default> -> some-routing-queue")
rabbitSpan(it, 0, "<default>", "some-routing-queue", "send", "<default>")
}
trace(2, 1) {
rabbitSpan(it, 0, "<default>", "some-routing-queue", "receive", queue.name, null)
Expand Down Expand Up @@ -347,8 +347,8 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "rabbitmq"
"${SemanticAttributes.MESSAGING_DESTINATION.key}" exchange
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
//TODO add to SemanticAttributes
"rabbitmq.routing_key" { it == null || it == routingKey || it.startsWith("amq.gen-") }

"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY}" { it == null || it == routingKey || it.startsWith("amq.gen-") }
if (operation != null && operation != "send") {
"${SemanticAttributes.MESSAGING_OPERATION.key}" operation
}
Expand All @@ -359,7 +359,7 @@ class RabbitMqTest extends AgentInstrumentationSpecification implements WithRabb
switch (trace.span(index).attributes.get(AttributeKey.stringKey("rabbitmq.command"))) {
case "basic.publish":
"rabbitmq.command" "basic.publish"
"rabbitmq.routing_key" {
"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY}" {
it == null || it == "some-routing-key" || it == "some-routing-queue" || it.startsWith("amq.gen-")
}
"rabbitmq.delivery_mode" { it == null || it == 2 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
}
span(3) {
// span created by rabbitmq instrumentation
name "testTopic -> testTopic send"
name "testTopic send"
childOf span(1)
kind PRODUCER
attributes {
Expand All @@ -67,6 +67,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
"${SemanticAttributes.MESSAGING_DESTINATION.key}" "testTopic"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long
"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY.key}" String
}
}
// spring-cloud-stream-binder-rabbit listener puts all messages into a BlockingQueue immediately after receiving
Expand All @@ -82,6 +83,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
"${SemanticAttributes.MESSAGING_OPERATION.key}" "process"
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long
"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY.key}" String
}
}
// spring-integration will detect that spring-rabbit has already created a consumer span and back off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification {
}
span(1) {
// created by rabbitmq instrumentation
name "<default> -> testQueue send"
name "<default> send"
kind PRODUCER
childOf span(0)
attributes {
Expand All @@ -89,6 +89,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.MESSAGING_DESTINATION.key}" "<default>"
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long
"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY.key}" String
}
}
// spring-cloud-stream-binder-rabbit listener puts all messages into a BlockingQueue immediately after receiving
Expand All @@ -104,6 +105,7 @@ class ContextPropagationTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
"${SemanticAttributes.MESSAGING_OPERATION.key}" "process"
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long
"${SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY.key}" String
}
}
span(3) {
Expand Down