Query Builder

Extra columns that are selected in the query can be viewed in the expanded log row:

### Time series[​](#time-series "Direct link to Time series")

The time series query type is similar to [table](#table), but with a focus on time series data.

The two views are mostly the same, with these notable differences:

- A dedicated *Time* field.
- In Aggregate mode, a time interval macro is automatically applied along with a Group By for the Time field.
- In Aggregate mode, the "Columns" field is hidden.
- A time range filter and Order By are automatically added for the **Time** field.

Is your visualization missing data?

In some cases the time series panel will appear to be cut off because the limit defaults to `1000`.

Try removing the `LIMIT` clause by setting it to `0` (if your dataset allows).

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Field Description|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Builder Mode Simple queries exclude Aggregates and Group By, while aggregate queries include these options.|  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Time The primary time column for the query. Will display time-like types, but allows for custom values/functions.|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Columns The selected columns. Raw SQL can be typed into this field to allow for functions and column aliasing. Only visible in Simple mode.|  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Aggregates A list of [aggregate functions](/docs/sql-reference/aggregate-functions). Allows for custom values for function and column. Only visible in Aggregate mode.| Group By A list of [GROUP BY](/docs/sql-reference/statements/select/group-by) expressions. Only visible in Aggregate mode.| Order By A list of [ORDER BY](/docs/sql-reference/statements/select/order-by) expressions.| Limit Appends a [LIMIT](/docs/sql-reference/statements/select/limit) statement to the end of the query. If set to `0` then it will be excluded, this is recommended for some time series datasets in order to show the full visualization.| Filters A list of filters to be applied in the `WHERE` clause. | | | | | | | | | | | | | | | | | |

This query type will render the data with the time series panel.

### Traces[​](#traces "Direct link to Traces")

The trace query type offers a query builder for easily searching and viewing traces.
It is designed for OpenTelemetry data, but columns can be selected to render traces from a different schema.
Defaults can be configured in the data source's [trace configuration](/docs/integrations/grafana/config#traces) to allow the query builder to be pre-loaded with a default database/table and columns. If defaults are configured, the column selection will be collapsed by default.
OpenTelemetry can also be enabled to auto select the columns according to a schema version.

Default filters are added with the intent to show only top level spans.
An Order By for the Time and Duration Time columns is also included.
These filters are tied to their respective fields, and will update as the columns are changed.
The **Service Name** filter is excluded from the SQL by default, changing it from the `IS ANYTHING` option will enable it.

The trace query type supports [data links](#data-links).

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Field Description|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Trace Mode Changes the query from Trace Search to Trace ID lookup.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Use OTel Enables OpenTelemetry columns. Will overwrite the selected columns to use columns defined by the selected OTel schema version (Disables column selection).|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Trace ID Column The trace's ID.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Span ID Column Span ID.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Parent Span ID Column Parent span ID. This is usually empty for top level traces.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Service Name Column Service name.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Operation Name Column Operation name.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Start Time Column The primary time column for the trace span. The time when the span started.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Duration Time Column The duration of the span. By default Grafana expects this to be a float in milliseconds. A conversion is automatically applied via the `Duration Unit` dropdown.| Duration Unit The unit of time used for the duration. Nanoseconds by default. The selected unit will be converted to a float in milliseconds as required by Grafana.|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Tags Column Span Tags. Exclude this if not using an OTel based schema as it expects a specific Map column type.|  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Service Tags Column Service Tags. Exclude this if not using an OTel based schema as it expects a specific Map column type.|  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | | Order By A list of [ORDER BY](/docs/sql-reference/statements/select/order-by) expressions.| Limit Appends a [LIMIT](/docs/sql-reference/statements/select/limit) statement to the end of the query. If set to `0` then it will be excluded, but this isn't recommended for large trace datasets.| Filters A list of filters to be applied in the `WHERE` clause.| Trace ID The Trace ID to filter by. Only used in Trace ID mode, and when opening a trace ID [data link](#data-links). | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

This query type will render the data with the table view for Trace Search mode, and the trace panel for Trace ID mode.

## SQL editor[​](#sql-editor "Direct link to SQL editor")