bytecodealliance / bytecodealliance/opentelemetry-wasi

Panic in `rust/examples/spin-tracing`

Open
#37 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
12
Forks
7
PR merge metrics
No merged PRs in 30d

Description

There's a panic that happens when attempting to alter the parent span within a function that uses the `tracing::instrument` macro:
```text
thread '' (1) panicked at examples/spin-tracing/src/lib.rs:44:9:
Span has already been started, cannot set parent
```

```rust
#[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:
```rust
// 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.