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:
Tyler Benson 2018-03-29 12:32:50 +08:00
parent cb604a0932
commit 513cded8aa
2 changed files with 8 additions and 12 deletions

View File

@ -34,10 +34,6 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
"datadog.trace.instrumentation.kafka_clients.TracingIterable$TracingIterator",
"datadog.trace.instrumentation.kafka_clients.TracingIterable$SpanBuilderDecorator",
"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() {
super("kafka");
@ -75,7 +71,7 @@ public final class KafkaConsumerInstrumentation extends Instrumenter.Configurabl
@Advice.OnMethodExit(suppress = Throwable.class)
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)
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
implements TracingIterable.SpanBuilderDecorator<ConsumerRecord> {
public static final ConsumeScopeAction INSTANCE = new ConsumeScopeAction();
@Override
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.RESOURCE_NAME, "Consume Topic " + topic)
.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("partition", record.partition())
.withTag("offset", record.offset());

View File

@ -34,9 +34,6 @@ public class KafkaStreamsProcessorInstrumentation {
public static final HelperInjector HELPER_INJECTOR =
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)
public static class StartInstrumentation extends Instrumenter.Configurable {
@ -80,12 +77,12 @@ public class KafkaStreamsProcessorInstrumentation {
Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(record.value.headers()));
GlobalTracer.get()
.buildSpan(OPERATION)
.buildSpan("kafka.consume")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "kafka")
.withTag(DDTags.RESOURCE_NAME, "Consume Topic " + record.topic())
.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("partition", record.partition())
.withTag("offset", record.offset())