-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental option to suppress messaging receive spans (#4187)
* Experimental option to suppress messaging receive spans * Kafka streams too * Better conditionals * Remove oops * Extract base class for kafka streams tests * Spotless
- Loading branch information
Showing
10 changed files
with
518 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
...s/kafka-clients-0.11/javaagent/src/test/groovy/KafkaClientSuppressReceiveSpansTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes | ||
import org.apache.kafka.clients.producer.ProducerRecord | ||
import org.apache.kafka.common.TopicPartition | ||
|
||
import java.time.Duration | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.CONSUMER | ||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL | ||
import static io.opentelemetry.api.trace.SpanKind.PRODUCER | ||
|
||
class KafkaClientSuppressReceiveSpansTest extends KafkaClientBaseTest { | ||
|
||
def "test kafka produce and consume"() { | ||
when: | ||
String greeting = "Hello Kafka!" | ||
runWithSpan("parent") { | ||
producer.send(new ProducerRecord(SHARED_TOPIC, greeting)) { meta, ex -> | ||
if (ex == null) { | ||
runWithSpan("producer callback") {} | ||
} else { | ||
runWithSpan("producer exception: " + ex) {} | ||
} | ||
} | ||
} | ||
|
||
then: | ||
// check that the message was received | ||
def records = consumer.poll(Duration.ofSeconds(5).toMillis()) | ||
for (record in records) { | ||
runWithSpan("processing") { | ||
assert record.value() == greeting | ||
assert record.key() == null | ||
} | ||
} | ||
|
||
assertTraces(1) { | ||
trace(0, 5) { | ||
span(0) { | ||
name "parent" | ||
kind INTERNAL | ||
hasNoParent() | ||
} | ||
span(1) { | ||
name SHARED_TOPIC + " send" | ||
kind PRODUCER | ||
childOf span(0) | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
} | ||
} | ||
span(2) { | ||
name SHARED_TOPIC + " process" | ||
kind CONSUMER | ||
childOf span(1) | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "process" | ||
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long | ||
"${SemanticAttributes.MESSAGING_KAFKA_PARTITION.key}" { it >= 0 } | ||
"kafka.offset" Long | ||
"kafka.record.queue_time_ms" { it >= 0 } | ||
} | ||
} | ||
span(3) { | ||
name "processing" | ||
childOf span(2) | ||
} | ||
span(4) { | ||
name "producer callback" | ||
kind INTERNAL | ||
childOf span(0) | ||
} | ||
} | ||
} | ||
} | ||
|
||
def "test pass through tombstone"() { | ||
when: | ||
producer.send(new ProducerRecord<>(SHARED_TOPIC, null)) | ||
|
||
then: | ||
// check that the message was received | ||
def records = consumer.poll(Duration.ofSeconds(5).toMillis()) | ||
for (record in records) { | ||
assert record.value() == null | ||
assert record.key() == null | ||
} | ||
|
||
assertTraces(1) { | ||
trace(0, 2) { | ||
span(0) { | ||
name SHARED_TOPIC + " send" | ||
kind PRODUCER | ||
hasNoParent() | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
"${SemanticAttributes.MESSAGING_KAFKA_TOMBSTONE.key}" true | ||
} | ||
} | ||
span(1) { | ||
name SHARED_TOPIC + " process" | ||
kind CONSUMER | ||
childOf span(0) | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "process" | ||
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long | ||
"${SemanticAttributes.MESSAGING_KAFKA_PARTITION.key}" { it >= 0 } | ||
"${SemanticAttributes.MESSAGING_KAFKA_TOMBSTONE.key}" true | ||
"kafka.offset" Long | ||
"kafka.record.queue_time_ms" { it >= 0 } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def "test records(TopicPartition) kafka consume"() { | ||
setup: | ||
def partition = 0 | ||
when: "send message" | ||
def greeting = "Hello from MockConsumer!" | ||
producer.send(new ProducerRecord<>(SHARED_TOPIC, partition, null, greeting)) | ||
then: "wait for PRODUCER span" | ||
waitForTraces(1) | ||
when: "receive messages" | ||
def consumerRecords = consumer.poll(Duration.ofSeconds(5).toMillis()) | ||
def recordsInPartition = consumerRecords.records(new TopicPartition(SHARED_TOPIC, partition)) | ||
for (record in recordsInPartition) { | ||
assert record.value() == greeting | ||
assert record.key() == null | ||
} | ||
then: | ||
assertTraces(1) { | ||
trace(0, 2) { | ||
span(0) { | ||
name SHARED_TOPIC + " send" | ||
kind PRODUCER | ||
hasNoParent() | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
"${SemanticAttributes.MESSAGING_KAFKA_PARTITION.key}" { it >= 0 } | ||
} | ||
} | ||
span(1) { | ||
name SHARED_TOPIC + " process" | ||
kind CONSUMER | ||
childOf span(0) | ||
attributes { | ||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "kafka" | ||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" SHARED_TOPIC | ||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "topic" | ||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "process" | ||
"${SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES.key}" Long | ||
"${SemanticAttributes.MESSAGING_KAFKA_PARTITION.key}" { it >= 0 } | ||
"kafka.offset" Long | ||
"kafka.record.queue_time_ms" { it >= 0 } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.