Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(personhog): error metric tagging (#61464)

Zach Brownfc90c36296c9
diff --git a/nodejs/src/ingestion/personhog/client.test.ts b/nodejs/src/ingestion/personhog/client.test.ts
index b289aa01aa81..f14ec9897782 100644
--- a/nodejs/src/ingestion/personhog/client.test.ts
+++ b/nodejs/src/ingestion/personhog/client.test.ts
@@ -409,7 +409,7 @@ describe('PersonHogClient', () => {
},
})
- // 300 items should produce 2 chunks: 250 + 50
+ // 300 items should produce 3 chunks: 100 + 100 + 100
const count = 300
const teamIds = Array.from({ length: count }, (_, i) => i + 1)
const groupTypeIndexes = Array.from({ length: count }, () => 0)
@@ -417,8 +417,8 @@ describe('PersonHogClient', () => {
const result = await client.groups.fetchGroupsByKeys(teamIds, groupTypeIndexes, groupKeys)
- expect(callCount).toBe(2)
- expect(batchSizes).toEqual([250, 50])
+ expect(callCount).toBe(3)
+ expect(batchSizes).toEqual([100, 100, 100])
expect(result).toHaveLength(300)
expect(result.every((r) => r.group_properties.chunked === true)).toBe(true)
})
diff --git a/nodejs/src/ingestion/personhog/groups.ts b/nodejs/src/ingestion/personhog/groups.ts
index 16df36ff4e3f..0934d3c68c57 100644
--- a/nodejs/src/ingestion/personhog/groups.ts
+++ b/nodejs/src/ingestion/personhog/groups.ts
@@ -13,7 +13,7 @@ import type { Group as ProtoGroup } from '../../generated/personhog/personhog/ty
import { Group as DomainGroup, GroupTypeIndex } from '../../types'
import { epochMsToDateTime, eventualReadOptions, parseJsonBytes } from './client'
-const PERSONHOG_BATCH_SIZE = 250
+const PERSONHOG_BATCH_SIZE = 100
const VALID_GROUP_TYPE_INDEXES = new Set<number>([0, 1, 2, 3, 4])
function toGroupTypeIndex(value: number): GroupTypeIndex {
diff --git a/nodejs/src/ingestion/personhog/grpc-retry.ts b/nodejs/src/ingestion/personhog/grpc-retry.ts
index 5757a10faeca..a549fd99c77e 100644
--- a/nodejs/src/ingestion/personhog/grpc-retry.ts
+++ b/nodejs/src/ingestion/personhog/grpc-retry.ts
@@ -1,6 +1,7 @@
import { Code, ConnectError } from '@connectrpc/connect'
import { logger } from '../../utils/logger'
+import { grpcErrorType, personhogRetriesTotal } from './metrics'
const RETRYABLE_CODES = new Set([
Code.Unavailable,
@@ -41,6 +42,7 @@ export async function withRetry<T>(
})
throw error
}
+ personhogRetriesTotal.inc({ source: label, error_type: grpcErrorType(error) })
logger.warn(`[${label}] Retryable gRPC error, retrying`, {
attempt: attempt + 1,
maxRetries,
diff --git a/nodejs/src/ingestion/personhog/metrics.ts b/nodejs/src/ingestion/personhog/metrics.ts
index 158d5532775d..5073b4e872bd 100644
--- a/nodejs/src/ingestion/personhog/metrics.ts
+++ b/nodejs/src/ingestion/personhog/metrics.ts
@@ -1,3 +1,4 @@
+import { Code, ConnectError } from '@connectrpc/connect'
import { Counter, Gauge, Histogram } from 'prom-client'
// -- Connection-level metrics --
@@ -46,10 +47,23 @@ export const personhogRequestsTotal = new Counter({
export const personhogErrorsTotal = new Counter({
name: 'personhog_errors_total',
- help: 'Total PersonHog gRPC errors (before fallback to Postgres)',
- labelNames: ['method', 'client'] as const,
+ help: 'Total PersonHog gRPC errors',
+ labelNames: ['method', 'client', 'error_type'] as const,
})
+export const personhogRetriesTotal = new Counter({
+ name: 'personhog_retries_total',
+ help: 'Total PersonHog gRPC retries before success or exhaustion',
+ labelNames: ['source', 'error_type'] as const,
+})
+
+export function grpcErrorType(error: unknown): string {
+ if (error instanceof ConnectError) {
+ return Code[error.code] ?? 'unknown'
+ }
+ return 'non_grpc'
+}
+
export const personhogLatencySeconds = new Histogram({
name: 'personhog_latency_seconds',
help: 'PersonHog request latency in seconds',
@@ -72,7 +86,7 @@ export async function timedGrpc<T>(clientLabel: string, method: string, fn: () =
try {
return await fn()
} catch (error) {
- personhogErrorsTotal.inc({ method, client: clientLabel })
+ personhogErrorsTotal.inc({ method, client: clientLabel, error_type: grpcErrorType(error) })
throw error
} finally {
end()
diff --git a/nodejs/src/utils/lazy-loader.ts b/nodejs/src/utils/lazy-loader.ts
index 23774e4617c8..58c670bd6866 100644
--- a/nodejs/src/utils/lazy-loader.ts
+++ b/nodejs/src/utils/lazy-loader.ts
@@ -194,7 +194,12 @@ export class LazyLoader<T> {
// If we haven't triggered a hard refresh, we check for a background refresh
if (backgroundRefreshAfter && Date.now() > backgroundRefreshAfter) {
- void this.load([key])
+ void this.load([key]).catch((err) => {
+ logger.warn(`[LazyLoader:${this.options.name}] Background refresh failed`, {
+ key,
+ error: String(err),
+ })
+ })
lazyLoaderCacheHits.labels({ name: this.options.name, hit: 'hit_background' }).inc()
continue
}
diff --git a/rust/personhog-router/src/main.rs b/rust/personhog-router/src/main.rs
index 123bdacff454..72945a565415 100644
--- a/rust/personhog-router/src/main.rs
+++ b/rust/personhog-router/src/main.rs
@@ -115,8 +115,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1.0, 5.0, 10.0, 50.0, 100.0, 250.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0,
];
const RESPONSE_SIZE_BUCKETS: &[f64] = &[
- 256.0, 1024.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, 16777216.0,
- 67108864.0,
+ 256.0, 1024.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, 8388608.0,
+ 16777216.0, 33554432.0, 67108864.0,
];
let recorder_handle = PrometheusBuilder::new()
.add_global_label("service", "personhog-router")