Skip to content

trulens.core.schema.record

trulens.core.schema.record

Serializable record-related classes.

Classes

RecordAppCallMethod

Bases: SerialModel

Method information for the stacks inside RecordAppCall.

Attributes
path instance-attribute
path: Lens

Path to the method in the app's structure.

method instance-attribute
method: Method

The method that was called.

Functions
__rich_repr__
__rich_repr__() -> Result

Requirement for pretty printing using the rich package.

RecordAppCall

Bases: SerialModel

Info regarding each instrumented method call.

Attributes
call_id class-attribute instance-attribute
call_id: CallID = Field(default_factory=new_call_id)

Unique identifier for this call.

This is shared across different instances of RecordAppCall if they refer to the same python method call. This may happen if multiple recorders capture the call in which case they will each have a different RecordAppCall but the call_id will be the same.

stack instance-attribute

Call stack but only containing paths of instrumented apps/other objects.

args instance-attribute
args: JSON

Arguments to the instrumented method.

rets class-attribute instance-attribute
rets: Optional[JSON] = None

Returns of the instrumented method if successful.

Sometimes this is a dict, sometimes a sequence, and sometimes a base value.

error class-attribute instance-attribute
error: Optional[str] = None

Error message if call raised exception.

perf class-attribute instance-attribute
perf: Optional[Perf] = None

Timestamps tracking entrance and exit of the instrumented method.

pid instance-attribute
pid: int

Process id.

tid instance-attribute
tid: int

Thread id.

top property

The top of the stack.

method property
method: Method

The method at the top of the stack.

Functions
__rich_repr__
__rich_repr__() -> Result

Requirement for pretty printing using the rich package.

Record

Bases: SerialModel, Hashable

The record of a single main method call.

Note

This class will be renamed to Trace in the future.

Attributes
app_id instance-attribute
app_id: AppID

The app that produced this record.

cost class-attribute instance-attribute
cost: Optional[Cost] = None

Costs associated with the record.

perf class-attribute instance-attribute
perf: Optional[Perf] = None

Performance information.

ts class-attribute instance-attribute
ts: datetime = Field(default_factory=now)

Timestamp of last update.

This is usually set whenever a record is changed in any way.

tags class-attribute instance-attribute
tags: Optional[str] = ''

Tags for the record.

meta class-attribute instance-attribute
meta: Optional[JSON] = None

Metadata for the record.

main_input class-attribute instance-attribute
main_input: Optional[JSON] = None

The app's main input.

main_output class-attribute instance-attribute
main_output: Optional[JSON] = None

The app's main output if there was no error.

main_error class-attribute instance-attribute
main_error: Optional[JSON] = None

The app's main error if there was an error.

calls class-attribute instance-attribute
calls: List[RecordAppCall] = []

The collection of calls recorded.

Note that these can be converted into a json structure with the same paths as the app that generated this record via layout_calls_as_app.

Invariant: calls are ordered by .perf.end_time.

experimental_otel_spans class-attribute instance-attribute
experimental_otel_spans: List[Any] = []

EXPERIMENTAL(otel-tracing): OTEL spans representation of this record.

This will be filled in only if the otel-tracing experimental feature is enabled.

feedback_and_future_results class-attribute instance-attribute
feedback_and_future_results: Optional[
    List[Tuple[FeedbackDefinition, Future[FeedbackResult]]]
] = Field(None, exclude=True)

Map of feedbacks to the futures for of their results.

These are only filled for records that were just produced. This will not be filled in when read from database. Also, will not fill in when using FeedbackMode.DEFERRED.

feedback_results class-attribute instance-attribute
feedback_results: Optional[List[Future[FeedbackResult]]] = (
    Field(None, exclude=True)
)

Only the futures part of the above for backwards compatibility.

feedback_results_as_completed property
feedback_results_as_completed: Iterable[FeedbackResult]

Generate feedback results as they are completed.

Wraps feedback_results in as_completed.

record_id instance-attribute
record_id: RecordID = record_id

Unique identifier for this record.

Functions
__rich_repr__
__rich_repr__() -> Result

Requirement for pretty printing using the rich package.

wait_for_feedback_results
wait_for_feedback_results(
    feedback_timeout: Optional[float] = None,
) -> Dict[FeedbackDefinition, FeedbackResult]

Wait for feedback results to finish.

PARAMETER DESCRIPTION
feedback_timeout

Timeout in seconds for each feedback function. If not given, will use the default timeout trulens.core.utils.threading.TP.DEBUG_TIMEOUT.

TYPE: Optional[float] DEFAULT: None

RETURNS DESCRIPTION
Dict[FeedbackDefinition, FeedbackResult]

A mapping of feedback functions to their results.

get
get(path: Lens) -> Optional[T]

Get a value from the record using a path.

PARAMETER DESCRIPTION
path

Path to the value.

TYPE: Lens

layout_calls_as_app
layout_calls_as_app() -> Munch

Layout the calls in this record into the structure that follows that of the app that created this record.

This uses the paths stored in each RecordAppCall which are paths into the app.

Note: We cannot create a validated AppDefinition class (or subclass) object here as the layout of records differ in these ways:

  • Records do not include anything that is not an instrumented method hence have most of the structure of a app missing.

  • Records have RecordAppCall as their leafs where method definitions would be in the AppDefinition structure.