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
@@ -1,6 +1,7 @@
package datadog.trace.instrumentation.kafka_clients;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.traceConfig;
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.OFFSET;
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.PARTITION;
import static datadog.trace.instrumentation.kafka_clients.KafkaDecorator.PRODUCER_DECORATE;
Expand Down Expand Up @@ -48,7 +49,11 @@ public void onCompletion(final RecordMetadata metadata, final Exception exceptio
callback.onCompletion(metadata, exception);
}
}
if (metadata == null || exception != null || metadata.partition() < 0) {
// trackBacklog is a no-op with DSM off, so skip building its tags.
if (metadata == null
|| exception != null
|| metadata.partition() < 0
|| !traceConfig().isDataStreamsEnabled()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.traceConfig;
import static datadog.trace.instrumentation.kafka_clients.KafkaDecorator.JAVA_KAFKA;
import static datadog.trace.instrumentation.kafka_clients.KafkaDecorator.KAFKA_PRODUCE;
import static datadog.trace.instrumentation.kafka_clients.KafkaDecorator.PRODUCER_DECORATE;
Expand Down Expand Up @@ -216,11 +217,16 @@ public static void onEnter(
&& !Config.get().isKafkaClientPropagationDisabledForTopic(record.topic())) {
setter = TextMapInjectAdapter.SETTER;
}
DataStreamsTags tags = createWithClusterId("kafka", OUTBOUND, record.topic(), clusterId);
// With DSM off the DSM propagator injects nothing, so skip building its tags and context.
DataStreamsTags tags =
traceConfig().isDataStreamsEnabled()
? createWithClusterId("kafka", OUTBOUND, record.topic(), clusterId)
: null;
try {
defaultPropagator().inject(span, record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
if (tags != null
&& (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
// message size.
// The stats are saved in the pathway context and sent in PayloadSizeAdvice.
Expand All @@ -240,8 +246,9 @@ record =
record.headers());

defaultPropagator().inject(span, record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
if (tags != null
&& (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic()))) {
Propagator dsmPropagator = Propagators.forConcern(DSM_CONCERN);
DataStreamsContext dsmContext = fromTagsWithoutCheckpoint(tags);
dsmPropagator.inject(span.with(dsmContext), record.headers(), setter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.instrumentation.kafka_clients38;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.traceConfig;
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.OFFSET;
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.PARTITION;
import static datadog.trace.instrumentation.kafka_clients38.KafkaDecorator.PRODUCER_DECORATE;
Expand Down Expand Up @@ -47,7 +48,11 @@ public void onCompletion(final RecordMetadata metadata, final Exception exceptio
callback.onCompletion(metadata, exception);
}
}
if (metadata == null || exception != null || metadata.partition() < 0) {
// trackBacklog is a no-op with DSM off, so skip building its tags.
if (metadata == null
|| exception != null
|| metadata.partition() < 0
|| !traceConfig().isDataStreamsEnabled()) {
return;
}
DataStreamsTags tags =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static datadog.trace.api.datastreams.DataStreamsTags.create;
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.DSM_CONCERN;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.traceConfig;
import static datadog.trace.instrumentation.kafka_clients38.KafkaDecorator.TIME_IN_QUEUE_ENABLED;
import static datadog.trace.instrumentation.kafka_common.StreamingContext.STREAMING_CONTEXT;

Expand Down Expand Up @@ -41,11 +42,16 @@ public static void onEnter(
&& !Config.get().isKafkaClientPropagationDisabledForTopic(record.topic())) {
setter = TextMapInjectAdapter.SETTER;
}
DataStreamsTags tags = create("kafka", OUTBOUND, record.topic(), null, clusterId);
// With DSM off the DSM propagator injects nothing, so skip building its tags and context.
DataStreamsTags tags =
traceConfig().isDataStreamsEnabled()
? create("kafka", OUTBOUND, record.topic(), null, clusterId)
: null;
try {
defaultPropagator().inject(span, record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
if (tags != null
&& (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
// message size.
// The stats are saved in the pathway context and sent in PayloadSizeAdvice.
Expand All @@ -65,8 +71,9 @@ record =
record.headers());

defaultPropagator().inject(span, record.headers(), setter);
if (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic())) {
if (tags != null
&& (STREAMING_CONTEXT.isDisabledForTopic(record.topic())
|| STREAMING_CONTEXT.isSinkTopic(record.topic()))) {
Propagator dsmPropagator = Propagators.forConcern(DSM_CONCERN);
DataStreamsContext dsmContext = fromTagsWithoutCheckpoint(tags);
dsmPropagator.inject(span.with(dsmContext), record.headers(), setter);
Expand Down
Loading