Adding links when using @WithSpan #4465
-
I'm using a combination of automatic and manual instrumentation in a project. I'd like to track items as they flow through the system. Imagine an Amazon order fulfillment system where you can ask to have all of your weekly orders sent to you on Wednesdays. Let's say I order a bunch of books on Friday, Saturday and Sunday. Each book is placed into the BatchProcessor by calling bufferTrackedItem(). When Wednesday rolls around, all 10 books I ordered are sent out at once by calling processBufferedItems(). I'd like to be able to trace how the books are processed through the system. Occasionally, items get lost and being able to track them through the system will let us determine where things go bad. As this is obviously a long-running operation, I'd like to use Links in the processBufferedItems() method to point back to the original TraceId/SpanId's for each of the ordered books. I don't see a way to add links via Spans. Is there a way to accomodate my use case? Thanks! public class BatchProcessor {
private Map<TrackedItem, SpanContext> bufferedItems = new HashMap<>();
@WithSpan("buffer-tracked-item")
public void bufferTrackedItem(TrackedItem item) {
bufferedItems.put(item, Span.current().getSpanContext());
}
@WithSpan("process-buffered-items")
public void processBufferedItems() {
Span span = Span.current();
for (Map.Event<TrackedItem, SpanContext> item : bufferedItems) {
TrackedItem trackedItem = item.getKey();
SpanContext originalSpanContext = item.getValue();
// do some work on the tracked item...
// It's easy to add Events to a span. I'd like to do something similar with Links.
// Can something like this be done?
span.addLink(originalSpanContext);
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi @frgauthier! currently links can only be added at span start, so that they can take part in sampling decision. there is some discussion in the specification repository about relaxing this "limitation", but this would require an update to the specification before any change to this behavior is done in the Java SDK |
Beta Was this translation helpful? Give feedback.
hi @frgauthier! currently links can only be added at span start, so that they can take part in sampling decision. there is some discussion in the specification repository about relaxing this "limitation", but this would require an update to the specification before any change to this behavior is done in the Java SDK