I'm trying to instrument a function using tokio tracing, get its arguments and then walk to the parent span
and get the values for a handful of fields. I was able to successfully get the argument by creating a new Layer as follows:
impl<S> Layer<S> for MyTestLayer
where
S: tracing::Subscriber,
S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>,
{
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let span = ctx.span(id).unwrap();
let mut visitor = MyVisitor{ ... };
attrs.record(&mut visitor);
...
}
This seems to work and lets me get the attributes
for the expected span
. However, visiting each field/value with a visitor feels like I'm doing something wrong. Is this the best way to get the attribute values?
From here, I'd like to get two fields from the parent span. It seems like I should be able to do something like:
let parent = span.parent().unwrap();
let parent_fields = p.fields();
// ... Read the data from the fields?
However, this doesn't seem to work as fields()
provides a FieldSet
and no apparent access to the values or ValueSet
. What's the proper way of getting a value from the parent field? Is there an easier/better way to do this?