Trace API Payload Model

The SigNoz Trace API uses a JSON payload for queries, which includes various fields and nested fields. This document provides a detailed explanation of each field to help users construct effective queries.

Top-level

The top-level of the payload model has the following fields:

NAMEDESCRIPTION
startEpoch timestamp marking the start of the query range (in milliseconds)
endEpoch timestamp marking the end of the query range (in milliseconds)
requestTypeType of response expected (e.g., time_series, scalar, raw, trace)
compositeQueryThis contains the compositeQuery which is explained below
variablesMap of variables used in the query (optional)

Composite Query

The compositeQuery field consists of:

NAMEDESCRIPTION
queriesArray of query envelopes

Query Envelope

Each query in the queries array consists of:

NAMEDESCRIPTION
typeType of query (e.g., builder_query, clickhouse_sql, promql). Scope of this documentation is limited to builder_query and clickhouse_sql types
specQuery specification based on type - contains the builderQuery for builder_query type or chQuery for clickhouse_sql type

Builder Query

A builderQuery spec consists of:

NAMEDESCRIPTION
nameName of the query (e.g., A, B, C)
signalSource of data (e.g., traces)
stepIntervalAggregation interval for query in seconds
aggregationsArray of aggregation expressions
filterfilter expression for filtering data
selectFieldsArray of selectField which is used in raw/trace requestType to fetch columns/attributes
groupByArray of groupByKey used for groupBy
orderArray of orderBy used for ordering data
havinghaving expression used for filtering data after aggregation
disabledSpecifies if the query is disabled
limitLimit number of results
offsetOffset used in pagination

Ch Query

A chQuery spec consists of:

NAMEDESCRIPTION
nameName of the query (e.g., A, B, C)
queryClickhouse query
disabledWhether the query is disabled

Aggregation

An aggregation consists of:

NAMEDESCRIPTION
expressionAggregation expression - count(), count_distinct(field), sum(field), avg(field), min(field), max(field), p50(field), p75(field), p90(field), p95(field), p99(field), rate(field)
aliasOptional alias for the aggregation result

Filter

A filter consists of:

NAMEDESCRIPTION
expressionFilter expression string using operators like =, !=, >, >=, <, <=, IN, NOT IN, CONTAINS, NOT CONTAINS, REGEXP, NOT REGEXP, EXISTS, NOT EXISTS

Select Field

A selectField consists of:

NAMEDESCRIPTION
nameName of the field
fieldDataTypeData type of the field (e.g., string, int64, float64, bool)
fieldContextType of the field, i.e., attribute/resource.

GroupBy Key

The groupByKey includes:

NAMEDESCRIPTION
nameName of the field
fieldDataTypeData type of the field (e.g., string, int64, float64, bool)
fieldContextType of the field, i.e., attribute/resource

Order By

An orderBy consists of:

NAMEDESCRIPTION
keyObject containing the field name to order by
directionSort direction (asc, desc)

Having

A having consists of:

NAMEDESCRIPTION
expressionHaving expression (e.g., "count() > 100", "avg_duration > 1000")

Sample Payload

For builderQuery with table requestType

This sample payload contains the different fields that we looked at above. It queries the SigNoz Trace API and illustrates how to count errors and group them by serviceName where hasError is true.

{
    "start": 1702007766000,
    "end": 1702009566000,
    "requestType": "time_series",
    "variables": {},
    "compositeQuery": {
        "queries": [
            {
                "type": "builder_query",
                "spec": {
                    "name": "A",
                    "signal": "traces",
                    "stepInterval": 60,
                    "aggregations": [
                        {
                            "expression": "count()",
                            "alias": "error_count"
                        }
                    ],
                    "filter": {
                        "expression": "hasError = true"
                    },
                    "groupBy": [
                        {
                            "name": "serviceName",
                        }
                    ],
                    "order": [
                        {
                            "key": {
                                "name": "error_count"
                            },
                            "direction": "desc"
                        }
                    ],
                    "disabled": false
                }
            }
        ]
    }
}

For chQuery

{
    "start": 1723644761000,
    "end": 1723646561000,
    "requestType": "scalar",
    "compositeQuery": {
        "queries": [
            {
                "type": "clickhouse_sql",
                "spec": {
                    "name": "A",
                    "query": "SELECT resource_string_service$$name AS `service.name`, toFloat64(avg(durationNano)) AS value FROM signoz_traces.distributed_signoz_index_v3 WHERE timestamp BETWEEN $start_datetime AND $end_datetime AND ts_bucket_start BETWEEN $start_timestamp - 1800 AND $end_timestamp GROUP BY (`service.name`) order by (`service.name`) ASC;",
                    "disabled": false
                }
            }
        ]
    }
}

Last updated: June 6, 2024

Edit on GitHub

Was this page helpful?