Skip to content

Commit a1f26c8

Browse files
committed
post-review changes
1 parent 5b7ccc2 commit a1f26c8

File tree

27 files changed

+237
-235
lines changed

27 files changed

+237
-235
lines changed

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/AdviceScope.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public class AdviceScope {
2121
private final String item;
2222
private final Scope scope;
2323

24-
public AdviceScope(Context context, Scope scope, String item) {
24+
private AdviceScope(Context context, Scope scope, String item) {
2525
this.context = context;
2626
this.scope = scope;
2727
this.item = item;
2828
}
2929

3030
@Nullable
31-
public static AdviceScope start(String itemName) {
31+
public static AdviceScope enter(String itemName) {
3232
Context parentContext = currentContext();
3333
ChunkContext chunkContext = getChunkContext(parentContext);
3434
if (chunkContext == null || !shouldTraceItems()) {
@@ -43,7 +43,7 @@ public static AdviceScope start(String itemName) {
4343
return new AdviceScope(context, context.makeCurrent(), item);
4444
}
4545

46-
public void close(@Nullable Throwable thrown) {
46+
public void exit(@Nullable Throwable thrown) {
4747
scope.close();
4848
itemInstrumenter().end(context, item, null, thrown);
4949
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/chunk/ChunkSingletons.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1717
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
1818
import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksBuilder;
19-
import io.opentelemetry.instrumentation.api.util.VirtualField;
20-
import io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.ContextAndScope;
2119
import org.springframework.batch.core.scope.context.ChunkContext;
2220
import org.springframework.batch.core.step.builder.SimpleStepBuilder;
2321

2422
public class ChunkSingletons {
2523

2624
private static final Instrumenter<ChunkContextAndBuilder, Void> INSTRUMENTER;
2725

28-
public static final VirtualField<ChunkContext, ContextAndScope> CONTEXT_AND_SCOPE =
29-
VirtualField.find(ChunkContext.class, ContextAndScope.class);
30-
3126
static {
3227
InstrumenterBuilder<ChunkContextAndBuilder, Void> instrumenterBuilder =
3328
Instrumenter.builder(

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/chunk/StepBuilderInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.chunk;
77

8-
import static io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.chunk.ChunkSingletons.CONTEXT_AND_SCOPE;
98
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
109
import static net.bytebuddy.matcher.ElementMatchers.named;
1110
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
@@ -41,8 +40,7 @@ public static class BuildAdvice {
4140

4241
@Advice.OnMethodEnter(suppress = Throwable.class)
4342
public static void onEnter(@Advice.This AbstractTaskletStepBuilder<?> stepBuilder) {
44-
stepBuilder.listener(
45-
new TracingChunkExecutionListener(CONTEXT_AND_SCOPE, stepBuilder.getClass()));
43+
stepBuilder.listener(new TracingChunkExecutionListener(stepBuilder.getClass()));
4644
}
4745
}
4846
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/chunk/TracingChunkExecutionListener.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import org.springframework.core.Ordered;
2121

2222
public final class TracingChunkExecutionListener implements ChunkListener, Ordered {
23-
private final VirtualField<ChunkContext, ContextAndScope> executionVirtualField;
23+
private static final VirtualField<ChunkContext, ContextAndScope> CONTEXT_AND_SCOPE =
24+
VirtualField.find(ChunkContext.class, ContextAndScope.class);
2425
private final Class<?> builderClass;
2526
private ChunkContextAndBuilder chunkContextAndBuilder;
2627

27-
public TracingChunkExecutionListener(
28-
VirtualField<ChunkContext, ContextAndScope> executionVirtualField, Class<?> builderClass) {
29-
this.executionVirtualField = executionVirtualField;
28+
public TracingChunkExecutionListener(Class<?> builderClass) {
3029
this.builderClass = builderClass;
3130
}
3231

@@ -41,7 +40,7 @@ public void beforeChunk(ChunkContext chunkContext) {
4140
Context context = chunkInstrumenter().start(parentContext, chunkContextAndBuilder);
4241
// beforeJob & afterJob always execute on the same thread
4342
Scope scope = context.makeCurrent();
44-
executionVirtualField.set(chunkContext, new ContextAndScope(context, scope));
43+
CONTEXT_AND_SCOPE.set(chunkContext, new ContextAndScope(context, scope));
4544
}
4645

4746
@Override
@@ -57,12 +56,12 @@ public void afterChunkError(ChunkContext chunkContext) {
5756
}
5857

5958
private void end(ChunkContext chunkContext, @Nullable Throwable throwable) {
60-
ContextAndScope contextAndScope = executionVirtualField.get(chunkContext);
59+
ContextAndScope contextAndScope = CONTEXT_AND_SCOPE.get(chunkContext);
6160
if (contextAndScope == null) {
6261
return;
6362
}
6463

65-
executionVirtualField.set(chunkContext, null);
64+
CONTEXT_AND_SCOPE.set(chunkContext, null);
6665
contextAndScope.closeScope();
6766
chunkInstrumenter().end(contextAndScope.getContext(), chunkContextAndBuilder, null, throwable);
6867
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/item/JsrChunkProcessorInstrumentation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public static class ProvideAdvice {
4545
@Nullable
4646
@Advice.OnMethodEnter(suppress = Throwable.class)
4747
public static AdviceScope onEnter() {
48-
return AdviceScope.start(ITEM_OPERATION_READ);
48+
return AdviceScope.enter(ITEM_OPERATION_READ);
4949
}
5050

5151
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
5252
public static void onExit(
5353
@Advice.Thrown @Nullable Throwable thrown,
5454
@Advice.Enter @Nullable AdviceScope adviceScope) {
5555
if (adviceScope != null) {
56-
adviceScope.close(thrown);
56+
adviceScope.exit(thrown);
5757
}
5858
}
5959
}
@@ -64,15 +64,15 @@ public static class TransformAdvice {
6464
@Nullable
6565
@Advice.OnMethodEnter(suppress = Throwable.class)
6666
public static AdviceScope onEnter() {
67-
return AdviceScope.start(ITEM_OPERATION_PROCESS);
67+
return AdviceScope.enter(ITEM_OPERATION_PROCESS);
6868
}
6969

7070
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
7171
public static void onExit(
7272
@Advice.Thrown @Nullable Throwable thrown,
7373
@Advice.Enter @Nullable AdviceScope adviceScope) {
7474
if (adviceScope != null) {
75-
adviceScope.close(thrown);
75+
adviceScope.exit(thrown);
7676
}
7777
}
7878
}
@@ -83,15 +83,15 @@ public static class PersistAdvice {
8383
@Nullable
8484
@Advice.OnMethodEnter(suppress = Throwable.class)
8585
public static AdviceScope onEnter() {
86-
return AdviceScope.start(ITEM_OPERATION_WRITE);
86+
return AdviceScope.enter(ITEM_OPERATION_WRITE);
8787
}
8888

8989
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
9090
public static void onExit(
9191
@Advice.Thrown @Nullable Throwable thrown,
9292
@Advice.Enter @Nullable AdviceScope adviceScope) {
9393
if (adviceScope != null) {
94-
adviceScope.close(thrown);
94+
adviceScope.exit(thrown);
9595
}
9696
}
9797
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/item/SimpleChunkProcessorInstrumentation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public static class ProcessAdvice {
4444
@Advice.OnMethodEnter(suppress = Throwable.class)
4545
public static AdviceScope onEnter(
4646
@Advice.FieldValue("itemProcessor") ItemProcessor<?, ?> itemProcessor) {
47-
return AdviceScope.start(ITEM_OPERATION_PROCESS);
47+
return AdviceScope.enter(ITEM_OPERATION_PROCESS);
4848
}
4949

5050
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
5151
public static void onExit(
5252
@Advice.Thrown @Nullable Throwable thrown,
5353
@Advice.Enter @Nullable AdviceScope adviceScope) {
5454
if (adviceScope != null) {
55-
adviceScope.close(thrown);
55+
adviceScope.exit(thrown);
5656
}
5757
}
5858
}
@@ -63,7 +63,7 @@ public static class WriteAdvice {
6363
@Nullable
6464
@Advice.OnMethodEnter(suppress = Throwable.class)
6565
public static AdviceScope onEnter(@Advice.FieldValue("itemWriter") ItemWriter<?> itemWriter) {
66-
return AdviceScope.start(ITEM_OPERATION_WRITE);
66+
return AdviceScope.enter(ITEM_OPERATION_WRITE);
6767
}
6868

6969
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
@@ -72,7 +72,7 @@ public static void onExit(
7272
@Advice.Enter @Nullable AdviceScope adviceScope) {
7373

7474
if (adviceScope != null) {
75-
adviceScope.close(thrown);
75+
adviceScope.exit(thrown);
7676
}
7777
}
7878
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/item/SimpleChunkProviderInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public static class ReadAdvice {
3939
@Nullable
4040
@Advice.OnMethodEnter(suppress = Throwable.class)
4141
public static AdviceScope onEnter() {
42-
return AdviceScope.start(ITEM_OPERATION_READ);
42+
return AdviceScope.enter(ITEM_OPERATION_READ);
4343
}
4444

4545
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
4646
public static void onExit(
4747
@Advice.Thrown @Nullable Throwable thrown,
4848
@Advice.Enter @Nullable AdviceScope adviceScope) {
4949
if (adviceScope != null) {
50-
adviceScope.close(thrown);
50+
adviceScope.exit(thrown);
5151
}
5252
}
5353
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/job/JobBuilderHelperInstrumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job;
77

8-
import static io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job.JobSingletons.CONTEXT_AND_SCOPE;
98
import static net.bytebuddy.matcher.ElementMatchers.isProtected;
109
import static net.bytebuddy.matcher.ElementMatchers.named;
1110
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -40,7 +39,7 @@ public static class EnhanceAdvice {
4039

4140
@Advice.OnMethodEnter(suppress = Throwable.class)
4241
public static void onEnter(@Advice.This JobBuilderHelper<?> jobBuilder) {
43-
jobBuilder.listener(new TracingJobExecutionListener(CONTEXT_AND_SCOPE));
42+
jobBuilder.listener(new TracingJobExecutionListener());
4443
}
4544
}
4645
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/job/JobFactoryBeanInstrumentation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job;
77

8-
import static io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job.JobSingletons.CONTEXT_AND_SCOPE;
98
import static net.bytebuddy.matcher.ElementMatchers.isArray;
109
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
1110
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
@@ -61,10 +60,10 @@ public static Object[] onEnter(@Advice.Argument(0) Object[] originalListeners) {
6160
Object[] listeners = originalListeners;
6261

6362
if (listeners == null) {
64-
listeners = new Object[] {new TracingJobExecutionListener(CONTEXT_AND_SCOPE)};
63+
listeners = new Object[] {new TracingJobExecutionListener()};
6564
} else {
6665
Object[] newListeners = new Object[listeners.length + 1];
67-
newListeners[0] = new TracingJobExecutionListener(CONTEXT_AND_SCOPE);
66+
newListeners[0] = new TracingJobExecutionListener();
6867
System.arraycopy(listeners, 0, newListeners, 1, listeners.length);
6968
listeners = newListeners;
7069
}

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/job/JobParserJobFactoryBeanInstrumentation.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job;
77

8-
import static io.opentelemetry.javaagent.instrumentation.spring.batch.v3_0.job.JobSingletons.CONTEXT_AND_SCOPE;
98
import static net.bytebuddy.matcher.ElementMatchers.isArray;
109
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
1110
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
@@ -59,18 +58,14 @@ public static class SetListenersAdvice {
5958
@Advice.AssignReturned.AsScalar
6059
@Advice.OnMethodEnter(suppress = Throwable.class)
6160
public static JobExecutionListener[] onEnter(
62-
@Advice.Argument(0) JobExecutionListener[] originalListeners) {
63-
JobExecutionListener[] listeners = originalListeners;
64-
61+
@Advice.Argument(0) JobExecutionListener[] listeners) {
6562
if (listeners == null) {
66-
listeners = new JobExecutionListener[] {new TracingJobExecutionListener(CONTEXT_AND_SCOPE)};
67-
} else {
68-
JobExecutionListener[] newListeners = new JobExecutionListener[listeners.length + 1];
69-
newListeners[0] = new TracingJobExecutionListener(CONTEXT_AND_SCOPE);
70-
System.arraycopy(listeners, 0, newListeners, 1, listeners.length);
71-
listeners = newListeners;
63+
return new JobExecutionListener[] {new TracingJobExecutionListener()};
7264
}
73-
return listeners;
65+
JobExecutionListener[] newListeners = new JobExecutionListener[listeners.length + 1];
66+
newListeners[0] = new TracingJobExecutionListener();
67+
System.arraycopy(listeners, 0, newListeners, 1, listeners.length);
68+
return newListeners;
7469
}
7570
}
7671
}

0 commit comments

Comments
 (0)