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(nodejs): instrument redis calls in blobby (#65952)

Nick Best919bf26ab32c
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/metrics.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/metrics.ts
index e309c78a82a3..cc4ee0d327cb 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/metrics.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/metrics.ts
@@ -114,6 +114,30 @@ export class SessionBatchMetrics {
help: 'Number of Redis errors in session filter (failed open)',
})
+ private static readonly sessionTrackerRedisLatency = new Histogram({
+ name: 'recording_blob_ingestion_v2_session_tracker_redis_latency_seconds',
+ help: 'Time taken for session tracker Redis calls (acquire + SET NX + release)',
+ buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
+ })
+
+ private static readonly sessionFilterRedisLatency = new Histogram({
+ name: 'recording_blob_ingestion_v2_session_filter_redis_latency_seconds',
+ help: 'Time taken for session filter Redis calls (acquire + EXISTS/SET + release)',
+ buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
+ })
+
+ private static readonly keystoreRedisLatency = new Histogram({
+ name: 'recording_blob_ingestion_v2_keystore_redis_latency_seconds',
+ help: 'Time taken for keystore Redis cache calls (acquire + GET/SETEX + release)',
+ buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
+ })
+
+ private static readonly retentionRedisLatency = new Histogram({
+ name: 'recording_blob_ingestion_v2_retention_redis_latency_seconds',
+ help: 'Time taken for retention service Redis calls (acquire + GET/SET + release)',
+ buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
+ })
+
public static incrementBatchesFlushed(): void {
this.batchesFlushed.inc()
}
@@ -202,4 +226,20 @@ export class SessionBatchMetrics {
public static incrementSessionFilterRedisErrors(count: number = 1): void {
this.sessionFilterRedisErrors.inc(count)
}
+
+ public static observeSessionTrackerRedisLatency(seconds: number): void {
+ this.sessionTrackerRedisLatency.observe(seconds)
+ }
+
+ public static observeSessionFilterRedisLatency(seconds: number): void {
+ this.sessionFilterRedisLatency.observe(seconds)
+ }
+
+ public static observeKeystoreRedisLatency(seconds: number): void {
+ this.keystoreRedisLatency.observe(seconds)
+ }
+
+ public static observeRetentionRedisLatency(seconds: number): void {
+ this.retentionRedisLatency.observe(seconds)
+ }
}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.test.ts
index 37bdea0a0de4..54c4d16bfbb0 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.test.ts
@@ -11,6 +11,7 @@ jest.mock('./metrics', () => ({
incrementSessionFilterCacheMiss: jest.fn(),
incrementNewSessionsRateLimited: jest.fn(),
incrementSessionFilterRedisErrors: jest.fn(),
+ observeSessionFilterRedisLatency: jest.fn(),
},
}))
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.ts
index 4a3514774052..747dc0c43534 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-filter.ts
@@ -75,6 +75,7 @@ export class SessionFilter {
this.localCache.set(key, true)
SessionBatchMetrics.incrementSessionsBlocked()
+ const startTime = performance.now()
let client
try {
client = await this.redisPool.acquire()
@@ -97,6 +98,7 @@ export class SessionFilter {
if (client) {
await this.redisPool.release(client)
}
+ SessionBatchMetrics.observeSessionFilterRedisLatency((performance.now() - startTime) / 1000)
}
}
@@ -126,6 +128,7 @@ export class SessionFilter {
SessionBatchMetrics.incrementSessionFilterCacheMiss()
+ const startTime = performance.now()
let client
try {
client = await this.redisPool.acquire()
@@ -150,6 +153,7 @@ export class SessionFilter {
if (client) {
await this.redisPool.release(client)
}
+ SessionBatchMetrics.observeSessionFilterRedisLatency((performance.now() - startTime) / 1000)
}
}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.test.ts
index ef7c2d56f880..c7c5435c1348 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.test.ts
@@ -11,6 +11,7 @@ jest.mock('./metrics', () => ({
incrementSessionTrackerCacheHit: jest.fn(),
incrementSessionTrackerCacheMiss: jest.fn(),
incrementSessionTrackerRedisErrors: jest.fn(),
+ observeSessionTrackerRedisLatency: jest.fn(),
},
}))
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.ts
index 14eb1fe74e78..e898c74b38b4 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-tracker.ts
@@ -47,6 +47,7 @@ export class SessionTracker {
SessionBatchMetrics.incrementSessionTrackerCacheMiss()
+ const startTime = performance.now()
let client
try {
client = await this.redisPool.acquire()
@@ -83,6 +84,7 @@ export class SessionTracker {
if (client) {
await this.redisPool.release(client)
}
+ SessionBatchMetrics.observeSessionTrackerRedisLatency((performance.now() - startTime) / 1000)
}
}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.test.ts
index 36542a30d168..368450cc84a3 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.test.ts
@@ -2,6 +2,12 @@ import { KeyStore, SessionKey } from '~/ingestion/pipelines/sessionreplay/shared
import { RedisCachedKeyStore } from './redis-cache'
+jest.mock('~/ingestion/pipelines/sessionreplay/sessions/metrics', () => ({
+ SessionBatchMetrics: {
+ observeKeystoreRedisLatency: jest.fn(),
+ },
+}))
+
describe('RedisCachedKeyStore', () => {
let mockDelegate: jest.Mocked<KeyStore>
let mockRedisClient: any
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.ts
index 694d54b2bfa0..04c3354c566f 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/keystore/cache/redis-cache.ts
@@ -1,3 +1,4 @@
+import { SessionBatchMetrics } from '~/ingestion/pipelines/sessionreplay/sessions/metrics'
import {
deserializeSessionKey,
serializeSessionKey,
@@ -24,30 +25,36 @@ export class RedisCachedKeyStore implements KeyStore {
}
private async getCached(sessionId: string, teamId: number): Promise<SessionKey | null> {
+ const startTime = performance.now()
const client = await this.redisPool.acquire()
try {
const cached = await client.get(this.cacheKey(sessionId, teamId))
return cached ? deserializeSessionKey(cached) : null
} finally {
await this.redisPool.release(client)
+ SessionBatchMetrics.observeKeystoreRedisLatency((performance.now() - startTime) / 1000)
}
}
private async setCached(sessionId: string, teamId: number, key: SessionKey): Promise<void> {
+ const startTime = performance.now()
const client = await this.redisPool.acquire()
try {
await client.setex(this.cacheKey(sessionId, teamId), this.ttlSeconds, serializeSessionKey(key))
} finally {
await this.redisPool.release(client)
+ SessionBatchMetrics.observeKeystoreRedisLatency((performance.now() - startTime) / 1000)
}
}
private async deleteCached(sessionId: string, teamId: number): Promise<void> {
+ const startTime = performance.now()
const client = await this.redisPool.acquire()
try {
await client.del(this.cacheKey(sessionId, teamId))
} finally {
await this.redisPool.release(client)
+ SessionBatchMetrics.observeKeystoreRedisLatency((performance.now() - startTime) / 1000)
}
}
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.test.ts
index 54a785b3d077..493911762a67 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.test.ts
@@ -12,6 +12,12 @@ jest.mock('./metrics', () => ({
},
}))
+jest.mock('~/ingestion/pipelines/sessionreplay/sessions/metrics', () => ({
+ SessionBatchMetrics: {
+ observeRetentionRedisLatency: jest.fn(),
+ },
+}))
+
describe('RetentionService', () => {
let retentionService: RetentionService
let mockRedisClient: jest.Mocked<Redis>
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.ts
index 15102f8b5ad3..a7b10b4c4032 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/retention/retention-service.ts
@@ -1,3 +1,4 @@
+import { SessionBatchMetrics } from '~/ingestion/pipelines/sessionreplay/sessions/metrics'
import {
RetentionPeriod,
RetentionPeriodToDaysMap,
@@ -37,6 +38,7 @@ export class RetentionService {
public async getSessionRetention(teamId: TeamId, sessionId: string): Promise<RetentionPeriod> {
let retentionPeriod: string | null = null
+ const startTime = performance.now()
const client = await this.redisPool.acquire()
const redisKey = this.generateRedisKey(sessionId)
@@ -54,6 +56,7 @@ export class RetentionService {
}
} finally {
await this.redisPool.release(client)
+ SessionBatchMetrics.observeRetentionRedisLatency((performance.now() - startTime) / 1000)
}
if (retentionPeriod !== null && isValidRetentionPeriod(retentionPeriod)) {