vector_core/
span_fields.rs

1/// Span field name that should be captured onto log events emitted by the `internal_logs`
2/// source. Vector's `SpanFields` visitor only captures fields `component_*` by default;
3/// downstream crates can extend that set through this type.
4///
5/// Use [`register_extra_span_field!`](crate::register_extra_span_field) to register one.
6#[derive(Debug)]
7pub struct SpanField(pub &'static str); // name of the span field
8
9inventory::collect!(SpanField); // collect the span field names
10
11/// Register a tracing-span field name that downstream crates want preserved on Vector's
12/// internal observability output.
13///
14/// A single registration covers both output channels:
15///
16/// * On metrics, the field is added to the allowlist consulted by
17///   [`VectorLabelFilter`](crate::metrics) (alongside Vector's built-in `component_id`,
18///   `component_type`, `component_kind`, `buffer_type`), so `metrics-tracing-context` no
19///   longer drops it before the metrics registry sees it.
20/// * On logs/traces emitted via `internal_logs`, the field is added to the allowlist
21///   consulted by `SpanFields` (alongside the existing `component_*` prefix gate), so it is
22///   captured onto the log event under `vector.<field>`.
23///
24/// Example: an embedder that owns a "deployment-version" concept of its own can write
25/// `register_extra_span_field!("deployment_version");` once at module scope and any internal
26/// metric or log emitted from inside a span carrying that field will inherit it.
27///
28/// Registrations are collected at link time via the `inventory` crate, so both read paths
29/// are lock-free. The expansion goes through this crate's re-exports of `inventory`,
30/// [`MetricLabel`](crate::metrics::MetricLabel), and [`SpanField`], so callers do not need
31/// a direct `inventory` dependency.
32#[macro_export]
33macro_rules! register_extra_span_field {
34    ($key:expr) => {
35        $crate::__inventory::submit! {
36            $crate::metrics::MetricLabel($key)
37        }
38        $crate::__inventory::submit! {
39            $crate::SpanField($key)
40        }
41    };
42}