macro_rules! completion_parent_span {
(
target: $target:literal,
parent: $parent:expr,
name: $name:literal,
operation: $operation:expr,
system_instructions: $system:expr
$(, $($extra:tt)*)?
) => { ... };
(
target: $target:literal,
name: $name:literal,
operation: $operation:expr,
system_instructions: $system:expr
$(, $($extra:tt)*)?
) => { ... };
}Expand description
Declare a completion-parent span conforming to the adoption contract.
This macro is the single declarative source of the contract: it declares
COMPLETION_PARENT_MARKER_FIELD and every field in
COMPLETION_PARENT_REQUIRED_FIELDS, so a span it builds is always
adoptable by CompletionSpanBuilder::build and can absorb every field
recorded over the completion’s lifetime. Runtimes should declare their
completion-parent spans through it rather than hand-writing the marker and
field list — tracing::Span::record silently no-ops on undeclared
fields, so a hand-written span that omits one field loses that telemetry
with no error (and a span that omits enough to fail the adoption gate is
not adopted at all). A span declared through this macro tracks the contract
automatically; a hand-written one has to be maintained by hand.
By default the span is explicitly parented on
tracing::Span::current(); pass parent: <expr> between target and
name to override it with any parent expression tracing::info_span!
accepts (including None). operation and system_instructions are
declared with the given values; the provider records
gen_ai.provider.name and gen_ai.request.model at adoption time.
Additional runtime-specific fields may be appended after the named
arguments. Extra fields must not repeat the marker or a required contract
field: a duplicate compiles, but the span then declares two same-named
fields and tracing::Span::record targets only the first.
Invoking this macro does not require a direct tracing dependency. To
declare a field with no value yet, use Empty (re-exported here for
exactly this reason) or Option::<&str>::None; tracing::field::Empty
itself is the same type but only nameable by a crate that depends on
tracing directly.
§Examples
use rig_core::telemetry::completion_parent_span;
let span = completion_parent_span!(
target: "my_runtime",
name: "chat",
operation: "chat",
system_instructions: Option::<&str>::None,
gen_ai.agent.name = "assistant",
);