Hi, I'm using SB 3.1 and the properties
management.tracing.propagation.type=B3
management.tracing.brave.spanJoiningSupported=true
When I launch a request like
curl http://localhost:8080/hello -H "b3: 646ce89e9fa17f1ed7e8b40fdaad443b-d7e8b40fdaad443b"
If span joined is supported I expect that current span in my controller was d7e8b40fdaad443b but the reality is that is created a new span per request
Controller
@GetMapping(path = "/hello")
public TraceData hello() {
TraceContext traceContext = tracer.currentSpan().context();
System.out.println(tracingProperties.getBrave().isSpanJoiningSupported());
return new TraceData(traceContext.traceId(), traceContext.spanId(), traceContext.parentId());
}
Test
@Test
void textJoinSpan() throws Exception {
mockMvc.perform(get("/hello")
.header("b3","646ce89e9fa17f1ed7e8b40fdaad443b-d7e8b40fdaad443b"))
.andExpect(status().isOk())
.andExpect(content().json("""
{"traceId":"646ce89e9fa17f1ed7e8b40fdaad443b","spanId":"d7e8b40fdaad443b","parentSpanId":null}
"""));
}
Sorry for my english. I expect the next example could clarify the problem https://github.com/rgarciapariente/TestJoinSpanApplicationTests
Regards
Comment From: jonatan-ivanov
Please check the docs of Brave: https://github.com/openzipkin/brave/tree/master/brave#sharing-span-ids-between-client-and-server
Tracer.joinSpan attempts to continue this trace, using the same span ID if supported, or creating a child span if not.
If you ask Brave (our instrumentation does) to create a new Span, it will create a new one. You can ask it to continue the same span if supported by calling tracing.joinSpan(parentSpan.context()), please also see the tests for usage example: https://github.com/spring-projects/spring-boot/blob/40f5d650f97f1d78f0972ea4d0380225273b1743/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfigurationTests.java#L235-L248