There's a panic that happens when attempting to alter the parent span within a function that uses the tracing::instrument macro:
thread '<unnamed>' (1) panicked at examples/spin-tracing/src/lib.rs:44:9:
Span has already been started, cannot set parent
#[instrument(fields(my_attribute = "my-value"))]
fn main_operation() {
let wasi_propagator = opentelemetry_wasi::TraceContextPropagator::new();
if let Err(e) =
// Panics
tracing::Span::current().set_parent(wasi_propagator.extract(&Context::current()))
{
panic!("{e}");
};
tracing::info!(name: "Main span event", foo = "1");
child_operation();
}
This can be worked around by moving the host context extraction into the handle_spin_tracing method; however, this is not ideal:
// Propagate the context from the Wasm host
let wasi_propagator = opentelemetry_wasi::TraceContextPropagator::new();
let _guard = wasi_propagator.extract(&Context::current()).attach();
main_operation();
We need to investigate whether there is a way to set the parent span after the span has already been started.
There's a panic that happens when attempting to alter the parent span within a function that uses the
tracing::instrumentmacro:This can be worked around by moving the host context extraction into the
handle_spin_tracingmethod; however, this is not ideal:We need to investigate whether there is a way to set the parent span after the span has already been started.