Skip to content

Commit fd30d85

Browse files
committed
feat: allow filtering events in preprocessor
1 parent ad884f3 commit fd30d85

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/v2/defaultEventProcessor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import {
66
type InputEvent,
77
} from './types'
88

9-
export const defaultEventProcessor: EventProcessor = (entry): Event => {
9+
export const defaultEventProcessor: EventProcessor = (
10+
entry,
11+
): Event | undefined => {
12+
if (entry.entryType === 'mark' && entry.name.startsWith('--')) {
13+
// react in dev mode hundreds of these marks, ignore them
14+
return undefined
15+
}
16+
1017
const detail = typeof entry.detail === 'object' && entry.detail
1118
const metadata =
1219
'metadata' in entry && typeof entry.metadata === 'object'

src/v2/operation.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ import {
1515
SKIP_PROCESSING,
1616
} from './constants'
1717
import { defaultEventProcessor } from './defaultEventProcessor'
18-
import { FinalizationReason, OperationState } from './types'
1918
import {
2019
type CaptureInteractiveConfig,
2120
type Event,
2221
type EventMatchCriteria,
2322
type EventMatchFunction,
23+
type EventProcessor,
2424
type EventStatus,
2525
type InputEvent,
2626
type InstanceOptions,
2727
type ObserveFn,
2828
type OperationDefinition,
2929
type PerformanceApi,
3030
type PerformanceEntryLike,
31+
FinalizationReason,
32+
OperationState,
3133
} from './types'
3234

3335
/** returns the best supported blocking task type or undefined if none */
@@ -702,7 +704,7 @@ export class OperationManager {
702704
* which will be updated by the manager with metadata related to the operations that have processed it.
703705
* This will happen synchronously when running in unbuffered mode, and asynchronously when running in buffered mode.
704706
*/
705-
private preprocessEvent: (event: PerformanceEntryLike | InputEvent) => Event
707+
private preprocessEvent: EventProcessor
706708
supportedEntryTypes: readonly string[]
707709
expectBlockingTasks: boolean
708710

@@ -830,6 +832,9 @@ export class OperationManager {
830832
}
831833

832834
const event = this.preprocessEvent(entry)
835+
if (!event) {
836+
return undefined
837+
}
833838

834839
if (this.bufferDuration && !this.isFlushingBuffer) {
835840
this.eventBuffer.push(event)

src/v2/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ export interface PerformanceApi {
299299
now: () => number
300300
}
301301

302-
export type EventProcessor = (entry: InputEvent | PerformanceEntryLike) => Event
302+
export type EventProcessor = (
303+
entry: InputEvent | PerformanceEntryLike,
304+
) => Event | undefined
303305

304306
export interface InstanceOptions {
305307
defaultDebounceTime?: number

0 commit comments

Comments
 (0)