#12072·cube

Trino/Presto driver: tag queries with requestId, like BigQuery and ClickHouse

Author: natalieschauserCreated Sep 30, 2026Updated Sep 30, 2026

Is your feature request related to a problem? Please describe.

Cube passes each query's requestId to the driver so the driver can tag the query it sends to the database. The driver interface says so directly (driver.interface.ts#L135):

Cube request identifier, forwarded so drivers can tag the underlying database job/query for tracing (e.g. BigQuery job labels).

The orchestrator passes it through: client.query(req.query, req.values, req) for queries and stream(..., { requestId }) for pre-aggregation builds. Two drivers already use it:

The Presto/Trino driver drops it:

So there's no way to trace a Trino query back to the Cube request that issued it. For example, when Cube runs behind an APM-instrumented service, the incoming W3C traceparent becomes the requestId, but it stops at the driver, so Trino query logs and event-listener data can't be joined back to the originating trace.

Describe the solution you'd like

Do what BigQuery and ClickHouse do: when requestId is present, attach it to the Trino query.

  1. Pass options from query() and stream() into queryPromised().
  2. In queryPromised(), merge a per-query header into the headers passed to client.execute(), on top of config.headers:
    typescript
    headers: { ...this.config.headers, ...this.requestIdHeaders(options) },
  3. requestIdHeaders(options) returns { 'X-Trino-Trace-Token': <id> }, or X-Presto-Trace-Token for the presto engine. As in the BigQuery and ClickHouse drivers, <id> is extractRequestUUID(requestId) from @cubejs-backend/shared, so all sub-queries of one request share an ID. The value should also be limited to header-safe characters and a sensible length. requestId can come from a client-supplied x-request-id, and an invalid header value makes Node throw, which would fail the query.

TrinoDriver extends PrestoDriver, so this one change covers both engines. Only the initial POST /v1/statement needs the header. Trino records it on the query when the query is created, so the nextUri polls don't need it.