Skip to content

Panic in rust/examples/spin-tracing #37

@asteurer

Description

@asteurer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions