Page MenuHomePhabricator

Allow Instrumentation Engineers to label events sent during a pageview or session
Open, Needs TriagePublic


As an Instrumentation Engineer
I want to label all events sent on a pageview or in session
So that I and others can determine what interventions (or combination of interventions) affected our metrics

While analysing the EditAttemptStep instrument, I noticed that there was a complicated oversample signalling mechanism where a number of extensions run the WikimediaEventsShouldSchemaEditAttemptStepOversample hook. The GrowthExperiments handles that hook, returning truthy if the user has just clicked an element on their newcomer homepage.

This is a useful pattern – collaborator notifying an instrument that something relevant has happened – but the relationship between the collaborator and instrument is inverted – the instrument asks the collaborator whether or not something specific has happened. Further, the implementation doesn't scale well from a maintenance perspective.

There should be a public API for Instrumentation Engineers to add labels to events dispatched via the Metrics Platform for a pageview or for a session, e.g.

mw.metricsPlatform.addLabel( 'foo' );
mw.metricsPlatform.addLabel( [ 'bar', 'baz' ] );
mw.metricsPlatform.addLabel( 'qux', true ); // Add the "qux" label to all events dispatched in this session.

Because instrumentation logic and/or state is sometimes split across the server and client, there should also be a protocol for adding labels available on the server, e.g.

namespace MediaWiki\Extensions\EventLogging;

interface GetMetricsPlatformLabelsHook {
  public function onGetMetricsPlatformLabels( array &$labels ): void;


  1. We use label rather than tag for the same reasons as in T316992: ClientError fieldname 'tags' is conflicting.