Quickstart: For a simple end-to-end example, check the Tutorial.
Installation
Install thetracely package from PyPi:
Initialize tracing
To start sending traces, useinit_tracing:
init_tracing() Function Arguments
Tracing dataset ID
To get theexport_id of the tracing dataset, run:
export_id as a dataset id for download. See datasets API.
Decorator
OnceTracely is initialized, you can decorate your functions with trace_event to start collecting traces for a specific function:
trace_event Decorator Arguments
Nested events (Spans)
Many LLM workflows involve multiple steps — such as retrieval followed by generation, or extraction followed by summarization. In these cases, it’s useful to trace all steps as part of a single parent trace, with each step recorded as a nested child span. You can trace multi-step workflows using the@trace_event decorator and nesting the functions. If a traced function is called inside another traced function, it will automatically appear as a nested child span, as long as it’s executed in the same call context (same thread).
For example:
Context manager
To create a trace event without using a decorator (e.g., for a specific piece of code), you can use the context manager:create_trace_event() calls inline inside the same function, using with blocks.
create_trace_event Function Arguments
event Object Methods
Sessions
If your trace events are created in separate functions or threads you can also pass a sharedsession_id. In this case traces will be separate but you can view the session in the UI to join them together - e.g. to read the chat conversation.
See the example above the “Context Manager” session.
Add event attributes
If you want to add a new attribute to an active event span, you can useget_current_span() to get access to the current span:
get_current_span() Object Methods
Connecting event into a trace
Sometimes events happen across different systems, but it’s helpful to link them all into a single trace. You can do this usingtracely.bind_to_trace:
trace_id.