dcontext_tracing/span_info.rs
1/// Span metadata exposed as a dcontext value.
2///
3/// When [`DcontextLayer`](crate::DcontextLayer) is configured with
4/// [`include_span_info()`](crate::DcontextLayerBuilder::include_span_info),
5/// this type is automatically set in the context on span enter.
6///
7/// # Example
8///
9/// ```ignore
10/// use dcontext_tracing::SpanInfo;
11///
12/// let info: SpanInfo = dcontext::sync_ctx::get_context("dcontext.span").unwrap_or_default();
13/// println!("current span: {} ({})", info.name, info.target);
14/// ```
15#[derive(Clone, Default, Debug, serde::Serialize, serde::Deserialize)]
16pub struct SpanInfo {
17 /// The span's name (from `#[instrument]` or `tracing::span!`).
18 pub name: String,
19 /// The span's target (usually the module path).
20 pub target: String,
21 /// The span's level as a string ("TRACE", "DEBUG", "INFO", "WARN", "ERROR").
22 pub level: String,
23}
24
25/// The dcontext key used for [`SpanInfo`].
26pub const SPAN_INFO_KEY: &str = "dcontext.span";