nat.data_models.span#

Attributes#

Classes#

SpanKind

Create a collection of name/value pairs.

SpanAttributes

Create a collection of name/value pairs.

MimeTypes

Create a collection of name/value pairs.

SpanStatusCode

Create a collection of name/value pairs.

SpanEvent

SpanStatus

SpanContext

Span

Functions#

event_type_to_span_kind(→ SpanKind)

Convert an event type to a span kind.

Module Contents#

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

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

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

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NAT_SPAN_KIND = 'Uninferable.span.kind'#
INPUT_VALUE = 'input.value'#
INPUT_MIME_TYPE = 'input.mime_type'#
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 = 'Uninferable.usage.num_llm_calls'#
NAT_USAGE_SECONDS_BETWEEN_CALLS = 'Uninferable.usage.seconds_between_calls'#
NAT_USAGE_TOKEN_COUNT_PROMPT = 'Uninferable.usage.token_count.prompt'#
NAT_USAGE_TOKEN_COUNT_COMPLETION = 'Uninferable.usage.token_count.completion'#
NAT_USAGE_TOKEN_COUNT_TOTAL = 'Uninferable.usage.token_count.total'#
NAT_EVENT_TYPE = 'Uninferable.event_type'#
class MimeTypes(*args, **kwds)#

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

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

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

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#
class SpanContext(/, **data: Any)#

Bases: pydantic.BaseModel

trace_id: int = None#
span_id: int = None#
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.