Skip to content

Commit

Permalink
chore(plugin-server): add labels to merge txn metrics (#17934)
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored and daibhin committed Oct 23, 2023
1 parent 35ce77f commit 1daaf21
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export const mergeFinalFailuresCounter = new Counter({
export const mergeTxnAttemptCounter = new Counter({
name: 'person_merge_txn_attempt_total',
help: 'Number of person merge attempts.',
labelNames: ['call', 'oldPersonIdentified', 'newPersonIdentified', 'poEEmbraceJoin'],
})

export const mergeTxnSuccessCounter = new Counter({
name: 'person_merge_txn_success_total',
help: 'Number of person merges that succeeded.',
labelNames: ['call', 'oldPersonIdentified', 'newPersonIdentified', 'poEEmbraceJoin'],
})

// used to prevent identify from being used with generic IDs
Expand Down Expand Up @@ -152,8 +154,10 @@ export class PersonState {
return await this.updatePersonProperties(person)
}

/**
* @returns [Person, boolean that indicates if properties were already handled or not]
*/
private async createOrGetPerson(): Promise<[Person, boolean]> {
// returns: person, properties were already handled or not
let person = await this.db.fetchPerson(this.teamId, this.distinctId)
if (person) {
return [person, false]
Expand Down Expand Up @@ -477,7 +481,14 @@ export class PersonState {
createdAt: DateTime,
properties: Properties
): Promise<[ProducerRecord[], Person]> {
mergeTxnAttemptCounter.inc()
mergeTxnAttemptCounter
.labels({
call: this.event.event, // $identify, $create_alias or $merge_dangerously
oldPersonIdentified: String(otherPerson.is_identified),
newPersonIdentified: String(mergeInto.is_identified),
poEEmbraceJoin: String(this.poEEmbraceJoin),
})
.inc()

const result: [ProducerRecord[], Person] = await this.db.postgres.transaction(
PostgresUse.COMMON_WRITE,
Expand Down Expand Up @@ -518,7 +529,14 @@ export class PersonState {
}
)

mergeTxnSuccessCounter.inc()
mergeTxnSuccessCounter
.labels({
call: this.event.event, // $identify, $create_alias or $merge_dangerously
oldPersonIdentified: String(otherPerson.is_identified),
newPersonIdentified: String(mergeInto.is_identified),
poEEmbraceJoin: String(this.poEEmbraceJoin),
})
.inc()
return result
}

Expand Down

0 comments on commit 1daaf21

Please sign in to comment.