i have an ETL pipeline with 5 steps. Each step can be executed on a different thread and different application.
That makes it really hard to pass down the otel trace context through everything because the internals are not available for me so all i have access to are the processings steps.
What iam looking for is a way to construct the trace context just from a single id which uniquely identifies a complete run through all the 5 steps of a single data entry.
Example:
Data package | step | thread | application |
---|---|---|---|
id_1234 | 1 | thread_01 | app_01 |
id_1234 | 2 | thread_02 | app_01 |
id_1234 | 3 | thread_10 | app_02 |
id_1234 | 4 | thread_01 | app_01 |
id_1234 | 5 | thread_05 | app_02 |
id_5555 | 1 | thread_05 | app_02 |
id_5555 | 2 | thread_01 | app_02 |
id_5555 | 3 | thread_05 | app_01 |
id_5555 | 4 | thread_06 | app_02 |
id_5555 | 5 | thread_15 | app_02 |
What iam looking for is code which works a little bit like this:
public class Step1 {
public void execute(DataPackage obj){
var otelContext = SpanContext.create(
TraceId.fromBytes(obj.getUniqueId().getBytes()),
SpanId.fromBytes(processorName.getBytes()),
TraceFlags.getDefault(),
TraceState.getDefault()
);
var wrap = Span.wrap(otelContext);
var with = Context.root().with(wrap);
var span = tracer.spanBuilder("Step1").setParent(with).startSpan();
CompletableFuture.runAsync(() -> { /* the code is here*/ }).whenComplete((c1, exception) -> {
if (exception != null) {
span.recordException(exception);
} else {
span.end();
}
});
}
}
What happens is that the start and the end of the span are separate and not under the same trace context. So something goes wrong here