Skip to content

Commit 7c02a02

Browse files
authored
feat: Reduce noise from mousemove events (#1424)
1 parent 0c1ce6c commit 7c02a02

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/features/session_trace/aggregate/trace/storage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SUPPORTS_PERFORMANCE_OBSERVER = typeof globalScope.PerformanceObserver ===
1515

1616
const ignoredEvents = {
1717
// we find that certain events make the data too noisy to be useful
18-
global: { mouseup: true, mousedown: true },
18+
global: { mouseup: true, mousedown: true, mousemove: true },
1919
// certain events are present both in the window and in PVT metrics. PVT metrics are prefered so the window events should be ignored
2020
window: { load: true, pagehide: true },
2121
// when ajax instrumentation is disabled, all XMLHttpRequest events will return with origin = xhrOriginMissing and should be ignored
@@ -182,8 +182,8 @@ export class TraceStorage {
182182
}
183183

184184
shouldIgnoreEvent (event, target) {
185-
const origin = eventOrigin(event.target, target, this.parent.ee)
186185
if (event.type in ignoredEvents.global) return true
186+
const origin = eventOrigin(event.target, target, this.parent.ee)
187187
if (!!ignoredEvents[origin] && ignoredEvents[origin].ignoreAll) return true
188188
return !!(!!ignoredEvents[origin] && event.type in ignoredEvents[origin])
189189
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright 2020 New Relic Corporation.
4+
PDX-License-Identifier: Apache-2.0
5+
-->
6+
<html lang="en">
7+
<head>
8+
<title>RUM Unit Test</title>
9+
{init}
10+
{config}
11+
{loader}
12+
<script>
13+
addEventListener("mousemove", function() {
14+
console.log("Mouse moved")
15+
})
16+
</script>
17+
</head>
18+
<body>
19+
<div id="initial">initial content</div>
20+
21+
<div id="foobar">
22+
FOOBAR!
23+
</div>
24+
<script>
25+
// Create a new mouse event
26+
const mouseMoveEvent = new MouseEvent('mousemove', {
27+
clientX: 100, // X coordinate relative to the viewport
28+
clientY: 200, // Y coordinate relative to the viewport
29+
bubbles: true, // Allow the event to bubble up the DOM tree
30+
cancelable: true // Allow the event to be canceled
31+
})
32+
33+
// Get the element to dispatch the event to
34+
const element = document.getElementById('foobar')
35+
36+
// Dispatch the event
37+
element.dispatchEvent(mouseMoveEvent)
38+
</script>
39+
</body>
40+
</html>

tests/specs/session-trace/trace-nodes.e2e.js

+14
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ describe('Trace nodes', () => {
126126
}, {})
127127
expect(Object.values(eventCounts).some(count => count > 1)).toBeFalsy()
128128
})
129+
130+
it('are not created for mouseover events', async () => {
131+
const url = await browser.testHandle.assetURL('event-listener-mousemove.html', stConfig())
132+
await browser.url(url).then(() => browser.waitForAgentLoad())
133+
134+
const [sessionTraceHarvests] = await Promise.all([
135+
sessionTraceCapture.waitForResult({ timeout: 10000 })
136+
])
137+
138+
sessionTraceHarvests.forEach(harvest => {
139+
const foobarMousemoveEvts = JSONPath({ path: '$.request.body.[?(!!@ && @.t===\'event\' && @.n===\'mousing\' && @.o===\'div#foobar\')]', json: harvest })
140+
expect(foobarMousemoveEvts.length).toEqual(0)
141+
})
142+
})
129143
})
130144

131145
function getEventsSetSize () {

0 commit comments

Comments
 (0)