Page MenuHomePhabricator

Dropped events in click tracking instrumentation (TypeError: event.target.getAttribute is not a function, Unable to get property 'classList' of undefined or null reference)
Closed, DeclinedPublic

Description

An error suggests we are dropping at least 37 events a day from the desktop UI web click tracking schema

https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2020.09.22/clienterror/?id=AXS2TPGWLNRtRo5XBq-J

Stack trace:

at URL1:89:363
at dispatch URL1:212:669
at add/elemData.handle URL1:209:366

URL1: https://fr.wikipedia.org/w/load.php?lang=fr&modules=ext.centralNotice.choiceData%2Cdisplay%2CgeoIP%2CkvStore%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cite.ux-enhancements%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2Ckartographer%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.growthExperiments.SuggestedEditSession%7Cext.kartographer.linkbox%2Cstaticframe%2Cutil%7Cext.quicksurveys.init%2Clib%7Cext.scribunto.logs%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2Ctablesorter%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Crouter%2Cstorage%2Ctoc%2Cuser%2Cutil%2Cviewport%7Cmediawiki.editfont.styles%7Cmediawiki.language.months%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui-widgets.icons%7Coojs-ui.styles.icons-media%2Cindicators%7Cskins.vector.js%7Cuser.defaults&skin=vector&version=3a53p

Another error in the same function is Unable to get property 'classList' of undefined or null reference

at logEvent  URL1:96:814
at Anonymous function  URL1:97:287
at Anonymous function  URL2:24:340

URL1: https://fr.wikipedia.org/w/load.php?lang=fr&modules=ext.centralNotice.bannerHistoryLogger%2CchoiceData%2Cdisplay%2CgeoIP%2CimpressionDiet%2CkvStore%2ClargeBannerLimit%2ClegacySupport%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Csite%7Cjquery.client%2Ccookie%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Cstorage%2Cuser%2Cutil%7Cmediawiki.action.view.metadata%7Cmediawiki.editfont.styles%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Cskins.vector.js%7Cuser.defaults&skin=vector&version=1lmdq
URL2: https://fr.wikipedia.org/w/load.php?lang=fr&modules=startup&only=scripts&raw=1&skin=vector

Seems to correspond with the line https://github.com/wikimedia/mediawiki-extensions-WikimediaEvents/blob/master/modules/ext.wikimediaEvents/desktopWebUIActions.js#L59

It's my understanding that this can be true if a simulated event is fired with no target.

Another error TypeError: document.body is null (was T263079)

Sam has suggested we move away from using the class on the body tag in our instrumentation and use mw.config directly.

at logEvent URL1:95:542
at URL1:96:12

URL1: https://fr.wikipedia.org/w/load.php?lang=fr&modules=ext.centralNotice.choiceData%2Cdisplay%2CgeoIP%2CkvStore%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cite.ux-enhancements%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.growthExperiments.SuggestedEditSession%7Cext.quicksurveys.init%2Clib%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Cstorage%2Cuser%2Cutil%2Cviewport%7Cmediawiki.editfont.styles%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui-widgets.icons%7Coojs-ui.styles.indicators%7Cskins.vector.js%7Cuser.defaults&skin=vector&version=1l4fr

Developer notes

Let's check whether ev.target is null.

Event Timeline

Jdlrobson triaged this task as Medium priority.Sep 22 2020, 3:29 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson renamed this task from TypeError: event.target.getAttribute is not a function to Dropped events in click tracking instrumentation (TypeError: event.target.getAttribute is not a function, Unable to get property 'classList' of undefined or null reference).Oct 13 2020, 7:37 PM
Jdlrobson updated the task description. (Show Details)

Which browser name/version does it affect? I noticed you recently introduced use of classList in WME and in core, which last I checked didn't pass under Grade A, but looking at it now, I think that was caught up, but maybe we found an edge case of maybe a minor version of one browser not having it yet? If so, we can probably add it to the startup feature test if it's very minor.

The error is most prevalent iun Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0

Ack, so not a browser issue then, but rather the variable itself being null in a certain context. In that case these are two different kinds of issue.

TypeError: event.target.getAttribute is not a function

This suggests event and event.target are defined and hold some kind of truthy/object value, but that getAttribute is not defined on that event.target object value. Perhaps a non-Element snuck in there?

Unable to get property 'classList' of undefined or null reference

This on the other hand suggets event.target itself is simply undefined or null, e.g. because the element has no parentNode, which is an easy bug to fix.

Correct however these are two issues in the same feature with possibly similar characteristics so I grouped them together. Removing the instrumentation might be the fix we end up with for example.

I believe the getAttribute issue occurs here:

		$( document ).on( 'click',
			function ( event ) {
				// Track special links that have data-event-name associated
				logEvent( 'click', event.target.getAttribute( 'data-event-name' ) );
			}
		).on( 'click',
			// Track links in nav element e.g. menus.
			'nav a',
			function ( event ) {
				logEvent( 'click', event.target.parentNode.getAttribute( 'id' ) );
			} );

while the skin version error is occuring here inside the logEvent function:

if ( !skinVersion ) {
			skinVersion = document.body.classList.contains( 'skin-vector-legacy' ) ?
				1 : 2;
		}
ovasileva subscribed.

@phuedx - Do we know what the average number of events in that schema is per day?

phuedx lowered the priority of this task from Medium to Low.Jan 13 2021, 5:58 PM

@phuedx - Do we know what the average number of events in that schema is per day?

[0]
year	month	n	
2020	11	69951605	
2020	12	61987604	
2021	1	27340724

select
    year,
    month,
    count(*) as n
from
    event.desktopwebuiactionstracking
where
    (
        ( year = 2020 and month >= 11 )
        or year = 2021
    )
group by
    year, month
order by
    year asc,
    month asc
limit 10000
;

With the above in mind, I'm going to be bold and re-prioritise this task as Low priority. Does anyone have any objection to declining this task outright?

I'm okay with declining this task, provided we're committing to turning off the instrumentation in future, which will deal with the logspam part of this.
If we plan to retain this schema for the indefinite future however, we should find a way to remove that logspam noise.

@Jdlrobson - in that case, declining. Do we have a task for turning off the instrumentation later on?