ClickStack: Create Source
This endpoint is in beta. API contract is stable, and no breaking changes are expected in the future.
ClickStack: Creates a new source. The request body is a source object without the id field. If an id is sent anyway it is silently ignored (stripped before validation — the request is never rejected because of it). Granularity fields (materializedViews[].minGranularity and metadataMaterializedViews.granularity) accept the same short format the API returns (e.g. 5m, 15s, 1h, 1d).
curl --request POST \
--url https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": false,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": false
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
EOFimport requests
url = "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources"
payload = {
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": False,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": False
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Logs',
kind: 'log',
connection: '507f1f77bcf86cd799439012',
from: {databaseName: 'otel', tableName: 'otel_logs'},
defaultTableSelectExpression: 'Timestamp, ServiceName, SeverityText, Body',
timestampValueExpression: 'Timestamp',
id: '507f1f77bcf86cd799439011',
section: 'Billing',
disabled: false,
querySettings: [{setting: 'max_threads', value: '4'}],
filterSettings: {
databaseName: 'default',
tableName: 'otel_logs',
columns: [
{
name: 'ServiceName',
label: 'Service Name',
valueExpression: 'lower(service_name)',
allowAll: false
}
]
},
serviceNameExpression: 'ServiceName',
serviceVersionExpression: 'ResourceAttributes[\'service.version\']',
severityTextExpression: 'SeverityText',
severityNumberExpression: 'SeverityNumber',
bodyExpression: 'Body',
eventNameExpression: 'EventName',
eventAttributesExpression: 'LogAttributes',
resourceAttributesExpression: 'ResourceAttributes',
displayedTimestampValueExpression: 'TimestampTime',
orderByExpression: 'Timestamp DESC',
metricSourceId: '507f1f77bcf86cd799439013',
traceSourceId: '507f1f77bcf86cd799439014',
traceIdExpression: 'TraceId',
spanIdExpression: 'SpanId',
implicitColumnExpression: 'Body',
knownColumnsListExpression: 'Timestamp, Body, ServiceName',
rowKeyExpression: 'toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset',
useTextIndexForImplicitColumn: 'auto',
mapKeyIndexMaxParts: 20,
mapKeyIndexPartSelection: 'median',
highlightedTraceAttributeExpressions: [
{
sqlExpression: 'SpanAttributes[\'http.status_code\']',
luceneExpression: 'http.status_code',
alias: 'HTTP Status Code'
}
],
highlightedRowAttributeExpressions: [
{
sqlExpression: 'SpanAttributes[\'http.status_code\']',
luceneExpression: 'http.status_code',
alias: 'HTTP Status Code'
}
],
materializedViews: [
{
databaseName: 'otel',
tableName: 'otel_logs_mv_5m',
dimensionColumns: 'ServiceName, SeverityText',
minGranularity: '5m',
timestampColumn: 'Timestamp',
aggregatedColumns: [{aggFn: 'sum', mvColumn: 'sum__Duration', sourceColumn: 'Duration'}],
minDate: '2025-01-01T00:00:00Z'
}
],
metadataMaterializedViews: {
keyRollupTable: 'otel_logs_key_rollup_15m',
kvRollupTable: 'otel_logs_kv_rollup_15m',
granularity: '15m'
}
})
};
fetch('https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Logs',
'kind' => 'log',
'connection' => '507f1f77bcf86cd799439012',
'from' => [
'databaseName' => 'otel',
'tableName' => 'otel_logs'
],
'defaultTableSelectExpression' => 'Timestamp, ServiceName, SeverityText, Body',
'timestampValueExpression' => 'Timestamp',
'id' => '507f1f77bcf86cd799439011',
'section' => 'Billing',
'disabled' => false,
'querySettings' => [
[
'setting' => 'max_threads',
'value' => '4'
]
],
'filterSettings' => [
'databaseName' => 'default',
'tableName' => 'otel_logs',
'columns' => [
[
'name' => 'ServiceName',
'label' => 'Service Name',
'valueExpression' => 'lower(service_name)',
'allowAll' => false
]
]
],
'serviceNameExpression' => 'ServiceName',
'serviceVersionExpression' => 'ResourceAttributes[\'service.version\']',
'severityTextExpression' => 'SeverityText',
'severityNumberExpression' => 'SeverityNumber',
'bodyExpression' => 'Body',
'eventNameExpression' => 'EventName',
'eventAttributesExpression' => 'LogAttributes',
'resourceAttributesExpression' => 'ResourceAttributes',
'displayedTimestampValueExpression' => 'TimestampTime',
'orderByExpression' => 'Timestamp DESC',
'metricSourceId' => '507f1f77bcf86cd799439013',
'traceSourceId' => '507f1f77bcf86cd799439014',
'traceIdExpression' => 'TraceId',
'spanIdExpression' => 'SpanId',
'implicitColumnExpression' => 'Body',
'knownColumnsListExpression' => 'Timestamp, Body, ServiceName',
'rowKeyExpression' => 'toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset',
'useTextIndexForImplicitColumn' => 'auto',
'mapKeyIndexMaxParts' => 20,
'mapKeyIndexPartSelection' => 'median',
'highlightedTraceAttributeExpressions' => [
[
'sqlExpression' => 'SpanAttributes[\'http.status_code\']',
'luceneExpression' => 'http.status_code',
'alias' => 'HTTP Status Code'
]
],
'highlightedRowAttributeExpressions' => [
[
'sqlExpression' => 'SpanAttributes[\'http.status_code\']',
'luceneExpression' => 'http.status_code',
'alias' => 'HTTP Status Code'
]
],
'materializedViews' => [
[
'databaseName' => 'otel',
'tableName' => 'otel_logs_mv_5m',
'dimensionColumns' => 'ServiceName, SeverityText',
'minGranularity' => '5m',
'timestampColumn' => 'Timestamp',
'aggregatedColumns' => [
[
'aggFn' => 'sum',
'mvColumn' => 'sum__Duration',
'sourceColumn' => 'Duration'
]
],
'minDate' => '2025-01-01T00:00:00Z'
]
],
'metadataMaterializedViews' => [
'keyRollupTable' => 'otel_logs_key_rollup_15m',
'kvRollupTable' => 'otel_logs_kv_rollup_15m',
'granularity' => '15m'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources"
payload := strings.NewReader("{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}"
response = http.request(request)
puts response.read_body{
"status": 200,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"result": {
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": false,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": false
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
}{
"status": 400,
"error": "<string>",
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"status": 500,
"error": "<string>",
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}ClickStack: Creates a new source. The request body is a source object without the
id field. If an id is sent anyway it is silently ignored (stripped before validation — the request is never rejected because of it). Granularity fields (materializedViews[].minGranularity and metadataMaterializedViews.granularity) accept the same short format the API returns (e.g. 5m, 15s, 1h, 1d).
Authorizations
Use key ID and key secret obtained in ClickHouse Cloud console: https://clickhouse.com/docs/cloud/manage/openapi
Path Parameters
Body
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Expression identifying the running release of a service. Defaults to the OpenTelemetry service.version resource attribute when unset. Where services carry the release on different attributes, fall back across them with coalesce(nullIf(a, ''), nullIf(b, '')).
"ResourceAttributes['service.version']"
For Distributed table sources whose target tables have non-matching column sets. A list of columns supported across all target tables, used instead of SELECT * when fetching full row data. Leave blank to select all columns.
"Timestamp, Body, ServiceName"
Comma-separated expressions that together identify one row, e.g. the partition key, primary key, _block_number and _block_offset. When set, row details are looked up by these columns only. Leave blank to detect keys from table metadata.
"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset"
Controls whether lucene rendering uses ClickHouse text indices via hasAllTokens() against the implicit column. "auto" detects a covering index at query time, "enabled" forces text index usage, "disabled" forces a LIKE/hasToken fallback.
auto, enabled, disabled "auto"
Which data parts, by row count, are read from text indexes to discover attribute keys and filter values. "median" (the default) balances coverage and cost, "smallest" reads the newest unmerged parts, "largest" reads the most merged data. Allowed values: 'median', 'smallest', 'largest'.
"median"
Was this page helpful?
curl --request POST \
--url https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": false,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": false
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
EOFimport requests
url = "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources"
payload = {
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": False,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": False
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Logs',
kind: 'log',
connection: '507f1f77bcf86cd799439012',
from: {databaseName: 'otel', tableName: 'otel_logs'},
defaultTableSelectExpression: 'Timestamp, ServiceName, SeverityText, Body',
timestampValueExpression: 'Timestamp',
id: '507f1f77bcf86cd799439011',
section: 'Billing',
disabled: false,
querySettings: [{setting: 'max_threads', value: '4'}],
filterSettings: {
databaseName: 'default',
tableName: 'otel_logs',
columns: [
{
name: 'ServiceName',
label: 'Service Name',
valueExpression: 'lower(service_name)',
allowAll: false
}
]
},
serviceNameExpression: 'ServiceName',
serviceVersionExpression: 'ResourceAttributes[\'service.version\']',
severityTextExpression: 'SeverityText',
severityNumberExpression: 'SeverityNumber',
bodyExpression: 'Body',
eventNameExpression: 'EventName',
eventAttributesExpression: 'LogAttributes',
resourceAttributesExpression: 'ResourceAttributes',
displayedTimestampValueExpression: 'TimestampTime',
orderByExpression: 'Timestamp DESC',
metricSourceId: '507f1f77bcf86cd799439013',
traceSourceId: '507f1f77bcf86cd799439014',
traceIdExpression: 'TraceId',
spanIdExpression: 'SpanId',
implicitColumnExpression: 'Body',
knownColumnsListExpression: 'Timestamp, Body, ServiceName',
rowKeyExpression: 'toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset',
useTextIndexForImplicitColumn: 'auto',
mapKeyIndexMaxParts: 20,
mapKeyIndexPartSelection: 'median',
highlightedTraceAttributeExpressions: [
{
sqlExpression: 'SpanAttributes[\'http.status_code\']',
luceneExpression: 'http.status_code',
alias: 'HTTP Status Code'
}
],
highlightedRowAttributeExpressions: [
{
sqlExpression: 'SpanAttributes[\'http.status_code\']',
luceneExpression: 'http.status_code',
alias: 'HTTP Status Code'
}
],
materializedViews: [
{
databaseName: 'otel',
tableName: 'otel_logs_mv_5m',
dimensionColumns: 'ServiceName, SeverityText',
minGranularity: '5m',
timestampColumn: 'Timestamp',
aggregatedColumns: [{aggFn: 'sum', mvColumn: 'sum__Duration', sourceColumn: 'Duration'}],
minDate: '2025-01-01T00:00:00Z'
}
],
metadataMaterializedViews: {
keyRollupTable: 'otel_logs_key_rollup_15m',
kvRollupTable: 'otel_logs_kv_rollup_15m',
granularity: '15m'
}
})
};
fetch('https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Logs',
'kind' => 'log',
'connection' => '507f1f77bcf86cd799439012',
'from' => [
'databaseName' => 'otel',
'tableName' => 'otel_logs'
],
'defaultTableSelectExpression' => 'Timestamp, ServiceName, SeverityText, Body',
'timestampValueExpression' => 'Timestamp',
'id' => '507f1f77bcf86cd799439011',
'section' => 'Billing',
'disabled' => false,
'querySettings' => [
[
'setting' => 'max_threads',
'value' => '4'
]
],
'filterSettings' => [
'databaseName' => 'default',
'tableName' => 'otel_logs',
'columns' => [
[
'name' => 'ServiceName',
'label' => 'Service Name',
'valueExpression' => 'lower(service_name)',
'allowAll' => false
]
]
],
'serviceNameExpression' => 'ServiceName',
'serviceVersionExpression' => 'ResourceAttributes[\'service.version\']',
'severityTextExpression' => 'SeverityText',
'severityNumberExpression' => 'SeverityNumber',
'bodyExpression' => 'Body',
'eventNameExpression' => 'EventName',
'eventAttributesExpression' => 'LogAttributes',
'resourceAttributesExpression' => 'ResourceAttributes',
'displayedTimestampValueExpression' => 'TimestampTime',
'orderByExpression' => 'Timestamp DESC',
'metricSourceId' => '507f1f77bcf86cd799439013',
'traceSourceId' => '507f1f77bcf86cd799439014',
'traceIdExpression' => 'TraceId',
'spanIdExpression' => 'SpanId',
'implicitColumnExpression' => 'Body',
'knownColumnsListExpression' => 'Timestamp, Body, ServiceName',
'rowKeyExpression' => 'toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset',
'useTextIndexForImplicitColumn' => 'auto',
'mapKeyIndexMaxParts' => 20,
'mapKeyIndexPartSelection' => 'median',
'highlightedTraceAttributeExpressions' => [
[
'sqlExpression' => 'SpanAttributes[\'http.status_code\']',
'luceneExpression' => 'http.status_code',
'alias' => 'HTTP Status Code'
]
],
'highlightedRowAttributeExpressions' => [
[
'sqlExpression' => 'SpanAttributes[\'http.status_code\']',
'luceneExpression' => 'http.status_code',
'alias' => 'HTTP Status Code'
]
],
'materializedViews' => [
[
'databaseName' => 'otel',
'tableName' => 'otel_logs_mv_5m',
'dimensionColumns' => 'ServiceName, SeverityText',
'minGranularity' => '5m',
'timestampColumn' => 'Timestamp',
'aggregatedColumns' => [
[
'aggFn' => 'sum',
'mvColumn' => 'sum__Duration',
'sourceColumn' => 'Duration'
]
],
'minDate' => '2025-01-01T00:00:00Z'
]
],
'metadataMaterializedViews' => [
'keyRollupTable' => 'otel_logs_key_rollup_15m',
'kvRollupTable' => 'otel_logs_kv_rollup_15m',
'granularity' => '15m'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources"
payload := strings.NewReader("{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.clickhouse.cloud/v1/organizations/{organizationId}/services/{serviceId}/clickstack/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Logs\",\n \"kind\": \"log\",\n \"connection\": \"507f1f77bcf86cd799439012\",\n \"from\": {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs\"\n },\n \"defaultTableSelectExpression\": \"Timestamp, ServiceName, SeverityText, Body\",\n \"timestampValueExpression\": \"Timestamp\",\n \"id\": \"507f1f77bcf86cd799439011\",\n \"section\": \"Billing\",\n \"disabled\": false,\n \"querySettings\": [\n {\n \"setting\": \"max_threads\",\n \"value\": \"4\"\n }\n ],\n \"filterSettings\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\",\n \"columns\": [\n {\n \"name\": \"ServiceName\",\n \"label\": \"Service Name\",\n \"valueExpression\": \"lower(service_name)\",\n \"allowAll\": false\n }\n ]\n },\n \"serviceNameExpression\": \"ServiceName\",\n \"serviceVersionExpression\": \"ResourceAttributes['service.version']\",\n \"severityTextExpression\": \"SeverityText\",\n \"severityNumberExpression\": \"SeverityNumber\",\n \"bodyExpression\": \"Body\",\n \"eventNameExpression\": \"EventName\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"displayedTimestampValueExpression\": \"TimestampTime\",\n \"orderByExpression\": \"Timestamp DESC\",\n \"metricSourceId\": \"507f1f77bcf86cd799439013\",\n \"traceSourceId\": \"507f1f77bcf86cd799439014\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"implicitColumnExpression\": \"Body\",\n \"knownColumnsListExpression\": \"Timestamp, Body, ServiceName\",\n \"rowKeyExpression\": \"toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset\",\n \"useTextIndexForImplicitColumn\": \"auto\",\n \"mapKeyIndexMaxParts\": 20,\n \"mapKeyIndexPartSelection\": \"median\",\n \"highlightedTraceAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"highlightedRowAttributeExpressions\": [\n {\n \"sqlExpression\": \"SpanAttributes['http.status_code']\",\n \"luceneExpression\": \"http.status_code\",\n \"alias\": \"HTTP Status Code\"\n }\n ],\n \"materializedViews\": [\n {\n \"databaseName\": \"otel\",\n \"tableName\": \"otel_logs_mv_5m\",\n \"dimensionColumns\": \"ServiceName, SeverityText\",\n \"minGranularity\": \"5m\",\n \"timestampColumn\": \"Timestamp\",\n \"aggregatedColumns\": [\n {\n \"aggFn\": \"sum\",\n \"mvColumn\": \"sum__Duration\",\n \"sourceColumn\": \"Duration\"\n }\n ],\n \"minDate\": \"2025-01-01T00:00:00Z\"\n }\n ],\n \"metadataMaterializedViews\": {\n \"keyRollupTable\": \"otel_logs_key_rollup_15m\",\n \"kvRollupTable\": \"otel_logs_kv_rollup_15m\",\n \"granularity\": \"15m\"\n }\n}"
response = http.request(request)
puts response.read_body{
"status": 200,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"result": {
"name": "Logs",
"kind": "log",
"connection": "507f1f77bcf86cd799439012",
"from": {
"databaseName": "otel",
"tableName": "otel_logs"
},
"defaultTableSelectExpression": "Timestamp, ServiceName, SeverityText, Body",
"timestampValueExpression": "Timestamp",
"id": "507f1f77bcf86cd799439011",
"section": "Billing",
"disabled": false,
"querySettings": [
{
"setting": "max_threads",
"value": "4"
}
],
"filterSettings": {
"databaseName": "default",
"tableName": "otel_logs",
"columns": [
{
"name": "ServiceName",
"label": "Service Name",
"valueExpression": "lower(service_name)",
"allowAll": false
}
]
},
"serviceNameExpression": "ServiceName",
"serviceVersionExpression": "ResourceAttributes['service.version']",
"severityTextExpression": "SeverityText",
"severityNumberExpression": "SeverityNumber",
"bodyExpression": "Body",
"eventNameExpression": "EventName",
"eventAttributesExpression": "LogAttributes",
"resourceAttributesExpression": "ResourceAttributes",
"displayedTimestampValueExpression": "TimestampTime",
"orderByExpression": "Timestamp DESC",
"metricSourceId": "507f1f77bcf86cd799439013",
"traceSourceId": "507f1f77bcf86cd799439014",
"traceIdExpression": "TraceId",
"spanIdExpression": "SpanId",
"implicitColumnExpression": "Body",
"knownColumnsListExpression": "Timestamp, Body, ServiceName",
"rowKeyExpression": "toDate(Timestamp), ServiceName, Timestamp, _block_number, _block_offset",
"useTextIndexForImplicitColumn": "auto",
"mapKeyIndexMaxParts": 20,
"mapKeyIndexPartSelection": "median",
"highlightedTraceAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"highlightedRowAttributeExpressions": [
{
"sqlExpression": "SpanAttributes['http.status_code']",
"luceneExpression": "http.status_code",
"alias": "HTTP Status Code"
}
],
"materializedViews": [
{
"databaseName": "otel",
"tableName": "otel_logs_mv_5m",
"dimensionColumns": "ServiceName, SeverityText",
"minGranularity": "5m",
"timestampColumn": "Timestamp",
"aggregatedColumns": [
{
"aggFn": "sum",
"mvColumn": "sum__Duration",
"sourceColumn": "Duration"
}
],
"minDate": "2025-01-01T00:00:00Z"
}
],
"metadataMaterializedViews": {
"keyRollupTable": "otel_logs_key_rollup_15m",
"kvRollupTable": "otel_logs_kv_rollup_15m",
"granularity": "15m"
}
}
}{
"status": 400,
"error": "<string>",
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"status": 500,
"error": "<string>",
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}