nat.data_models.span#

Attributes#

Classes#

SpanKind

Kinds of spans emitted by NAT telemetry.

SpanAttributes

Standard attribute keys used on NAT spans.

MimeTypes

MIME types used for span input and output payloads.

SpanStatusCode

Status codes used to describe span completion state.

SpanEvent

SpanStatus

SpanContext

Span

Functions#

event_type_to_span_kind(→ SpanKind)

Convert an event type to a span kind.

_generate_nonzero_trace_id(→ int)

Generate a non-zero 128-bit trace ID.

_generate_nonzero_span_id(→ int)

Generate a non-zero 64-bit span ID.

Module Contents#

logger#
_SPAN_PREFIX#
class SpanKind(*args, \*\*kwds)#

Bases: enum.Enum

Kinds of spans emitted by NAT telemetry.

LLM = 'LLM'#
TOOL = 'TOOL'#
WORKFLOW = 'WORKFLOW'#
TASK = 'TASK'#
FUNCTION = 'FUNCTION'#
CUSTOM = 'CUSTOM'#
SPAN = 'SPAN'#
EMBEDDER = 'EMBEDDER'#
RETRIEVER = 'RETRIEVER'#
AGENT = 'AGENT'#
RERANKER = 'RERANKER'#
GUARDRAIL = 'GUARDRAIL'#
EVALUATOR = 'EVALUATOR'#
UNKNOWN = 'UNKNOWN'#
EVENT_TYPE_TO_SPAN_KIND_MAP#
event_type_to_span_kind(event_type: str) SpanKind#

Convert an event type to a span kind.

Args:

event_type (str): The event type to convert.

Returns:

SpanKind: The span kind.

class SpanAttributes(*args, \*\*kwds)#

Bases: enum.Enum

Standard attribute keys used on NAT spans.

NAT_SPAN_KIND#
INPUT_VALUE = 'input.value'#
INPUT_MIME_TYPE = 'input.mime_type'#
LLM_MODEL_NAME = 'llm.model_name'#
LLM_PROVIDER = 'llm.provider'#
LLM_TOKEN_COUNT_PROMPT = 'llm.token_count.prompt'#
LLM_TOKEN_COUNT_COMPLETION = 'llm.token_count.completion'#
LLM_TOKEN_COUNT_TOTAL = 'llm.token_count.total'#
OUTPUT_VALUE = 'output.value'#
OUTPUT_MIME_TYPE = 'output.mime_type'#
NAT_USAGE_NUM_LLM_CALLS#
NAT_USAGE_SECONDS_BETWEEN_CALLS#
NAT_USAGE_TOKEN_COUNT_PROMPT#
NAT_USAGE_TOKEN_COUNT_COMPLETION#
NAT_USAGE_TOKEN_COUNT_TOTAL#
NAT_EVENT_TYPE#
class MimeTypes(*args, \*\*kwds)#

Bases: enum.Enum

MIME types used for span input and output payloads.

TEXT = 'text/plain'#
JSON = 'application/json'#
class SpanStatusCode(*args, \*\*kwds)#

Bases: enum.Enum

Status codes used to describe span completion state.

OK = 'OK'#
ERROR = 'ERROR'#
UNSET = 'UNSET'#
class SpanEvent(/, **data: Any)#

Bases: pydantic.BaseModel

timestamp: float = None#
name: str = None#
attributes: dict[str, Any] = None#
class SpanStatus(/, **data: Any)#

Bases: pydantic.BaseModel

code: SpanStatusCode = None#
message: str | None = None#
_generate_nonzero_trace_id() int#

Generate a non-zero 128-bit trace ID.

_generate_nonzero_span_id() int#

Generate a non-zero 64-bit span ID.

class SpanContext(/, **data: Any)#

Bases: pydantic.BaseModel

trace_id: int = None#
span_id: int = None#
classmethod _validate_trace_id(v: int | str | None) int#

Regenerate if trace_id is None; raise an exception if trace_id is invalid;

classmethod _validate_span_id(v: int | str | None) int#

Regenerate if span_id is None; raise an exception if span_id is invalid;

class Span(/, **data: Any)#

Bases: pydantic.BaseModel

name: str = None#
context: SpanContext | None = None#
parent: Span | None = None#
start_time: int = None#
end_time: int | None = None#
attributes: dict[str, Any] = None#
events: list[SpanEvent] = None#
status: SpanStatus = None#
classmethod set_default_context(v: SpanContext | None) SpanContext#

Set the default context if the context is not provided.

Args:

v (SpanContext | None): The context to set.

Returns:

SpanContext: The context.

set_attribute(key: str, value: Any) None#

Set the attribute of the span.

Args:

key (str): The key of the attribute. value (Any): The value of the attribute.

add_event(name: str, attributes: dict[str, Any] | None = None) None#

Add an event to the span.

Args:

name (str): The name of the event. attributes (dict[str, Any] | None): The attributes of the event.

end(end_time: int | None = None) None#

End the span.

Args:

end_time (int | None): The end time of the span.