Skip to content

Commit

Permalink
feat: add 'keep' option to trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
niieani committed Jun 5, 2024
1 parent a63653e commit b57495b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/v2/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class Operation implements PerformanceEntryLike {
}

let tracked = false
let shouldAddEvent = true
let interrupted = false
/**
* the maximum time any given tracker has allotted to wait
Expand All @@ -255,6 +256,9 @@ export class Operation implements PerformanceEntryLike {

if (criteriaMatched) {
tracked = true
if (trackerDefinition.keep === false) {
shouldAddEvent = false
}
if (trackerDefinition.interruptWhenSeen) {
interrupted = true
}
Expand Down Expand Up @@ -292,12 +296,14 @@ export class Operation implements PerformanceEntryLike {
: this.startTime
// TODO: calculate occurrence count during report generation

if (this.definition.keepOnlyExplicitlyTrackedEvents) {
if (tracked) {
if (shouldAddEvent) {
if (this.definition.keepOnlyExplicitlyTrackedEvents) {
if (tracked) {
this.events.push(event)
}
} else {
this.events.push(event)
}
} else {
this.events.push(event)
}

if (isOperationStartingEvent) {
Expand Down
7 changes: 7 additions & 0 deletions src/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export interface OperationDefinition {
* Useful for events like errors.
*/
interruptWhenSeen?: boolean

/**
* Indicates if events matching this tracker should be kept in the operation.
* Maybe used to filter out events that are not relevant to the operation.
* @default true
*/
keep?: boolean
}[]

/**
Expand Down

0 comments on commit b57495b

Please sign in to comment.