tracing
tracing copied to clipboard
mock: correct contextual/explicit parent assertions
Motivation
When recording the parent of an event or span, the MockCollector
treats an explicit parent of None
(i.e. an event or span that is an
explicit root) in the same way as if there is no explicit root. This
leads to it picking up the contextual parent or treating the event or
span as a contextual root.
Solution
This change refactors the recording of the parent to use is_contextual
to distinguish whether or not an explicit parent has been specified. The
actual parent is also written into a Parent
enum so that the expected
and actual values can be compared in a more explicit way.
Additionally, the Parent
struct has been moved into its own module and
the check behavior has been fixed. The error message has also been
unified across all cases.
Given the number of different cases involved in checking parents,
separate integration tests have been added to tracing-mock
specifically for testing all the positive and negative cases when
asserting on the parents of events and spans.
There were two tests in tracing-attributes
which specified both an
explicit and a contextual parent. This behavior was never intended to
work as all events and spans are either contextual or not. The tests
have been corrected to only expect one of the two.
Fixes: #2440
The clippy failure is unrelated to this change, so don't worry about that.
Marked this PR as a draft as it has been superceded by #3004.
Closing this one in favor of #3004 which has now been merged.