Skip to content

Commit

Permalink
[pinpoint-apm#8834] Remove static isHeaderRecorded field from kafka p…
Browse files Browse the repository at this point in the history
…lugin
  • Loading branch information
emeroad committed May 3, 2022
1 parent 9a14d52 commit 3c684b9
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public class ConsumerRecordEntryPointInterceptor extends SpanRecursiveAroundInte

protected final int parameterIndex;

private static boolean isHeaderRecorded;
private final TraceFactoryProvider traceFactoryProvider;

public ConsumerRecordEntryPointInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor, int parameterIndex) {
super(traceContext, methodDescriptor, SCOPE_NAME);
traceContext.cacheApi(ENTRY_POINT_METHOD_DESCRIPTOR);
this.parameterIndex = parameterIndex;
KafkaConfig config = new KafkaConfig(traceContext.getProfilerConfig());
this.isHeaderRecorded = config.isHeaderRecorded();
this.traceFactoryProvider = new TraceFactoryProvider(config.isHeaderRecorded());
}

@Override
Expand Down Expand Up @@ -108,15 +108,21 @@ protected Object getTargetParameter(Object[] args) {
private Trace createTrace(ConsumerRecord consumerRecord) {
TraceFactoryProvider.TraceFactory traceFactory = traceFactoryReference.get();
if (traceFactory == null) {
traceFactory = TraceFactoryProvider.get(consumerRecord);
traceFactory = traceFactoryProvider.get(consumerRecord);
traceFactoryReference.compareAndSet(null, traceFactory);
}
return traceFactory.createTrace(traceContext, consumerRecord);
}

private static class TraceFactoryProvider {

private static TraceFactory get(Object object) {
private final boolean isHeaderRecorded;

public TraceFactoryProvider(boolean isHeaderRecorded) {
this.isHeaderRecorded = isHeaderRecorded;
}

private TraceFactory get(Object object) {
if (KafkaClientUtils.supportHeaders(object.getClass())) {
return new SupportContinueTraceFactory(isHeaderRecorded);
} else {
Expand Down

0 comments on commit 3c684b9

Please sign in to comment.