[JS] Create Instrument class/newInstrument API
Instruments using MetricsClient#submitInteraction()
and other methods will need to repeat the streamName
and schemaID
parameters on every invocation. In order to allow instrument maintainers to keep their instruments DRY, I propose adding the Instrument
class, a class that has a MetricsClient
-like interface but is bound to a specific {streamName,schemaID}
pair.
Example
type Action = [ 'scroll', 'scroll-to-top' ];
const m = createMetricsClient();
const instrument = m.newInstrument(
'mediawiki.web_ui_scroll_migrated',
'/analytics/mediawiki/product_metrics/web_ui_actions/1.0.1'
);
// …
/**
* @param {Action} action
*/
function log( action ) {
instrument.submitInteraction( action );
}
// …
// Is the instrument enabled?
//if ( instrument.isStreamInSample() ) {
if ( instrument.isEnabled() ) {
}
c.f. mediawiki/extensions/WikimediaEvents/modules/ext.wikimediaEvents/webUIScroll.js
Future Improvements
-
Allow
MetricsClient#newInstrument()
to accept a{streamName,schemaVersion}
pair. Stream configs must have aschema_title
property. Combining that property with a version creates a schema ID -
Allow
MetricsClient#newInstrument()
to accept onlyinstrumentName
. In future, the MetricsPlatform MediaWiki extension will be updated to put more information about instruments inside of the relevant stream config. When this is done, we can updateMetricsClient
to use this information when constructingInstrument
instances
Notes
- The Mobile Web team (who became the Web team) had the same idea with the
mw.eventLog.Schema
class.
Depends-On: !42 (merged)
Bug: T366827