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.

feat(ingestion): prefetch teams and hog functions in non-analytics lanes (#106530)

Paweł Ledwoń5961f58f35b4
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/createPrefetchStep.test.ts b/nodejs/src/ingestion/common/steps/create-prefetch-step.test.ts
similarity index 96%
rename from nodejs/src/ingestion/pipelines/analytics/steps/createPrefetchStep.test.ts
rename to nodejs/src/ingestion/common/steps/create-prefetch-step.test.ts
index 955ba6f1bbc6..7d4b83c39bda 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/createPrefetchStep.test.ts
+++ b/nodejs/src/ingestion/common/steps/create-prefetch-step.test.ts
@@ -1,6 +1,6 @@
import { logger } from '~/common/utils/logger'
+import { createPrefetchStep } from '~/ingestion/common/steps/create-prefetch-step'
import { PipelineResultType, isOkResult } from '~/ingestion/framework/results'
-import { createPrefetchStep } from '~/ingestion/pipelines/analytics/steps/createPrefetchStep'
type TestInput = { key: string | null }
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/createPrefetchStep.ts b/nodejs/src/ingestion/common/steps/create-prefetch-step.ts
similarity index 100%
rename from nodejs/src/ingestion/pipelines/analytics/steps/createPrefetchStep.ts
rename to nodejs/src/ingestion/common/steps/create-prefetch-step.ts
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.test.ts b/nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.test.ts
similarity index 87%
rename from nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.test.ts
rename to nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.test.ts
index fb6fb889dd14..7c91f50edb94 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.test.ts
+++ b/nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.test.ts
@@ -1,5 +1,5 @@
+import { prefetchHogFunctionsStep } from '~/ingestion/common/steps/prefetch-hog-functions-step'
import { PipelineResultType } from '~/ingestion/framework/results'
-import { prefetchHogFunctionsStep } from '~/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep'
type TestInput = { team: { id: number } }
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.ts b/nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.ts
similarity index 88%
rename from nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.ts
rename to nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.ts
index c57a1d1cd7eb..77ff690c21e2 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep.ts
+++ b/nodejs/src/ingestion/common/steps/prefetch-hog-functions-step.ts
@@ -1,5 +1,5 @@
import { HogTransformer } from '~/common/hog-transformations/hog-transformer.interface'
-import { createPrefetchStep } from '~/ingestion/pipelines/analytics/steps/createPrefetchStep'
+import { createPrefetchStep } from '~/ingestion/common/steps/create-prefetch-step'
import { Team } from '~/types'
type PrefetchHogFunctionsStepInput = { team: Pick<Team, 'id'> }
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.test.ts b/nodejs/src/ingestion/common/steps/prefetch-teams-step.test.ts
similarity index 89%
rename from nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.test.ts
rename to nodejs/src/ingestion/common/steps/prefetch-teams-step.test.ts
index b88923de3b2c..038462e494c3 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.test.ts
+++ b/nodejs/src/ingestion/common/steps/prefetch-teams-step.test.ts
@@ -1,5 +1,5 @@
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import { PipelineResultType } from '~/ingestion/framework/results'
-import { prefetchTeamsStep } from '~/ingestion/pipelines/analytics/steps/prefetchTeamsStep'
type TestInput = { headers: { token?: string } }
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.ts b/nodejs/src/ingestion/common/steps/prefetch-teams-step.ts
similarity index 87%
rename from nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.ts
rename to nodejs/src/ingestion/common/steps/prefetch-teams-step.ts
index 5b3c567c79e7..44cd819d8338 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchTeamsStep.ts
+++ b/nodejs/src/ingestion/common/steps/prefetch-teams-step.ts
@@ -1,5 +1,5 @@
import { TeamManager } from '~/common/utils/team-manager'
-import { createPrefetchStep } from '~/ingestion/pipelines/analytics/steps/createPrefetchStep'
+import { createPrefetchStep } from '~/ingestion/common/steps/create-prefetch-step'
import { EventHeaders } from '~/types'
type PrefetchTeamsStepInput = { headers: Pick<EventHeaders, 'token'> }
diff --git a/nodejs/src/ingestion/pipelines/ai/consumer.test.ts b/nodejs/src/ingestion/pipelines/ai/consumer.test.ts
index 72b34ace1546..5f58b614057e 100644
--- a/nodejs/src/ingestion/pipelines/ai/consumer.test.ts
+++ b/nodejs/src/ingestion/pipelines/ai/consumer.test.ts
@@ -27,6 +27,8 @@ describe('createAiConsumer', () => {
INGESTION_OVERFLOW_PRESERVE_PARTITION_LOCALITY: false,
INGESTION_WORKER_CONCURRENT_BATCHES: 1,
DROP_EVENTS_BY_TOKEN_DISTINCT_ID: '',
+ TEAMS_PREFETCH_ENABLED: false,
+ HOG_FUNCTIONS_PREFETCH_ENABLED: false,
SKIP_PERSONS_PROCESSING_BY_TOKEN_DISTINCT_ID: '',
INGESTION_FORCE_OVERFLOW_BY_TOKEN_DISTINCT_ID: '',
EVENT_SCHEMA_ENFORCEMENT_ENABLED: false,
diff --git a/nodejs/src/ingestion/pipelines/ai/consumer.ts b/nodejs/src/ingestion/pipelines/ai/consumer.ts
index 6655b20de4a0..32b04d73656c 100644
--- a/nodejs/src/ingestion/pipelines/ai/consumer.ts
+++ b/nodejs/src/ingestion/pipelines/ai/consumer.ts
@@ -57,6 +57,8 @@ export type AiConsumerConfig = CommonIngestionConsumerConfig &
| 'SKIP_PERSONS_PROCESSING_BY_TOKEN_DISTINCT_ID'
| 'INGESTION_FORCE_OVERFLOW_BY_TOKEN_DISTINCT_ID'
| 'EVENT_SCHEMA_ENFORCEMENT_ENABLED'
+ | 'TEAMS_PREFETCH_ENABLED'
+ | 'HOG_FUNCTIONS_PREFETCH_ENABLED'
| 'AI_BLOB_S3_BUCKET'
| 'AI_BLOB_S3_PREFIX'
| 'AI_BLOB_S3_ENDPOINT'
@@ -199,6 +201,8 @@ export function createAiConsumer(config: AiConsumerConfig, sharedScope: AiShared
overflowLaneTTLRefreshService: container.overflowLaneTTLRefreshService,
concurrentBatches: config.INGESTION_WORKER_CONCURRENT_BATCHES,
eventSchemaEnforcementEnabled: config.EVENT_SCHEMA_ENFORCEMENT_ENABLED,
+ teamsPrefetchEnabled: config.TEAMS_PREFETCH_ENABLED,
+ hogFunctionsPrefetchEnabled: config.HOG_FUNCTIONS_PREFETCH_ENABLED,
// Schema loads run detached in the LazyLoader buffer, so an un-retried transient
// failure can surface as an unhandled rejection and restart the worker.
eventSchemaEnforcementManager: new EventSchemaEnforcementManager(container.postgres, {
diff --git a/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts b/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
index 9f583615849b..128d757c0309 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
@@ -40,7 +40,10 @@ describe('AiIngestionPipeline', () => {
let mockEventFilterManager: { getFilter: jest.Mock }
let mockCookielessManager: jest.Mocked<CookielessManager>
let mockHogTransformer: jest.Mocked<
- Pick<HogTransformer, 'transformEventAndProduceMessages' | 'processInvocationResults'>
+ Pick<
+ HogTransformer,
+ 'transformEventAndProduceMessages' | 'processInvocationResults' | 'prefetchHogFunctionsForTeams'
+ >
>
let mockPersonRepository: jest.Mocked<PersonReadRepository>
let mockGroupTypeManager: jest.Mocked<ReadOnlyGroupTypeManager>
@@ -105,6 +108,7 @@ describe('AiIngestionPipeline', () => {
mockTeamManager = {
getTeamByToken: jest.fn().mockResolvedValue(team),
+ getTeamsByTokens: jest.fn().mockResolvedValue({}),
getTeam: jest.fn().mockResolvedValue(team),
} as unknown as jest.Mocked<TeamManager>
@@ -124,8 +128,12 @@ describe('AiIngestionPipeline', () => {
.fn()
.mockImplementation((event) => Promise.resolve({ event, invocationResults: [] })),
processInvocationResults: jest.fn().mockResolvedValue(undefined),
+ prefetchHogFunctionsForTeams: jest.fn().mockResolvedValue(undefined),
} as unknown as jest.Mocked<
- Pick<HogTransformer, 'transformEventAndProduceMessages' | 'processInvocationResults'>
+ Pick<
+ HogTransformer,
+ 'transformEventAndProduceMessages' | 'processInvocationResults' | 'prefetchHogFunctionsForTeams'
+ >
>
mockPersonRepository = {
@@ -163,6 +171,8 @@ describe('AiIngestionPipeline', () => {
[APP_METRICS_OUTPUT]: single(APP_METRICS_OUTPUT, 'clickhouse_app_metrics2_test'),
}),
teamManager: mockTeamManager,
+ teamsPrefetchEnabled: true,
+ hogFunctionsPrefetchEnabled: true,
eventIngestionRestrictionManager: mockEventIngestionRestrictionManager,
eventFilterManager: mockEventFilterManager as any,
cookielessManager: mockCookielessManager,
diff --git a/nodejs/src/ingestion/pipelines/ai/pipeline.ts b/nodejs/src/ingestion/pipelines/ai/pipeline.ts
index 87fd0d14a87d..609680f03dd9 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/ai/pipeline.ts
@@ -43,6 +43,8 @@ import { createNormalizeProcessPersonFlagStep } from '~/ingestion/common/steps/e
import { createPrepareEventStep } from '~/ingestion/common/steps/event-processing/prepare-event-step'
import { createReadOnlyProcessGroupsStep } from '~/ingestion/common/steps/event-processing/readonly-process-groups-step'
import { createStripPersonUpdatePropertiesStep } from '~/ingestion/common/steps/event-processing/strip-person-update-properties-step'
+import { prefetchHogFunctionsStep } from '~/ingestion/common/steps/prefetch-hog-functions-step'
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
import {
createEventUsageBeforeBatchStep,
@@ -87,6 +89,8 @@ export interface AiIngestionPipelineConfig {
overflowLaneTTLRefreshService: OverflowRedirectService
concurrentBatches: number
eventSchemaEnforcementEnabled: boolean
+ teamsPrefetchEnabled: boolean
+ hogFunctionsPrefetchEnabled: boolean
eventSchemaEnforcementManager: EventSchemaEnforcementManager
topHog: TopHogRegistry
aiBlobStore: BlobStore | null
@@ -135,6 +139,8 @@ export function createAiIngestionPipeline<
overflowLaneTTLRefreshService,
concurrentBatches,
eventSchemaEnforcementEnabled,
+ teamsPrefetchEnabled,
+ hogFunctionsPrefetchEnabled,
eventSchemaEnforcementManager,
topHog,
aiBlobStore,
@@ -170,6 +176,7 @@ export function createAiIngestionPipeline<
// Kafka message key — the partition key capture computed. Cookieless
// events count under token:client_ip.
.pipeChunk(createRateLimitToOverflowStep(preservePartitionLocality, overflowRedirectService))
+ .pipeChunk(prefetchTeamsStep(teamManager, teamsPrefetchEnabled))
.parseMessage()
.resolveTeam()
.pipe(createValidateHistoricalMigrationStep())
@@ -187,6 +194,7 @@ export function createAiIngestionPipeline<
.gather()
.pipeChunk(createApplyCookielessProcessingStep(cookielessManager))
.pipeChunk(createOverflowLaneTTLRefreshStep(overflowLaneTTLRefreshService))
+ .pipeChunk(prefetchHogFunctionsStep(hogTransformer, hogFunctionsPrefetchEnabled))
// Read-only batch person fetch (no person writes). The personhog
// client retries transient gRPC errors for ~150ms; this outer
// retry absorbs longer blips that would otherwise crash the
diff --git a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
index 598fa56ec9bb..f416027e20a9 100644
--- a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
@@ -34,6 +34,7 @@ import { createFlushBatchStoresStep } from '~/ingestion/common/steps/event-proce
import { createFlushHogTransformerStep } from '~/ingestion/common/steps/event-processing/flush-hog-transformer-step'
import { createGroupStoreBeforeBatchStep } from '~/ingestion/common/steps/group-store-batch-step'
import { createPersonsStoreBeforeBatchStep } from '~/ingestion/common/steps/persons-store-batch-step'
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import {
createEventUsageBeforeBatchStep,
createFlushEventUsageStep,
@@ -54,7 +55,6 @@ import {
PostTeamPreprocessingSubpipelineConfig,
createPostTeamPreprocessingSubpipeline,
} from './post-team-preprocessing-subpipeline'
-import { prefetchTeamsStep } from './steps/prefetchTeamsStep'
export interface JoinedIngestionPipelineConfig {
eventSchemaEnforcementEnabled: boolean
diff --git a/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts b/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts
index 02fe4439f74e..432a1efce69f 100644
--- a/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts
@@ -22,10 +22,10 @@ import {
createValidateEventSchemaStep,
} from '~/ingestion/common/steps/event-preprocessing'
import { createDropOldEventsStep } from '~/ingestion/common/steps/event-processing/drop-old-events-step'
+import { prefetchHogFunctionsStep } from '~/ingestion/common/steps/prefetch-hog-functions-step'
import { ChunkPipelineBuilder } from '~/ingestion/framework/builders/chunk-pipeline-builders'
import { prefetchEventSchemasStep } from '~/ingestion/pipelines/analytics/steps/prefetchEventSchemasStep'
import { prefetchGroupsStep } from '~/ingestion/pipelines/analytics/steps/prefetchGroupsStep'
-import { prefetchHogFunctionsStep } from '~/ingestion/pipelines/analytics/steps/prefetchHogFunctionsStep'
import { prefetchPersonsStep } from '~/ingestion/pipelines/analytics/steps/prefetchPersonsStep'
import { PluginEvent } from '~/plugin-scaffold'
import { EventHeaders, Team } from '~/types'
diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchEventSchemasStep.ts b/nodejs/src/ingestion/pipelines/analytics/steps/prefetchEventSchemasStep.ts
index 3a905ee0881f..11454112c6a9 100644
--- a/nodejs/src/ingestion/pipelines/analytics/steps/prefetchEventSchemasStep.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/steps/prefetchEventSchemasStep.ts
@@ -1,5 +1,5 @@
import { EventSchemaEnforcementManager } from '~/common/utils/event-schema-enforcement-manager'
-import { createPrefetchStep } from '~/ingestion/pipelines/analytics/steps/createPrefetchStep'
+import { createPrefetchStep } from '~/ingestion/common/steps/create-prefetch-step'
import { Team } from '~/types'
type PrefetchEventSchemasStepInput = { team: Pick<Team, 'id'> }
diff --git a/nodejs/src/ingestion/pipelines/clientwarnings/consumer.test.ts b/nodejs/src/ingestion/pipelines/clientwarnings/consumer.test.ts
index 2f2870776746..4f7837fc41e5 100644
--- a/nodejs/src/ingestion/pipelines/clientwarnings/consumer.test.ts
+++ b/nodejs/src/ingestion/pipelines/clientwarnings/consumer.test.ts
@@ -20,6 +20,7 @@ describe('createClientWarningsConsumer', () => {
INGESTION_LANE: 'main',
KAFKA_BATCH_START_LOGGING_ENABLED: false,
DROP_EVENTS_BY_TOKEN_DISTINCT_ID: '',
+ TEAMS_PREFETCH_ENABLED: false,
...({} as IngestionOutputsConfig),
}
}
diff --git a/nodejs/src/ingestion/pipelines/clientwarnings/consumer.ts b/nodejs/src/ingestion/pipelines/clientwarnings/consumer.ts
index c307b2773c59..db6ae1db0adf 100644
--- a/nodejs/src/ingestion/pipelines/clientwarnings/consumer.ts
+++ b/nodejs/src/ingestion/pipelines/clientwarnings/consumer.ts
@@ -16,7 +16,7 @@ import { createClientWarningsPipeline } from './pipeline'
export type ClientWarningsConsumerConfig = CommonIngestionConsumerConfig &
IngestionOutputsConfig &
- Pick<IngestionConsumerConfig, 'DROP_EVENTS_BY_TOKEN_DISTINCT_ID'>
+ Pick<IngestionConsumerConfig, 'DROP_EVENTS_BY_TOKEN_DISTINCT_ID' | 'TEAMS_PREFETCH_ENABLED'>
export type ClientWarningsSharedScope = Scope<{
postgres: PostgresRouter
@@ -48,6 +48,6 @@ export function createClientWarningsConsumer(
)
return new CommonIngestionConsumerScope('clientwarnings', config, scope, ({ container }) =>
- createClientWarningsPipeline(container)
+ createClientWarningsPipeline({ ...container, teamsPrefetchEnabled: config.TEAMS_PREFETCH_ENABLED })
)
}
diff --git a/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.test.ts b/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.test.ts
index 68738973ce9e..61e1bc7feb4c 100644
--- a/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.test.ts
@@ -91,6 +91,7 @@ describe('ClientWarningsPipeline', () => {
mockTeamManager = {
getTeamByToken: jest.fn().mockResolvedValue(team),
+ getTeamsByTokens: jest.fn().mockResolvedValue({}),
getTeam: jest.fn().mockResolvedValue(team),
} as unknown as jest.Mocked<TeamManager>
@@ -124,6 +125,7 @@ describe('ClientWarningsPipeline', () => {
}),
topHog: createNoopTopHog(),
teamManager: mockTeamManager,
+ teamsPrefetchEnabled: true,
eventIngestionRestrictionManager: mockEventIngestionRestrictionManager,
eventFilterManager: mockEventFilterManager,
promiseScheduler,
diff --git a/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.ts b/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.ts
index 4680f676967a..556d483528da 100644
--- a/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/clientwarnings/pipeline.ts
@@ -21,6 +21,7 @@ import {
import { createApplyBasicEventRestrictionsStep } from '~/ingestion/common/steps/event-preprocessing/apply-event-restrictions'
import { createDropOldEventsStep } from '~/ingestion/common/steps/event-processing/drop-old-events-step'
import { createHandleClientIngestionWarningStep } from '~/ingestion/common/steps/event-processing/handle-client-ingestion-warning-step'
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
import { TopHogRegistry } from '~/ingestion/framework/extensions/tophog'
@@ -34,6 +35,7 @@ export interface ClientWarningsPipelineConfig {
eventFilterManager: EventFilterManager
promiseScheduler: PromiseScheduler
topHog: TopHogRegistry
+ teamsPrefetchEnabled: boolean
}
interface ClientWarningsPipelineInput {
@@ -48,8 +50,15 @@ export function createClientWarningsPipeline<
TInput extends ClientWarningsPipelineInput,
TContext extends ClientWarningsPipelineContext,
>(config: ClientWarningsPipelineConfig) {
- const { outputs, teamManager, eventIngestionRestrictionManager, eventFilterManager, promiseScheduler, topHog } =
- config
+ const {
+ outputs,
+ teamManager,
+ eventIngestionRestrictionManager,
+ eventFilterManager,
+ promiseScheduler,
+ topHog,
+ teamsPrefetchEnabled,
+ } = config
return newCommonIngestionPipeline<TInput, TContext>({
teamManager,
@@ -62,6 +71,7 @@ export function createClientWarningsPipeline<
.parseHeaders()
.pipe(createAllowEventsStep(['$$client_ingestion_warning']))
.pipe(createApplyBasicEventRestrictionsStep(eventIngestionRestrictionManager))
+ .pipeChunk(prefetchTeamsStep(teamManager, teamsPrefetchEnabled))
.parseMessage()
.resolveTeam()
.pipe(createValidateHistoricalMigrationStep())
diff --git a/nodejs/src/ingestion/pipelines/errortracking/consumer.ts b/nodejs/src/ingestion/pipelines/errortracking/consumer.ts
index e3fff0c2a2f0..3ab93811cfd6 100644
--- a/nodejs/src/ingestion/pipelines/errortracking/consumer.ts
+++ b/nodejs/src/ingestion/pipelines/errortracking/consumer.ts
@@ -18,6 +18,7 @@ import { RedisOverflowRepositoryComponent } from '~/ingestion/common/overflow-re
import { eventRateStrategy } from '~/ingestion/common/overflow-redirect/overflow-strategy'
import { Scope, extend } from '~/ingestion/common/scopes'
import { PromiseSchedulerComponent } from '~/ingestion/common/utils/promise-scheduler'
+import { IngestionConsumerConfig } from '~/ingestion/config'
import { RedisPool } from '~/types'
import { ErrorTrackingConsumerConfig } from './config'
@@ -39,6 +40,7 @@ export type ErrorTrackingLaneConfig = CommonIngestionConsumerConfig &
| 'ERROR_TRACKING_OVERFLOW_PRESERVE_PARTITION_LOCALITY'
| 'INGESTION_OVERFLOW_MODE'
> &
+ Pick<IngestionConsumerConfig, 'TEAMS_PREFETCH_ENABLED' | 'HOG_FUNCTIONS_PREFETCH_ENABLED'> &
Pick<CommonConfig, 'PLUGIN_SERVER_MODE'>
/**
@@ -134,6 +136,8 @@ export function createErrorTrackingConsumer(config: ErrorTrackingLaneConfig, sha
overflowLaneTTLRefreshService: container.overflowLaneTTLRefreshService,
topHog: container.topHog,
createEventUsageBatch,
+ teamsPrefetchEnabled: config.TEAMS_PREFETCH_ENABLED,
+ hogFunctionsPrefetchEnabled: config.HOG_FUNCTIONS_PREFETCH_ENABLED,
})
)
}
diff --git a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.test.ts b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.test.ts
index 19dabaa5c1fe..21a8662ee948 100644
--- a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.test.ts
@@ -241,6 +241,7 @@ describe('ErrorTrackingPipeline', () => {
mockTeamManager = {
getTeamByToken: jest.fn().mockResolvedValue(team),
+ getTeamsByTokens: jest.fn().mockResolvedValue({}),
getTeam: jest.fn().mockResolvedValue(team),
} as unknown as jest.Mocked<TeamManager>
@@ -266,6 +267,7 @@ describe('ErrorTrackingPipeline', () => {
.fn()
.mockImplementation((event) => Promise.resolve({ event, invocationResults: [] })),
processInvocationResults: jest.fn().mockResolvedValue(undefined),
+ prefetchHogFunctionsForTeams: jest.fn().mockResolvedValue(undefined),
}
mockCymbalClient = {
@@ -323,6 +325,8 @@ describe('ErrorTrackingPipeline', () => {
}),
promiseScheduler,
teamManager: mockTeamManager,
+ teamsPrefetchEnabled: true,
+ hogFunctionsPrefetchEnabled: true,
personRepository: mockPersonRepository,
hogTransformer: mockHogTransformer,
cymbalClient: mockCymbalClient,
diff --git a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.ts b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.ts
index 3f08f33bf5a0..36a3d49ef87f 100644
--- a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-pipeline.ts
@@ -32,6 +32,8 @@ import { createFetchPersonChunkStep } from '~/ingestion/common/steps/event-proce
import { createFlushHogTransformerStep } from '~/ingestion/common/steps/event-processing/flush-hog-transformer-step'
import { createHogTransformEventStep } from '~/ingestion/common/steps/event-processing/hog-transform-event-step'
import { createReadOnlyProcessGroupsStep } from '~/ingestion/common/steps/event-processing/readonly-process-groups-step'
+import { prefetchHogFunctionsStep } from '~/ingestion/common/steps/prefetch-hog-functions-step'
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
import {
EventUsageBatchContext,
@@ -53,7 +55,7 @@ import { createErrorTrackingPrepareEventStep } from './prepare-event-step'
/** The hog transformer methods the pipeline uses; lifecycle stays with the owning scope. */
export type ErrorTrackingHogTransformer = Pick<
HogTransformer,
- 'transformEventAndProduceMessages' | 'processInvocationResults'
+ 'transformEventAndProduceMessages' | 'processInvocationResults' | 'prefetchHogFunctionsForTeams'
>
export interface ErrorTrackingPipelineInput {
@@ -108,6 +110,8 @@ export interface ErrorTrackingPipelineConfig {
/** TopHog registry for metrics. */
topHog: TopHogRegistry
createEventUsageBatch: () => UsageRecordBatch
+ teamsPrefetchEnabled: boolean
+ hogFunctionsPrefetchEnabled: boolean
}
/**
@@ -117,19 +121,21 @@ export interface ErrorTrackingPipelineConfig {
* 1. Parse headers - Extract token, timestamps from Kafka message headers
* 2. Apply event restrictions - Billing limits, drop/overflow
* 3. Skip-cookieless rate limit - Redirect non-cookieless rate-limited events to overflow
- * pre-parse (cookieless events pass through to step 6)
- * 4. Parse Kafka message - Parse message body into event
- * 5. Resolve team - Look up team by token
- * 6. Apply cookieless processing - Rewrite distinct_id for cookieless events
- * 7. Only-cookieless rate limit - Redirect cookieless rate-limited events to overflow
- * using the hashed distinct_id from step 6
- * 8. Cymbal processing - Symbolicate, fingerprint, and link issues
- * 9. Person properties - Fetch person by distinct_id (read-only)
- * 10. Hog transformations - Run team transformations (including GeoIP if enabled)
- * 11. Prepare event - Convert to PreIngestionEvent format, track if person found
- * 12. Group type mapping - Map group types to indexes (read-only)
- * 13. Create event - Build ErrorTrackingKafkaEvent (matches Cymbal's output format)
- * 14. Emit event - Produce to output topic
+ * pre-parse (cookieless events pass through to step 7)
+ * 4. Prefetch teams - Warm the team cache for the chunk's tokens (TEAMS_PREFETCH_ENABLED)
+ * 5. Parse Kafka message - Parse message body into event
+ * 6. Resolve team - Look up team by token
+ * 7. Apply cookieless processing - Rewrite distinct_id for cookieless events
+ * 8. Only-cookieless rate limit - Redirect cookieless rate-limited events to overflow
+ * using the hashed distinct_id from step 7
+ * 9. Prefetch hog functions - Warm the transformation cache for the chunk's teams (HOG_FUNCTIONS_PREFETCH_ENABLED)
+ * 10. Cymbal processing - Symbolicate, fingerprint, and link issues
+ * 11. Person properties - Fetch person by distinct_id (read-only)
+ * 12. Hog transformations - Run team transformations (including GeoIP if enabled)
+ * 13. Prepare event - Convert to PreIngestionEvent format, track if person found
+ * 14. Group type mapping - Map group types to indexes (read-only)
+ * 15. Create event - Build ErrorTrackingKafkaEvent (matches Cymbal's output format)
+ * 16. Emit event - Produce to output topic
*
* Note: Cymbal runs before enrichment because it only needs the raw exception data
* for symbolication and fingerprinting. This reduces payload size and avoids
@@ -152,6 +158,8 @@ export function createErrorTrackingPipeline(config: ErrorTrackingPipelineConfig)
overflowLaneTTLRefreshService,
topHog,
createEventUsageBatch,
+ teamsPrefetchEnabled,
+ hogFunctionsPrefetchEnabled,
} = config
const preCymbal = newCommonIngestionPipeline<ErrorTrackingPipelineInput, { message: Message }, OverflowOutput>({
@@ -177,6 +185,7 @@ export function createErrorTrackingPipeline(config: ErrorTrackingPipelineConfig)
// Kafka message key — the partition key capture computed. Cookieless
// events count under token:client_ip.
.pipeChunk(createRateLimitToOverflowStep(preservePartitionLocality, overflowRedirectService))
+ .pipeChunk(prefetchTeamsStep(teamManager, teamsPrefetchEnabled))
.parseMessage()
.resolveTeam()
// Carry the Kafka message byte size through for Cymbal batch chunking.
@@ -188,6 +197,7 @@ export function createErrorTrackingPipeline(config: ErrorTrackingPipelineConfig)
.pipeChunk(createApplyCookielessProcessingStep(cookielessManager))
// Refresh TTLs for overflow lane events (keeps Redis flags alive)
.pipeChunk(createOverflowLaneTTLRefreshStep(overflowLaneTTLRefreshService))
+ .pipeChunk(prefetchHogFunctionsStep(hogTransformer, hogFunctionsPrefetchEnabled))
const afterCymbal = preCymbal
// Process through Cymbal as a batch (before enrichment - Cymbal only
diff --git a/nodejs/src/ingestion/pipelines/heatmaps/consumer.test.ts b/nodejs/src/ingestion/pipelines/heatmaps/consumer.test.ts
index 92ba7a4406d3..25c8f94ab6cc 100644
--- a/nodejs/src/ingestion/pipelines/heatmaps/consumer.test.ts
+++ b/nodejs/src/ingestion/pipelines/heatmaps/consumer.test.ts
@@ -21,6 +21,7 @@ describe('createHeatmapsConsumer', () => {
INGESTION_LANE: 'main',
KAFKA_BATCH_START_LOGGING_ENABLED: false,
DROP_EVENTS_BY_TOKEN_DISTINCT_ID: '',
+ TEAMS_PREFETCH_ENABLED: false,
...({} as IngestionOutputsConfig),
}
}
diff --git a/nodejs/src/ingestion/pipelines/heatmaps/consumer.ts b/nodejs/src/ingestion/pipelines/heatmaps/consumer.ts
index e9f15179c591..aedade6724bc 100644
--- a/nodejs/src/ingestion/pipelines/heatmaps/consumer.ts
+++ b/nodejs/src/ingestion/pipelines/heatmaps/consumer.ts
@@ -17,7 +17,7 @@ import { createHeatmapsPipeline } from './pipeline'
export type HeatmapsConsumerConfig = CommonIngestionConsumerConfig &
IngestionOutputsConfig &
- Pick<IngestionConsumerConfig, 'DROP_EVENTS_BY_TOKEN_DISTINCT_ID'>
+ Pick<IngestionConsumerConfig, 'DROP_EVENTS_BY_TOKEN_DISTINCT_ID' | 'TEAMS_PREFETCH_ENABLED'>
export type HeatmapsSharedScope = Scope<{
postgres: PostgresRouter
@@ -47,6 +47,6 @@ export function createHeatmapsConsumer(config: HeatmapsConsumerConfig, sharedSco
)
return new CommonIngestionConsumerScope('heatmaps', config, scope, ({ container }) =>
- createHeatmapsPipeline(container)
+ createHeatmapsPipeline({ ...container, teamsPrefetchEnabled: config.TEAMS_PREFETCH_ENABLED })
)
}
diff --git a/nodejs/src/ingestion/pipelines/heatmaps/pipeline.test.ts b/nodejs/src/ingestion/pipelines/heatmaps/pipeline.test.ts
index c257a9afec11..5e226a01e7a7 100644
--- a/nodejs/src/ingestion/pipelines/heatmaps/pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/heatmaps/pipeline.test.ts
@@ -105,6 +105,7 @@ describe('HeatmapsPipeline', () => {
mockTeamManager = {
getTeamByToken: jest.fn().mockResolvedValue(team),
+ getTeamsByTokens: jest.fn().mockResolvedValue({}),
getTeam: jest.fn().mockResolvedValue(team),
} as unknown as jest.Mocked<TeamManager>
@@ -150,6 +151,7 @@ describe('HeatmapsPipeline', () => {
}),
topHog: createNoopTopHog(),
teamManager: mockTeamManager,
+ teamsPrefetchEnabled: true,
eventIngestionRestrictionManager: mockEventIngestionRestrictionManager,
eventFilterManager: mockEventFilterManager,
cookielessManager: mockCookielessManager,
diff --git a/nodejs/src/ingestion/pipelines/heatmaps/pipeline.ts b/nodejs/src/ingestion/pipelines/heatmaps/pipeline.ts
index 450b354b26cc..e145a720389d 100644
--- a/nodejs/src/ingestion/pipelines/heatmaps/pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/heatmaps/pipeline.ts
@@ -24,6 +24,7 @@ import { createApplyBasicEventRestrictionsStep } from '~/ingestion/common/steps/
import { createDropOldEventsStep } from '~/ingestion/common/steps/event-processing/drop-old-events-step'
import { createNormalizeEventStep } from '~/ingestion/common/steps/event-processing/normalize-event-step'
import { createPrepareEventStep } from '~/ingestion/common/steps/event-processing/prepare-event-step'
+import { prefetchTeamsStep } from '~/ingestion/common/steps/prefetch-teams-step'
import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
import { TopHogRegistry } from '~/ingestion/framework/extensions/tophog'
@@ -43,6 +44,7 @@ export interface HeatmapsPipelineConfig {
cookielessManager: CookielessManager
promiseScheduler: PromiseScheduler
topHog: TopHogRegistry
+ teamsPrefetchEnabled: boolean
}
interface HeatmapsPipelineInput {
@@ -64,6 +66,7 @@ export function createHeatmapsPipeline<TInput extends HeatmapsPipelineInput, TCo
cookielessManager,
promiseScheduler,
topHog,
+ teamsPrefetchEnabled,
} = config
return (
@@ -78,6 +81,7 @@ export function createHeatmapsPipeline<TInput extends HeatmapsPipelineInput, TCo
.parseHeaders()
.pipe(createAllowEventsStep(['$$heatmap']))
.pipe(createApplyBasicEventRestrictionsStep(eventIngestionRestrictionManager))
+ .pipeChunk(prefetchTeamsStep(teamManager, teamsPrefetchEnabled))
.parseMessage()
.resolveTeam()
.pipe(createValidateHistoricalMigrationStep())
diff --git a/nodejs/src/servers/error-tracking-server.ts b/nodejs/src/servers/error-tracking-server.ts
index a5213e727a82..9548849bc5be 100644
--- a/nodejs/src/servers/error-tracking-server.ts
+++ b/nodejs/src/servers/error-tracking-server.ts
@@ -79,7 +79,10 @@ export type ErrorTrackingServerConfig = BaseServerConfig &
PersonHogConfig &
UsageIngestionConfig &
CookielessServerConfig &
- Pick<IngestionConsumerConfig, 'KAFKA_BATCH_START_LOGGING_ENABLED'> &
+ Pick<
+ IngestionConsumerConfig,
+ 'KAFKA_BATCH_START_LOGGING_ENABLED' | 'TEAMS_PREFETCH_ENABLED' | 'HOG_FUNCTIONS_PREFETCH_ENABLED'
+ > &
Pick<
CommonConfig,
| 'LOG_LEVEL'