-
Due to size limits of traces in our Grafana/Tempo setup, I need to split traces into multiple smaller ones. for (Batch batch : batches) {
SpanContext parentSpanContext = Span.current().getSpanContext();
String parentTraceId = parentSpanContext.getTraceId();
SpanContext childSpanContext = SpanContext.create(IdGenerator.random().generateTraceId(),
IdGenerator.random().generateSpanId(), TraceFlags.getDefault(), TraceState.getDefault());
Context childContext = Context.current().with(Span.wrap(childSpanContext));
Tracer tracer = GlobalOpenTelemetry.getTracer("batches");
Span span = tracer.spanBuilder("download").setSpanKind(SpanKind.SERVER).setParent(childContext)
.addLink(parentSpanContext).startSpan();
try (Scope unused = span.makeCurrent()) {
// ... business logic here Unfortunately when trying to find the "child" traces in Tempo, they do not seem to have been exported. The other traces are there as expected. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
what happens at the end of the |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what's going wrong here, but one thing you can simplify is to use so...
I don't know if this will change anything, but it will at least simplify your code a bit, which might make it easier to track down what's going on. It results in:
If you use the logging exporter, can you see the spans that would be exported? Do they look like you expect? I see you're calling |
Beta Was this translation helpful? Give feedback.
I'm not sure what's going wrong here, but one thing you can simplify is to use
spanBuilder.setNoParent()
rather than artificially constructing a parent for the span you're building.so...
I don't know if this will change anything, but it will at least simplify your code a bit, which might make it easier to track down what's going on.
It results in: