Skip to main content
Quickstart: For a simple end-to-end example, check the Tutorial.

Installation

Install the tracely package from PyPi:

Initialize tracing

You must first connect to Evidently Cloud and create a Project.
To start sending traces, use init_tracing:
You can also set parameters using environment variables with the specified names.

init_tracing() Function Arguments

Tracing dataset ID

To get the export_id of the tracing dataset, run:
You can use the export_id as a dataset id for download. See datasets API.

Decorator

Once Tracely is initialized, you can decorate your functions with trace_event to start collecting traces for a specific function:
You can also specify which function arguments should be included in the trace. Example 1. To log all arguments of the function:
Example 2. To log only input arguments of the function:
Example 3. To log only “arg1” and “arg2”:

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:
This results in the following trace structure:

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:
You can also trace multi-step workflows using context blocks. This gives you fine-grained control — useful when tracing inline code or scripts. For example, you can nest multiple 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 shared session_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 use get_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 using tracely.bind_to_trace:
In this example, instead of creating a new trace ID for each event, all events will be attached to the existing trace with the given trace_id.
In this case you manage the trace_id yourself, so you need to make sure it’s truly unique. If you reuse the same trace_id, all events will be joined, even if they don’t belong together.