Skip to content
Open
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 @@ -46,6 +46,7 @@
import datadog.trace.instrumentation.kafka_common.ClusterIdHolder;
import datadog.trace.instrumentation.kafka_common.KafkaConfigHelper;
import datadog.trace.instrumentation.kafka_common.MetadataState;
import datadog.trace.instrumentation.kafka_common.Utils;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -219,7 +220,7 @@ public static void onEnter(
}
DataStreamsTags tags = createWithClusterId("kafka", OUTBOUND, record.topic(), clusterId);
try {
defaultPropagator().inject(span, record.headers(), setter);
defaultPropagator().inject(Utils.currentContext(), record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
// inject the context in the headers, but delay sending the stats until we know the
Expand All @@ -241,7 +242,7 @@ record =
record.value(),
record.headers());

defaultPropagator().inject(span, record.headers(), setter);
defaultPropagator().inject(Utils.currentContext(), record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
Propagator dsmPropagator = Propagators.forConcern(DSM_CONCERN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.kafka_common.MetadataState;
import datadog.trace.instrumentation.kafka_common.Utils;
import net.bytebuddy.asm.Advice;
import org.apache.kafka.clients.Metadata;
import org.apache.kafka.clients.producer.ProducerRecord;
Expand All @@ -43,7 +44,7 @@ public static void onEnter(
}
DataStreamsTags tags = create("kafka", OUTBOUND, record.topic(), null, clusterId);
try {
defaultPropagator().inject(span, record.headers(), setter);
defaultPropagator().inject(Utils.currentContext(), record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
// inject the context in the headers, but delay sending the stats until we know the
Expand All @@ -65,7 +66,7 @@ record =
record.value(),
record.headers());

defaultPropagator().inject(span, record.headers(), setter);
defaultPropagator().inject(Utils.currentContext(), record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
Propagator dsmPropagator = Propagators.forConcern(DSM_CONCERN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.instrumentation.kafka_common;

import datadog.context.Context;
import datadog.trace.api.datastreams.DataStreamsTransactionTracker;
import java.nio.charset.StandardCharsets;
import org.apache.kafka.clients.consumer.ConsumerRecord;
Expand All @@ -9,6 +10,11 @@
public final class Utils {
private Utils() {} // prevent instantiation

/** Returns the current context from the thread-local context store. */
public static Context currentContext() {
return Context.current();
}

public static DataStreamsTransactionTracker.TransactionSourceReader
DSM_TRANSACTION_SOURCE_READER =
(source, headerName) -> {
Expand Down