If I understand what you are trying to achieve here, that is the default behavior of Sleuth, please take a look at the docs for the trace-span and the parent-child spans relationships.
The only thing you need to do is creating a new Span every time you notify a subscriber. There are multiple ways to do this, please see the the docs (e.g.: tracer.withSpan
, @NewSpan
).
Here's an imaginary example:
@GetMapping("/something") // Sleuth has already created a span for your endpoint
public void something() {
subscribers.forEach(subscriber -> notify(subscriber, new Event("foo")));
}
@NewSpan // This does the trick
public void notify(Subscriber subscriber, Event event) {
subscriber.notify(event);
}
If you want to tag your spans, please check the link to the docs I put above, it will show you how to attach tags.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…