Skip to main content

Module telemetry

Module telemetry 

Source
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> between target and name accepts any parent supported by tracing::info_span!, including None.

Structs§

Empty
Declares a span field without a value, including in completion_parent_span!. An empty field.
SpanBuilder
Builder for a canonical GenAI span.

Enums§

GenAiOperation
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_FIELD for adoption. Each must be statically declared with Empty or 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§

SpanCombinator
Records GenAI usage and response metadata on tracing spans.

Functions§

record_model_input
Records serialized model input messages on gen_ai.input.messages when content telemetry is explicitly enabled.
record_model_output
Records serialized model output messages on gen_ai.output.messages when content telemetry is explicitly enabled.
system_instructions_json
Serializes system instructions using the normalized GenAI telemetry shape.