diff --git a/plugin-server/src/worker/ingestion/process-event.ts b/plugin-server/src/worker/ingestion/process-event.ts index fc53331c98eb44..a7d563dd51dd2f 100644 --- a/plugin-server/src/worker/ingestion/process-event.ts +++ b/plugin-server/src/worker/ingestion/process-event.ts @@ -208,6 +208,16 @@ export class EventsProcessor { ): [RawClickHouseEvent, Promise] { const { eventUuid: uuid, event, teamId, distinctId, properties, timestamp } = preIngestionEvent + const team = this.teamManager.getCachedTeam(teamId) + if (team === undefined) { + throw new Error( + `Cache should have been warmed for team ID ${teamId} by eventsProcessor.processEvent() in prepareEventStep, but for some reason we didn't find the data in cache.` + ) + } + if (team === null) { + throw new Error(`No team found with ID ${teamId}. Can't ingest event.`) + } + let elementsChain = '' try { elementsChain = this.getElementsChain(properties) @@ -251,6 +261,7 @@ export class EventsProcessor { properties: JSON.stringify(properties ?? {}), timestamp: castTimestampOrNow(timestamp, TimestampFormat.ClickHouse), team_id: teamId, + project_id: team.project_id, distinct_id: safeClickhouseString(distinctId), elements_chain: safeClickhouseString(elementsChain), created_at: castTimestampOrNow(null, TimestampFormat.ClickHouse), diff --git a/plugin-server/src/worker/ingestion/team-manager.ts b/plugin-server/src/worker/ingestion/team-manager.ts index 9846071c094fde..46ec9ebcd0a055 100644 --- a/plugin-server/src/worker/ingestion/team-manager.ts +++ b/plugin-server/src/worker/ingestion/team-manager.ts @@ -41,7 +41,7 @@ export class TeamManager { } public async fetchTeam(teamId: number): Promise { - const cachedTeam = this.teamCache.get(teamId) + const cachedTeam = this.getCachedTeam(teamId) if (cachedTeam !== undefined) { return cachedTeam } @@ -56,6 +56,10 @@ export class TeamManager { } } + public getCachedTeam(teamId: TeamId): Team | null | undefined { + return this.teamCache.get(teamId) + } + public async getTeamByToken(token: string): Promise { /** * Validates and resolves the api token from an incoming event.