Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(observability): drop unused ClickHouse cost and export heartbeat row metrics (#18678)

Niklas Semmler314cd9b59005
diff --git a/packages/shared/src/server/clickhouse/queryOutcome.test.ts b/packages/shared/src/server/clickhouse/queryOutcome.test.ts
index fa6ebad9aa..f241a74906 100644
--- a/packages/shared/src/server/clickhouse/queryOutcome.test.ts
+++ b/packages/shared/src/server/clickhouse/queryOutcome.test.ts
@@ -2,13 +2,13 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import {
CLICKHOUSE_QUERY_OUTCOME_METRIC,
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS,
+ CLICKHOUSE_QUERY_ELAPSED_MS_METRIC,
CLICKHOUSE_RESOURCE_ERROR_OUTCOMES,
clickHouseQueryOutcomeRouteLabel,
clickHouseQueryShape,
clickHouseQueryTableLabel,
recordClickHouseQueryOutcome,
- recordClickHouseQueryPerformance,
+ recordClickHouseQueryElapsed,
} from "./queryOutcome";
const recordIncrement = vi.fn();
@@ -332,8 +332,8 @@ describe("ClickHouse query outcome metric", () => {
);
});
- it("emits the summary header as distributions with the outcome tags", () => {
- recordClickHouseQueryPerformance(
+ it("emits the summary runtime as a distribution with the outcome tags", () => {
+ recordClickHouseQueryElapsed(
{
read_rows: "1200",
read_bytes: "524288",
@@ -352,36 +352,33 @@ describe("ClickHouse query outcome metric", () => {
"main",
);
- const tags = {
- surface: "trpc",
- route: "scores.allFromEvents",
- table: "scores",
- query_shape: "scores_final",
- clickhouse_service: "main",
- };
expect(recordDistribution.mock.calls).toEqual([
- [CLICKHOUSE_QUERY_PERFORMANCE_METRICS.elapsedMs, 37.5, tags],
- [CLICKHOUSE_QUERY_PERFORMANCE_METRICS.readBytes, 524288, tags],
- [CLICKHOUSE_QUERY_PERFORMANCE_METRICS.readRows, 1200, tags],
- [CLICKHOUSE_QUERY_PERFORMANCE_METRICS.memoryBytes, 8388608, tags],
+ [
+ CLICKHOUSE_QUERY_ELAPSED_MS_METRIC,
+ 37.5,
+ {
+ surface: "trpc",
+ route: "scores.allFromEvents",
+ table: "scores",
+ query_shape: "scores_final",
+ clickhouse_service: "main",
+ },
+ ],
]);
});
- it("skips summary keys that are missing or not numeric", () => {
- recordClickHouseQueryPerformance(
- { read_rows: "10", read_bytes: "n/a" },
- { tag_schema_version: "1", surface: "unknown" },
- "other",
- "other",
- "main",
- );
+ it("skips a missing or non-numeric elapsed_ns", () => {
+ for (const summary of [{ read_rows: "10" }, { elapsed_ns: "n/a" }]) {
+ recordClickHouseQueryElapsed(
+ summary,
+ { tag_schema_version: "1", surface: "unknown" },
+ "other",
+ "other",
+ "main",
+ );
+ }
- expect(recordDistribution).toHaveBeenCalledTimes(1);
- expect(recordDistribution).toHaveBeenCalledWith(
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS.readRows,
- 10,
- expect.any(Object),
- );
+ expect(recordDistribution).not.toHaveBeenCalled();
});
it("keeps unknown surfaces and unlabelled routes queryable", () => {
diff --git a/packages/shared/src/server/clickhouse/queryOutcome.ts b/packages/shared/src/server/clickhouse/queryOutcome.ts
index 9a7cb9ad37..c9bad8217a 100644
--- a/packages/shared/src/server/clickhouse/queryOutcome.ts
+++ b/packages/shared/src/server/clickhouse/queryOutcome.ts
@@ -15,17 +15,13 @@ export const CLICKHOUSE_QUERY_OUTCOME_METRIC =
"langfuse.clickhouse.query.outcome";
/**
- * Per-query cost distributions, read from the `x-clickhouse-summary` response
+ * Per-query runtime distribution, read from the `x-clickhouse-summary` response
* header and emitted unsampled with the outcome metric's tags. APM keeps only a
- * small sample of query spans, so these are the series to track query cost over
- * time per route, table, shape and ClickHouse service.
+ * small sample of query spans, so this is the series to track query runtime
+ * over time per route, table, shape and ClickHouse service.
*/
-export const CLICKHOUSE_QUERY_PERFORMANCE_METRICS = {
- elapsedMs: "langfuse.clickhouse.query.elapsed_ms",
- readBytes: "langfuse.clickhouse.query.read_bytes",
- readRows: "langfuse.clickhouse.query.read_rows",
- memoryBytes: "langfuse.clickhouse.query.memory_bytes",
-} as const;
+export const CLICKHOUSE_QUERY_ELAPSED_MS_METRIC =
+ "langfuse.clickhouse.query.elapsed_ms";
export type ClickHouseQueryOutcome =
| "success"
@@ -304,53 +300,24 @@ export function recordClickHouseQueryOutcome(
});
}
-function summaryNumber(
- summary: Record<string, unknown>,
- key: string,
-): number | undefined {
- if (summary[key] === undefined) return undefined;
- const value = Number(summary[key]);
- return Number.isFinite(value) ? value : undefined;
-}
-
/**
- * Emits the cost distributions from a parsed `x-clickhouse-summary` header.
- * ClickHouse sends the values as numeric strings; keys an older server does not
- * send are skipped.
+ * Emits the runtime distribution from a parsed `x-clickhouse-summary` header.
+ * ClickHouse sends `elapsed_ns` as a numeric string; an older server that does
+ * not send it emits nothing.
*/
-export function recordClickHouseQueryPerformance(
+export function recordClickHouseQueryElapsed(
summary: Record<string, unknown>,
tags: NormalizedClickHouseQueryTags,
table: ClickHouseQueryTable,
shape: ClickHouseQueryShape,
clickhouseService: ClickhouseService,
): void {
- const metricTags = clickHouseQueryMetricTags(
- tags,
- table,
- shape,
- clickhouseService,
+ if (summary.elapsed_ns === undefined) return;
+ const elapsedNs = Number(summary.elapsed_ns);
+ if (!Number.isFinite(elapsedNs)) return;
+ recordDistribution(
+ CLICKHOUSE_QUERY_ELAPSED_MS_METRIC,
+ elapsedNs / 1e6,
+ clickHouseQueryMetricTags(tags, table, shape, clickhouseService),
);
- const elapsedNs = summaryNumber(summary, "elapsed_ns");
- const values: Array<[string, number | undefined]> = [
- [
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS.elapsedMs,
- elapsedNs === undefined ? undefined : elapsedNs / 1e6,
- ],
- [
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS.readBytes,
- summaryNumber(summary, "read_bytes"),
- ],
- [
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS.readRows,
- summaryNumber(summary, "read_rows"),
- ],
- [
- CLICKHOUSE_QUERY_PERFORMANCE_METRICS.memoryBytes,
- summaryNumber(summary, "memory_usage"),
- ],
- ];
- for (const [metric, value] of values) {
- if (value !== undefined) recordDistribution(metric, value, metricTags);
- }
}
diff --git a/packages/shared/src/server/repositories/clickhouse.ts b/packages/shared/src/server/repositories/clickhouse.ts
index 557ac36d9b..15e5b6e6f2 100644
--- a/packages/shared/src/server/repositories/clickhouse.ts
+++ b/packages/shared/src/server/repositories/clickhouse.ts
@@ -35,7 +35,7 @@ import {
clickHouseQueryShape,
clickHouseQueryTableLabel,
recordClickHouseQueryOutcome,
- recordClickHouseQueryPerformance,
+ recordClickHouseQueryElapsed,
} from "../clickhouse/queryOutcome";
/**
@@ -789,7 +789,7 @@ export async function queryClickhouse<T>(
clickhouseService,
);
if (summary) {
- recordClickHouseQueryPerformance(
+ recordClickHouseQueryElapsed(
summary,
normalizedTags,
table,
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 930e7723f9..56066e09fc 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -606,11 +606,6 @@ const processBlobStorageExport = async (config: {
projectId: config.projectId,
};
heartbeat = setInterval(() => {
- recordGauge(
- "langfuse.blobstorage.export_heartbeat.rows",
- sourceStats.rows,
- heartbeatTags,
- );
recordGauge(
"langfuse.blobstorage.export_heartbeat.serialized_bytes",
compressedCounter