Advice shouldn’t reference fields from non-injected classes
It might not be accessible on the classpath and cause failures.
This commit is contained in:
parent
cb604a0932
commit
513cded8aa
|
@ -34,10 +34,6 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
|
||||||
"datadog.trace.instrumentation.kafka_clients.TracingIterable$TracingIterator",
|
"datadog.trace.instrumentation.kafka_clients.TracingIterable$TracingIterator",
|
||||||
"datadog.trace.instrumentation.kafka_clients.TracingIterable$SpanBuilderDecorator",
|
"datadog.trace.instrumentation.kafka_clients.TracingIterable$SpanBuilderDecorator",
|
||||||
"datadog.trace.instrumentation.kafka_clients.KafkaConsumerInstrumentation$ConsumeScopeAction");
|
"datadog.trace.instrumentation.kafka_clients.KafkaConsumerInstrumentation$ConsumeScopeAction");
|
||||||
public static final ConsumeScopeAction CONSUME_ACTION = new ConsumeScopeAction();
|
|
||||||
|
|
||||||
private static final String OPERATION = "kafka.consume";
|
|
||||||
private static final String COMPONENT_NAME = "java-kafka";
|
|
||||||
|
|
||||||
public KafkaConsumerInstrumentation() {
|
public KafkaConsumerInstrumentation() {
|
||||||
super("kafka");
|
super("kafka");
|
||||||
|
@ -75,7 +71,7 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
|
||||||
|
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void wrap(@Advice.Return(readOnly = false) Iterable<ConsumerRecord> iterable) {
|
public static void wrap(@Advice.Return(readOnly = false) Iterable<ConsumerRecord> iterable) {
|
||||||
iterable = new TracingIterable(iterable, OPERATION, CONSUME_ACTION);
|
iterable = new TracingIterable(iterable, "kafka.consume", ConsumeScopeAction.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +79,15 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
|
||||||
|
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void wrap(@Advice.Return(readOnly = false) Iterator<ConsumerRecord> iterator) {
|
public static void wrap(@Advice.Return(readOnly = false) Iterator<ConsumerRecord> iterator) {
|
||||||
iterator = new TracingIterable.TracingIterator(iterator, OPERATION, CONSUME_ACTION);
|
iterator =
|
||||||
|
new TracingIterable.TracingIterator(
|
||||||
|
iterator, "kafka.consume", ConsumeScopeAction.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConsumeScopeAction
|
public static class ConsumeScopeAction
|
||||||
implements TracingIterable.SpanBuilderDecorator<ConsumerRecord> {
|
implements TracingIterable.SpanBuilderDecorator<ConsumerRecord> {
|
||||||
|
public static final ConsumeScopeAction INSTANCE = new ConsumeScopeAction();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decorate(final Tracer.SpanBuilder spanBuilder, final ConsumerRecord record) {
|
public void decorate(final Tracer.SpanBuilder spanBuilder, final ConsumerRecord record) {
|
||||||
|
@ -101,7 +100,7 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
|
||||||
.withTag(DDTags.SERVICE_NAME, "kafka")
|
.withTag(DDTags.SERVICE_NAME, "kafka")
|
||||||
.withTag(DDTags.RESOURCE_NAME, "Consume Topic " + topic)
|
.withTag(DDTags.RESOURCE_NAME, "Consume Topic " + topic)
|
||||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||||
.withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
|
.withTag(Tags.COMPONENT.getKey(), "java-kafka")
|
||||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||||
.withTag("partition", record.partition())
|
.withTag("partition", record.partition())
|
||||||
.withTag("offset", record.offset());
|
.withTag("offset", record.offset());
|
||||||
|
|
|
@ -34,9 +34,6 @@ public class KafkaStreamsProcessorInstrumentation {
|
||||||
public static final HelperInjector HELPER_INJECTOR =
|
public static final HelperInjector HELPER_INJECTOR =
|
||||||
new HelperInjector("datadog.trace.instrumentation.kafka_streams.TextMapExtractAdapter");
|
new HelperInjector("datadog.trace.instrumentation.kafka_streams.TextMapExtractAdapter");
|
||||||
|
|
||||||
private static final String OPERATION = "kafka.consume";
|
|
||||||
private static final String COMPONENT_NAME = "java-kafka";
|
|
||||||
|
|
||||||
@AutoService(Instrumenter.class)
|
@AutoService(Instrumenter.class)
|
||||||
public static class StartInstrumentation extends Instrumenter.Configurable {
|
public static class StartInstrumentation extends Instrumenter.Configurable {
|
||||||
|
|
||||||
|
@ -80,12 +77,12 @@ public class KafkaStreamsProcessorInstrumentation {
|
||||||
Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(record.value.headers()));
|
Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(record.value.headers()));
|
||||||
|
|
||||||
GlobalTracer.get()
|
GlobalTracer.get()
|
||||||
.buildSpan(OPERATION)
|
.buildSpan("kafka.consume")
|
||||||
.asChildOf(extractedContext)
|
.asChildOf(extractedContext)
|
||||||
.withTag(DDTags.SERVICE_NAME, "kafka")
|
.withTag(DDTags.SERVICE_NAME, "kafka")
|
||||||
.withTag(DDTags.RESOURCE_NAME, "Consume Topic " + record.topic())
|
.withTag(DDTags.RESOURCE_NAME, "Consume Topic " + record.topic())
|
||||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||||
.withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
|
.withTag(Tags.COMPONENT.getKey(), "java-kafka")
|
||||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||||
.withTag("partition", record.partition())
|
.withTag("partition", record.partition())
|
||||||
.withTag("offset", record.offset())
|
.withTag("offset", record.offset())
|
||||||
|
|
Loading…
Reference in New Issue