Skip to content

Commit e053c49

Browse files
authored
feat: Add user-agent to alerts client (#1209)
Closes HDX-2481 # Summary For browser-based queries, the clickhouse requests go through the clickhouse-proxy endpoint, which re-writes the user-agent header for analytics purposes. Alerts queries don't go through the clickhouse-proxy, and clickhouse-js doesn't allow us to directly set the user-agent header. We can instead provide an `application` name, which is pre-pended to the default clickhouse-js user-agent, yielding a user-agent like: ``` hyperdx-alerts 2.5.0 clickhouse-js/1.12.1 (lv:nodejs/v22.19.0; os:darwin) ``` The user agent shows up in ClickHouse query logs: <img width="607" height="279" alt="Screenshot 2025-09-25 at 1 27 36 PM" src="https://github.com/user-attachments/assets/8098648d-9245-42c5-a41c-d7a58186ad68" />
1 parent 8a24c32 commit e053c49

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/api": patch
4+
"@hyperdx/app": patch
5+
---
6+
7+
chore: Customize user-agent for Alerts ClickHouse client

packages/api/src/tasks/providers/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export default class DefaultAlertProvider implements AlertProvider {
313313
host,
314314
username,
315315
password,
316+
application: `hyperdx-alerts ${config.CODE_VERSION}`,
316317
});
317318
}
318319
}

packages/common-utils/src/clickhouse/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class ClickhouseClient extends BaseClickhouseClient {
9292
},
9393
fetch: myFetch,
9494
request_timeout: this.requestTimeout,
95+
application: this.application,
9596
});
9697
}
9798

packages/common-utils/src/clickhouse/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ export type ClickhouseClientOptions = {
373373
username?: string;
374374
password?: string;
375375
queryTimeout?: number;
376+
/** Application name, used as the client's HTTP user-agent header */
377+
application?: string;
376378
};
377379

378380
export abstract class BaseClickhouseClient {
@@ -381,6 +383,7 @@ export abstract class BaseClickhouseClient {
381383
protected readonly password?: string;
382384
protected readonly queryTimeout?: number;
383385
protected client?: WebClickHouseClient | NodeClickHouseClient;
386+
protected readonly application?: string;
384387
/*
385388
* Some clickhouse db's (the demo instance for example) make the
386389
* max_rows_to_read setting readonly and the query will fail if you try to
@@ -394,12 +397,14 @@ export abstract class BaseClickhouseClient {
394397
username,
395398
password,
396399
queryTimeout,
400+
application,
397401
}: ClickhouseClientOptions) {
398402
this.host = host!;
399403
this.username = username;
400404
this.password = password;
401405
this.queryTimeout = queryTimeout;
402406
this.maxRowReadOnly = false;
407+
this.application = application;
403408
}
404409

405410
protected getClient(): WebClickHouseClient | NodeClickHouseClient {

packages/common-utils/src/clickhouse/node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export { createClient as createNativeClient };
1313
export class ClickhouseClient extends BaseClickhouseClient {
1414
constructor(options: ClickhouseClientOptions) {
1515
super(options);
16+
1617
this.client = createClient({
1718
url: this.host,
1819
username: this.username,
1920
password: this.password,
2021
request_timeout: this.requestTimeout,
22+
application: this.application,
2123
});
2224
}
2325

0 commit comments

Comments
 (0)