Skip to main content

span_with_probe

Macro span_with_probe 

Source
span_with_probe!() { /* proc-macro */ }
Expand description

Like foundations::telemetry::tracing::span, plus a per-span USDT probe fired at span end.

Probes are only emitted on linux/x86_64; on any other platform the macro degrades to a plain foundations::telemetry::tracing::span call.

The probe shows up to tracers as <binary>:<usdt_provider>:span_end__<sanitized span name>, where sanitization replaces :: with __ and any other non-alphanumeric character with _.

Expands to a dedicated probe semaphore: a static in the .probes ELF section that the tracer (like bpftrace) increments on attach. When the semaphore is non-zero, the span start timestamp is recorded in the span state (regardless of span sampling), and the per-span probe_end function’s address is stored alongside it. When the last clone of the span drops, probe_end is called with the span duration in nanoseconds, executing the NOP whose address the stapsdt ELF note publishes as the span_end__<sanitized span name> probe location.

§Example

use foundations::telemetry::tracing::span_with_probe;

span_with_probe!("http::client::send_request", usdt_provider = "myapp")
     .into_context()
     .apply(do_exchange())
     .await

Options:

  • crate_path = "..." (defaults to ::foundations)
  • usdt_provider = "..." (defaults to the FOUNDATIONS_USDT_PROVIDER environment variable at compile time — settable per project via [env] in .cargo/config.toml — or "foundations" when unset); must be non-empty and must not contain :