Skip to content
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 @@ -36,6 +36,7 @@ tasks {
excludeTestsMatching("WrapperSuppressReceiveSpansTest")
}
jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true")
systemProperty("otel.instrumentation.messaging.experimental.capture-headers", "test-message-header")
}

check {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.kafkaclients.v2_6;

import static java.util.Collections.emptyList;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -32,6 +34,9 @@ public class TracingConsumerInterceptor<K, V> implements ConsumerInterceptor<K,
.setMessagingReceiveInstrumentationEnabled(
ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.messaging.experimental.receive-telemetry.enabled", false))
.setCapturedHeaders(
ConfigPropertiesUtil.getList(
"otel.instrumentation.messaging.experimental.capture-headers", emptyList()))
.build();

private String consumerGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

package io.opentelemetry.instrumentation.kafkaclients.v2_6;

import static java.util.Collections.emptyList;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
Expand All @@ -22,7 +25,12 @@
*/
public class TracingProducerInterceptor<K, V> implements ProducerInterceptor<K, V> {

private static final KafkaTelemetry telemetry = KafkaTelemetry.create(GlobalOpenTelemetry.get());
private static final KafkaTelemetry telemetry =
KafkaTelemetry.builder(GlobalOpenTelemetry.get())
.setCapturedHeaders(
ConfigPropertiesUtil.getList(
"otel.instrumentation.messaging.experimental.capture-headers", emptyList()))
.build();

@Nullable private String clientId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void testInterceptors() throws InterruptedException {
new ProducerRecord<>(SHARED_TOPIC, greeting);
producerRecord
.headers()
// add header to test capturing header value as span attribute
.add("test-message-header", "test".getBytes(StandardCharsets.UTF_8))
// adding baggage header in w3c baggage format
.add(
"baggage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.kafkaclients.v2_6;

import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand All @@ -16,6 +17,7 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_BODY_SIZE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanContext;
Expand All @@ -42,6 +44,9 @@ void assertTraces() {
.hasKind(SpanKind.PRODUCER)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.test_message_header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
equalTo(MESSAGING_OPERATION, "publish"),
Expand All @@ -64,6 +69,9 @@ void assertTraces() {
.hasNoParent()
.hasLinksSatisfying(links -> assertThat(links).isEmpty())
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.test_message_header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
equalTo(MESSAGING_OPERATION, "receive"),
Expand All @@ -78,6 +86,9 @@ void assertTraces() {
.hasParent(trace.getSpan(0))
.hasLinks(LinkData.create(producerSpanContext.get()))
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.test_message_header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
equalTo(MESSAGING_OPERATION, "process"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
description: >
This instrumentation provides a library integration that enables messaging spans and metrics for Apache Kafka 2.6+ clients.
configurations:
- name: otel.instrumentation.messaging.experimental.capture-headers
description: A comma-separated list of header names to capture as span attributes.
type: list
default: ''
- name: otel.instrumentation.messaging.experimental.receive-telemetry.enabled
description: >
Enables experimental receive telemetry, which will cause consumers to start a new trace, with
only a span link connecting it to the producer trace.
type: boolean
default: false