References
Classes
Use these classes to handle trace data in the watsonx Orchestrate platform.Import example
TracesController
TracesController
A controller that provides programmatic access to trace operations in Watson Orchestrate’s observability platform.
Includes methods to search, fetch, and export traces, with optional pagination and CLI‑oriented progress logging.Returns:Returns:Returns:
Methods
get_client(self) -> TracesClient
Return the underlying TracesClient, creating it if necessary.Returns:TracesClient
An authenticated client bound to the active environment.
fetch_trace_spans(self, trace_id: str, page_size: int = 100, fetch_all: bool = True, show_progress: bool = False) -> SpansResponse
Fetch spans for a specific trace IDParameters:A 32‑character hexadecimal trace ID.
Number of spans per page (1–1000). Default is
100.When True, retrieves spans across all pages. Default is
True.When True, logs progress through the logger. Default is
False.SpansResponse
Contains spans and paging metadata. Depending on the platform:
- Legacy: spans_response.spans (list of span objects) with total_count.
- New (OTLP-style): spans_response.traceData.resourceSpans with scopeSpans[..].spans[..] (dicts).
export_trace_to_json(self, trace_id: str, output_file: Optional[str] = None, pretty: bool = True, page_size: int = 50) -> tuple[SpansResponse, str]
Fetch spans for a trace ID and export the data in JSON format. Uses TraceExporter for serialization and optionally writes to a file.Parameters:A 32‑character hexadecimal trace ID.
A file path for the JSON output. When None, JSON is returned as a string only. Default is
None.Indented JSON for readability. Default is
True.Number of spans per page. Default is
50.tuple
- SpansResponse: The spans fetched for programmatic use.
- string: The JSON output, suitable for CLI display or storage.
search_traces(self, filters: Optional[TraceFilters] = None, sort: Optional[TraceSort] = None, page_size: int = 50, include_root_spans: bool = False, fetch_all: bool = True, show_progress: bool = False) -> TraceSearchResponse
Search traces using optional time filters and additional criteria such as service metadata, IDs, or span count ranges. Supports embedding root‑span data to quickly inspect error‑related attributes.Parameters:Search criteria. Typically includes a time window:
- start_time (str, RFC 3339 with Z)
- end_time (str, RFC 3339 with Z) Optional fields:
- service_names
- agent_ids
- agent_names
- user_ids
- session_ids
- SpanCountRange
Default is
None.
Sorting options (e.g., field=“start_time”, direction=“desc”).
Default is
None.Results per page (1–100). Default is
100.If True, embeds root span data in summaries (useful for filtering error traces by root_span.status.code).
Default is
False.If True, logs progress messages via logger.
Default is
False.TraceSearchResponse
Contains traceSummaries and pagination details. Field names may vary depending on the model;
traceSummaries is the typical structure.Models
Use these models and the client to work with trace data in the watsonx Orchestrate platform.Import example
SpanContext
SpanContext
SpanStatus
SpanStatus
SpanEvent
SpanEvent
Span
Span
OpenTelemetry‑compliant span object.Attributes
Human-readable operation name.
Trace and span identifiers.
Parent span ID; None for root spans.
Span kind such as INTERNAL, SERVER, or CLIENT.
ISO 8601 timestamp in UTC.
ISO 8601 timestamp in UTC.
Execution status.
Arbitrary key-value attributes.
Events recorded during the span.
TraceData
TraceData
Trace data containing resource spans.Attributes
OpenTelemetry‑style structure, such as resourceSpans[].scopeSpans[].spans[*].
SpansResponse
SpansResponse
Response from the get spans API. Supports two response shapes:
- Structured: traceData.resourceSpans, an OpenTelemetry‑style grouping
- Legacy: a flat spans array with pagination metadata
Structured trace data.
Legacy spans array.
Pagination cursor using the internal camelCase field name.
Reported total number of spans, using the internal camelCase field name.
SpanCountRange
SpanCountRange
Range used to filter traces by their span count.
TraceFilters
TraceFilters
Filters used to search traces.Accepts ISO 8601 strings or Python datetime objects.
A field serializer converts datetime values to strings with a trailing Z.Attributes
A field serializer converts datetime values to strings with a trailing Z.Attributes
Start time for filtering.
End time for filtering.
Service name filter. Supports multiple values and can be specified multiple times.
Agent ID filter. Allows selecting multiple agent identifiers and can be repeated as needed.
Agent name filter. Accepts several agent names and may be provided multiple times.
User ID filter. Supports filtering by one or more user identifiers, with repeatable entries.
Session ID filter. Enables filtering by multiple session identifiers and can be included multiple times.
Thresholds for minimum and maximum span counts.
TraceSort
TraceSort
Sort configuration for trace searches.
TraceSearchRequest
TraceSearchRequest
Request body used to search traces.
RootSpanStatus
RootSpanStatus
Status found in the root span, which may differ from the SpanStatus schema.
RootSpan
RootSpan
Root‑span data included in a trace summary.
TraceSummary
TraceSummary
Summary data for a trace.

