Skip to content

Commit a1df365

Browse files
Adds event entry names for INP handler. Also guard against empty metric value
1 parent 4eede83 commit a1df365

File tree

1 file changed

+44
-2
lines changed
  • packages/tracing-internal/src/browser/metrics

1 file changed

+44
-2
lines changed

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,56 @@ function _trackFID(): () => void {
201201
});
202202
}
203203

204+
enum InteractionType {
205+
Click = 'click',
206+
Hover = 'hover',
207+
Drag = 'drag',
208+
Press = 'press',
209+
}
210+
211+
const INP_ENTRY_MAP: Record<string, InteractionType> = {
212+
click: InteractionType.Click,
213+
pointerdown: InteractionType.Click,
214+
pointerup: InteractionType.Click,
215+
mousedown: InteractionType.Click,
216+
mouseup: InteractionType.Click,
217+
touchstart: InteractionType.Click,
218+
touchend: InteractionType.Click,
219+
mouseover: InteractionType.Hover,
220+
mouseout: InteractionType.Hover,
221+
mouseenter: InteractionType.Hover,
222+
mouseleave: InteractionType.Hover,
223+
pointerover: InteractionType.Hover,
224+
pointerout: InteractionType.Hover,
225+
pointerenter: InteractionType.Hover,
226+
pointerleave: InteractionType.Hover,
227+
dragstart: InteractionType.Drag,
228+
dragend: InteractionType.Drag,
229+
drag: InteractionType.Drag,
230+
dragenter: InteractionType.Drag,
231+
dragleave: InteractionType.Drag,
232+
dragover: InteractionType.Drag,
233+
drop: InteractionType.Drag,
234+
keydown: InteractionType.Press,
235+
keyup: InteractionType.Press,
236+
keypress: InteractionType.Press,
237+
input: InteractionType.Press,
238+
};
239+
204240
/** Starts tracking the Interaction to Next Paint on the current page. */
205241
function _trackINP(interactionIdtoRouteNameMapping: InteractionRouteNameMapping): () => void {
206242
return addInpInstrumentationHandler(({ metric }) => {
207-
const entry = metric.entries.find(e => e.name === 'click' || e.name === 'pointerdown');
243+
if (metric.value === undefined) {
244+
return;
245+
}
246+
const entry = metric.entries.find(
247+
entry => entry.duration === metric.value && INP_ENTRY_MAP[entry.name] !== undefined,
248+
);
208249
const client = getClient();
209250
if (!entry || !client) {
210251
return;
211252
}
253+
const InteractionType = INP_ENTRY_MAP[entry.name];
212254
const options = client.getOptions();
213255
/** Build the INP span, create an envelope from the span, and then send the envelope */
214256
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
@@ -229,7 +271,7 @@ function _trackINP(interactionIdtoRouteNameMapping: InteractionRouteNameMapping)
229271
const span = new Span({
230272
startTimestamp: startTime,
231273
endTimestamp: startTime + duration,
232-
op: 'ui.interaction.click',
274+
op: `ui.interaction.${InteractionType}`,
233275
name: htmlTreeAsString(entry.target),
234276
attributes: {
235277
release: options.release,

0 commit comments

Comments
 (0)