Skip to content

Commit

Permalink
feat(plugin-server): project_id in clickhouse_events_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Oct 29, 2024
1 parent f04c43b commit 97f98ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions plugin-server/src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ export class EventsProcessor {
): [RawClickHouseEvent, Promise<void>] {
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)
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion plugin-server/src/worker/ingestion/team-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TeamManager {
}

public async fetchTeam(teamId: number): Promise<Team | null> {
const cachedTeam = this.teamCache.get(teamId)
const cachedTeam = this.getCachedTeam(teamId)
if (cachedTeam !== undefined) {
return cachedTeam
}
Expand All @@ -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<Team | null> {
/**
* Validates and resolves the api token from an incoming event.
Expand Down

0 comments on commit 97f98ce

Please sign in to comment.