|
@@ -14,6 +14,7 @@ import io.opentelemetry.api.trace.SpanContext;
|
|
import io.opentelemetry.context.Context;
|
|
import io.opentelemetry.context.Context;
|
|
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
|
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
|
import org.springframework.batch.core.scope.context.ChunkContext;
|
|
import org.springframework.batch.core.scope.context.ChunkContext;
|
|
|
|
+import org.springframework.batch.core.step.builder.SimpleStepBuilder;
|
|
|
|
|
|
public class ChunkExecutionTracer extends BaseTracer {
|
|
public class ChunkExecutionTracer extends BaseTracer {
|
|
private static final ChunkExecutionTracer TRACER = new ChunkExecutionTracer();
|
|
private static final ChunkExecutionTracer TRACER = new ChunkExecutionTracer();
|
|
@@ -22,19 +23,22 @@ public class ChunkExecutionTracer extends BaseTracer {
|
|
return TRACER;
|
|
return TRACER;
|
|
}
|
|
}
|
|
|
|
|
|
- public Context startSpan(ChunkContext chunkContext) {
|
|
|
|
|
|
+ public Context startSpan(ChunkContext chunkContext, Class<?> builderClass) {
|
|
Context parentContext = Context.current();
|
|
Context parentContext = Context.current();
|
|
- SpanBuilder spanBuilder = spanBuilder(parentContext, spanName(chunkContext), INTERNAL);
|
|
|
|
|
|
+ SpanBuilder spanBuilder =
|
|
|
|
+ spanBuilder(parentContext, spanName(chunkContext, builderClass), INTERNAL);
|
|
if (shouldCreateRootSpanForChunk()) {
|
|
if (shouldCreateRootSpanForChunk()) {
|
|
linkParentSpan(spanBuilder, parentContext);
|
|
linkParentSpan(spanBuilder, parentContext);
|
|
}
|
|
}
|
|
return parentContext.with(spanBuilder.startSpan());
|
|
return parentContext.with(spanBuilder.startSpan());
|
|
}
|
|
}
|
|
|
|
|
|
- private static String spanName(ChunkContext chunkContext) {
|
|
|
|
|
|
+ private static String spanName(ChunkContext chunkContext, Class<?> builderClass) {
|
|
String jobName = chunkContext.getStepContext().getJobName();
|
|
String jobName = chunkContext.getStepContext().getJobName();
|
|
String stepName = chunkContext.getStepContext().getStepName();
|
|
String stepName = chunkContext.getStepContext().getStepName();
|
|
- return "BatchJob " + jobName + "." + stepName + ".Chunk";
|
|
|
|
|
|
+ // only use "Chunk" for item processing steps, steps that use custom Tasklets will get "Tasklet"
|
|
|
|
+ String type = SimpleStepBuilder.class.isAssignableFrom(builderClass) ? "Chunk" : "Tasklet";
|
|
|
|
+ return "BatchJob " + jobName + "." + stepName + "." + type;
|
|
}
|
|
}
|
|
|
|
|
|
private static void linkParentSpan(SpanBuilder spanBuilder, Context parentContext) {
|
|
private static void linkParentSpan(SpanBuilder spanBuilder, Context parentContext) {
|