Skip to main content
This guide describes how to use the unomiq-sdk Python package to query the Unomiq Economic Engine API — the API that lets you search traces, retrieve aggregated metrics, list traces, and inspect individual spans.

Prerequisites

API Credentials

Create API credentials from the Unomiq Dashboard. The credentials must have the read:traces permission. This will give you an API key (Client ID) and secret (Client Secret).

Application ID

You need the Application ID (app_id) for the application whose traces you want to query. You can find this in the Unomiq Dashboard under your application settings.

Install the SDK


Configuration

Set the following environment variables for your application: The SDK uses these credentials internally to acquire and refresh OAuth2 tokens when making requests to the Engine API. Alternatively, you can pass credentials directly to the constructor:

Constructor Parameters


Initializing the Client

Using environment variables (recommended):
Remember to call engine.close() when you are done to release resources.

Querying Spans

The engine/query endpoint lets you search for individual spans across traces using filter expressions.
The response includes paginated span data along with the total count of matching results.

Filter Expressions

The SDK provides composable filter primitives — Condition, AndGroup, and OrGroup — that map directly to the Engine API filter schema. These can be used with engine.query(), engine.get_traces(), and engine.get_metrics().

Simple Condition

A Condition matches a single field against a value using a comparison operator:

Supported Operators

Filterable Fields

Combining Conditions with AND / OR

Use AndGroup and OrGroup to build complex filter expressions:
Groups can be nested arbitrarily to express any boolean logic.

Listing Traces

The /traces endpoint returns a paginated list of traces with aggregated information (duration, span count, total cost).
By default, filters apply only to root spans. Set search_child_spans=True to apply filters across all spans in the trace:

Retrieving a Single Trace

The /traces/{trace_id} endpoint returns all spans for a specific trace:

Getting Metrics

The /engine/metrics endpoint returns aggregated statistical distributions for trace duration, cost, and spans per trace.
You can pass the same filter expressions to narrow down the metrics:
The response includes distribution statistics (mean, median, p50, p90, p95, p99, min, max, stddev) for each metric.

Live Traces

The /traces/live endpoint returns the most recent spans from the live data stream:

Cleanup

Always close the engine client when you are done to release the underlying HTTP connection and OAuth2 token manager:

Full Example

Here is a complete example that initializes the client, queries spans, retrieves metrics, and lists traces: