1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! The [`RecordContext`] extension trait for attaching context to a live span.
use RequestContext;
use record_optional_fields;
/// Attach `ctx`'s identifying fields to an existing span.
///
/// This is the extension-trait form of the recording logic used by
/// [`request_span`](super::request_span). Use it when you already hold a span (for example one
/// created by `#[tracing::instrument]`) that declared the relevant fields as
/// [`Empty`](tracing::field::Empty), and want to populate them from a context obtained later.
///
/// Recording a field the span did not declare is a no-op in `tracing`, so this
/// is always safe to call.
///
/// ```
/// use klauthed_core::context::RequestContext;
/// use klauthed_observability::RecordContext;
///
/// let ctx = RequestContext::new().with_tenant("acme");
/// let span = tracing::info_span!(
/// "work",
/// request_id = tracing::field::Empty,
/// tenant = tracing::field::Empty,
/// );
/// span.record_context(&ctx);
/// ```