-
Hey everybody, I have a small question regarding the parent/child relationship in the case The reason this confuses me a little is because this a little is when you consider the following scenario: let a = tracing::info_span!("A");
let b = a.in_scope(|| {
tracing::info_span!("B")
});
tracing::info_span!("C").in_scope(|| {
b.in_scope(|| {
// ...
});
}); In that case, the parent of If I understand everything correctly my main question is: What should the parent/child relationship of spans express conceptually? Maybe I just missed it in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You do understand everything correctly. In most scenarios you enter a span inside its parent so this shouldn't be an issue. Setting the parent to the current span when entered would not work because you might enter it multiple times in different contexts. Setting it on the first enter would be more confusing than setting it on creation and would be weird with explicit parents. I can imagine the example you created to happen where span A is a producer that creates some task, instruments it with span B which is set as the producer span's child and without running that task, it sends it to another thread where a worker thread runs in span C and executes the task, thus entering the span there. It would be equally valid to instrument the task on the other side with the consumer span as the parent, this really depends on what you want to track more. Anyway, the parent-child relationship should imply some form of causality and or being part of a bigger whole. It's vague, but I can't give you more. |
Beta Was this translation helpful? Give feedback.
You do understand everything correctly.
In most scenarios you enter a span inside its parent so this shouldn't be an issue.
Setting the parent to the current span when entered would not work because you might enter it multiple times in different contexts. Setting it on the first enter would be more confusing than setting it on creation and would be weird with explicit parents.
I can imagine the example you created to happen where span A is a producer that creates some task, instruments it with span B which is set as the producer span's child and without running that task, it sends it to another thread where a worker thread runs in span C and executes the task, thus entering the span there…