Expand description
GenAI tracing spans, completion-parent adoption, and opt-in content recording.
use rig_core::telemetry::{GenAiOperation, SpanBuilder};
let span = SpanBuilder::new("provider", "model", GenAiOperation::Chat).build();Macros§
- completion_
parent_ span - Declares a completion-parent span with the marker and all required fields.
Defaults to the current span as parent. An optional
parent: <expr>betweentargetandnameaccepts any parent supported bytracing::info_span!, includingNone.
Structs§
- Empty
- Declares a span field without a value, including in
completion_parent_span!. An empty field. - Span
Builder - Builder for a canonical GenAI span.
Enums§
- GenAi
Operation - A GenAI operation and its canonical span name. Completion operations carry message content and may adopt a completion-parent span; the others record only usage and identity on a fresh span.
Constants§
- COMPLETION_
PARENT_ MARKER_ FIELD - Marker field for completion-parent adoption, independent of tracing target.
Its value is ignored. Adoption requires every field in
COMPLETION_PARENT_REQUIRED_FIELDS; otherwise the builder creates a child span and warns once per incomplete callsite. - COMPLETION_
PARENT_ REQUIRED_ FIELDS - Fields required alongside
COMPLETION_PARENT_MARKER_FIELDfor adoption. Each must be statically declared withEmptyor a value.completion_parent_span!declares the complete set. - PROVIDER_
REQUEST_ ID_ FIELD - Span field holding the provider’s transport request id (the request-id response header), recorded on success and on provider errors. GenAI semantic conventions define no attribute for it. Rig’s own completion spans declare it; it is not required of an adopted parent, which simply does not record it when undeclared.
Traits§
- Span
Combinator - Records GenAI usage and response metadata on tracing spans.
Functions§
- record_
model_ input - Records serialized model input messages on
gen_ai.input.messageswhen content telemetry is explicitly enabled. - record_
model_ output - Records serialized model output messages on
gen_ai.output.messageswhen content telemetry is explicitly enabled. - system_
instructions_ json - Serializes system instructions using the normalized GenAI telemetry shape.