Documentation

ClickHouse Adapter

Configure safe semantic and native ClickHouse queries with OpenTelemetry mappings — TypeScript and Python.

ClickHouse Adapter

ClickHouse compiles semantic queries into parameterized, read-only SQL and normalizes JSON responses into dataframes.

  • TypeScript: @openplait/adapter-clickhouse (full reference)
  • Python: openplait.adapters.ClickHouseAdapter (config + capabilities scaffold)

Configure

import { ClickHouseAdapter } from "@openplait/adapter-clickhouse";

const adapter = new ClickHouseAdapter({
  url: "https://clickhouse.example.com:8443",
  username: process.env.CLICKHOUSE_USER,
  password: process.env.CLICKHOUSE_PASSWORD,
  database: "observability",
  httpHeaders: { "X-ClickHouse-Quota": "product-api" },
  maxResultRows: 10_000,
  maxRowsToRead: 10_000_000,
  maxTimeRangeMs: 31 * 24 * 60 * 60 * 1_000,
  queryTimeoutMs: 30_000,
});

Default datasets

Logical datasetDefault table
otel.spansotel_traces
otel.logsotel_logs
otel.metrics.gaugeotel_metrics_gauge
otel.metrics.sumotel_metrics_sum
otel.metrics.histogramotel_metrics_histogram

Applications may supply additional allowlisted mappings through datasets. OpenLIT can opt into its preset without changing generic defaults:

import {
  ClickHouseAdapter,
  OPENLIT_CLICKHOUSE_DATASETS,
} from "@openplait/adapter-clickhouse";

const adapter = new ClickHouseAdapter({
  url: clickhouseUrl,
  datasets: [...OPENLIT_CLICKHOUSE_DATASETS],
});

Compile, inspect, execute

const compiled = await adapter.compile(query, {
  variables: { __from: fromIso, __to: toIso },
});

const explanation = await adapter.explain(query, {
  variables: { __from: fromIso, __to: toIso },
});

const result = await adapter.execute(compiled, {
  audit: { requestId: "request-6a1c", actorId: "user-42" },
});

await adapter.close();

Native SQL is disabled unless allowNativeQueries: true is set. Even then, queries are single-statement and read-only, parameters use ClickHouse bindings, and configured row, time, and read limits still apply.