pub struct TracingField { /* private fields */ }Expand description
Unified tracing metadata for a context key.
Controls three behaviors:
- Extract: populate a context variable from a tracing span field
- Enrich log: include the context value in log output
- Record span: record the context value into span fields
Created via TracingFieldBuilder:
use dcontext_tracing::TracingField;
builder.register_with::<String>("request_id", |opts| {
opts.cached().with_metadata(
TracingField::builder("rid")
.extract_from_str(|s| Some(s.to_string()))
.enrich_display::<String>() // enables both log + span
.build()
)
});Implementations§
Source§impl TracingField
impl TracingField
Sourcepub fn builder(log_name: &'static str) -> TracingFieldBuilder
pub fn builder(log_name: &'static str) -> TracingFieldBuilder
Start building a TracingField with the given log field name.
The log_name is the field name used in log output and (by default)
span recording. It can differ from the context key.
Sourcepub fn span_field(&self) -> Option<&'static str>
pub fn span_field(&self) -> Option<&'static str>
The span field name to extract from, if extraction is enabled.
Sourcepub fn record_field(&self) -> &'static str
pub fn record_field(&self) -> &'static str
The span field name to record into.
Returns record_field if set, otherwise log_name.
Sourcepub fn has_extract(&self) -> bool
pub fn has_extract(&self) -> bool
Whether this field has extraction enabled.
Sourcepub fn has_enrich(&self) -> bool
pub fn has_enrich(&self) -> bool
Whether this field has any enrichment enabled (log or span).
Sourcepub fn has_log_enrich(&self) -> bool
pub fn has_log_enrich(&self) -> bool
Whether this field has log enrichment enabled.
Sourcepub fn has_span_record(&self) -> bool
pub fn has_span_record(&self) -> bool
Whether this field has span recording enabled.
Sourcepub fn format(&self, any_val: &dyn Any) -> Option<String>
pub fn format(&self, any_val: &dyn Any) -> Option<String>
Format a type-erased value for log enrichment.
Returns None if log enrichment is not enabled or the type doesn’t match.
Sourcepub fn format_for_span(&self, any_val: &dyn Any) -> Option<String>
pub fn format_for_span(&self, any_val: &dyn Any) -> Option<String>
Format a type-erased value for span recording.
Returns None if span recording is not enabled or the type doesn’t match.