Skip to main content
Get traces from watsonx Orchestrate and export their observations by using a Python script.

References

Classes

Use these classes to handle trace data in the watsonx Orchestrate platform.
Import example
Use TracesController to access trace operations programmatically in the watsonx Orchestrate observability platform. It exposes methods to search, fetch, and export traces, with optional pagination and CLI-oriented progress logging.

Methods

get_client(self) -> TracesClient

Return the underlying TracesClient, creating it if necessary.Returns:
An authenticated client bound to the active environment.

fetch_trace_observations(self, trace_id: str, page_size: int = 100, fetch_all: bool = True, show_progress: bool = False) -> ObservationsExportResponse

Fetch all observations for a specific trace ID.Parameters:
string
A trace ID.
int
Number of observations per page (1–1000). Default is 100.
bool
When True, retrieves observations across all pages automatically. Default is True.
bool
When True, logs progress through the logger. Default is False.
Returns:
Contains observations (list of Observation objects), totalCount, page, and totalPages.

export_trace_to_json(self, trace_id: str, output_file: Optional[str] = None, pretty: bool = True, page_size: int = 50) -> tuple[ObservationsExportResponse, str]

Fetch observations for a trace ID and serialize them to JSON. Optionally writes the output to a file.Parameters:
string
A trace ID.
string (optional)
A file path for the JSON output. When None, JSON is returned as a string only. Default is None.
bool
Indented JSON for readability. Default is True.
int
Number of observations per page. Default is 50.
Returns:
  • ObservationsExportResponse: The observations fetched, for programmatic use.
  • string: The JSON output, suitable for display or storage.

search_traces(self, filters: Optional[TraceFilters] = None, sort: Optional[TraceSort] = None, page_size: int = 100, show_progress: bool = False) -> TraceSearchResponse

Search for traces using optional filters and sort options.Parameters:
TraceFilters (optional)
Search criteria. Supported fields:
  • start_time — ISO 8601 string or datetime
  • end_time — ISO 8601 string or datetime
  • user_ids — list of user IDs (only the first value is used by the API)
  • session_ids — list of session IDs (only the first value is used by the API)
Default is None (returns all traces up to page_size).
TraceSort (optional)
Sorting options. Use field="start_time" and direction="asc" or direction="desc". The values "start_time" and "end_time" both map to "timestamp" at the API level. Default is None.
int
Results per page (1–1000). Default is 100.
bool
When True, logs progress messages via logger. Default is False.
Returns:
Contains traces (list of TraceItem), traceSummaries, totalCount, and meta (pagination).

Models

Use these models and the client to work with trace data in the watsonx Orchestrate platform.
Import example
Represents a single recorded step within a trace. The API returns this object from GET /v1/agentops-v3/observations.Attributes
string
Observation ID.
string
Parent trace ID.
string
Observation type, for example GENERATION.
string
Observation name.
string
Start time (ISO 8601).
string | None
End time (ISO 8601). May be None for in-progress observations.
string | None
LLM model used, if applicable.
dict | list | string | None
Input data passed to the operation.
dict | list | string | None
Output data returned from the operation.
dict | None
Arbitrary metadata.
dict | None
Token usage statistics.
The response object that fetch_trace_observations() and export_trace_to_json() return.Attributes
list[Observation] | None
List of observations for the trace.
int | None
Total number of observations reported by the API. Also accessible as the total_count property.
int | None
Current page number.
int | None
Total number of pages.
Represents a single trace entry. The API returns this object from GET /v1/agentops-v3/traces.Attributes
string
Trace ID.
string | None
Trace name.
string
Trace start time (ISO 8601).
string | None
Session ID associated with the trace.
string | None
User ID associated with the trace.
list[string] | None
Tags attached to the trace.
float | None
Trace duration in seconds.
dict | list | string | None
Input data for the trace.
dict | list | string | None
Output data for the trace.
dict | None
Arbitrary metadata.
Defines search criteria for trace queries. All fields are optional.Attributes
string | datetime
Start of the time range. Accepts an ISO 8601 string or a Python datetime object.
string | datetime
End of the time range. Accepts an ISO 8601 string or a Python datetime object.
list[string]
Filter by user ID. Only the first value in the list is sent to the API.
list[string]
Filter by session ID. Only the first value in the list is sent to the API.
Defines sort options for trace search queries.Attributes
string
Field to sort by. Use "timestamp". The values "start_time" and "end_time" are also accepted and map to "timestamp".
string
Sort direction: "asc" or "desc".
Provides summary data for a trace. The TraceSearchResponse.traceSummaries list contains these objects.Attributes
string
Trace ID.
string
Trace start time (ISO 8601).
Note:The agentops-v3 API does not return separate start and end times for agent traces. Both startTime and endTime are populated from the same timestamp field returned by the API. Dedicated start/end time values may become available in a future API update.
string
Trace end time (ISO 8601).
Note:The agentops-v3 API does not return separate start and end times for agent traces. Both startTime and endTime are populated from the same timestamp field returned by the API. Dedicated start/end time values may become available in a future API update.
float
Trace duration in milliseconds.
list[string] | None
Agent IDs extracted from trace metadata.
list[string] | None
Agent names extracted from trace metadata.
list[string] | None
User IDs associated with the trace.
list[string] | None
Session IDs associated with the trace.
The response object that search_traces() returns.Attributes
list[TraceItem] | None
List of trace items from the agentops-v3 API.
list[TraceSummary]
Summary view of each trace, derived from the trace items.
int | None
Total number of matching traces.
PaginationMeta | None
Pagination metadata.
string
Time the response object was created.
object
The query parameters that were sent to the API.
Pagination metadata that API responses include.Attributes
int
Current page number.
int
Items per page.
int
Total number of items across all pages.
int
Total number of pages.