Skip to content

Draft: [JS] Create Submitter

Phuedx requested to merge work/phuedx/submitter into main

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 a "submitter," an object 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 submitter = m.newSubmitter(
  'mediawiki.web_ui_scroll_migrated',
  '/analytics/mediawiki/product_metrics/web_ui_actions/1.0.1',
  true // Submit "init" event immediately
);

// …

/**
 * @param {Action} action
 */
function log( action ) {
    submitter.submitInteraction( action );
}

// …

// Is the instrument enabled?
if ( submitter.isStreamInSample() ) {
}

c.f. mediawiki/extensions/WikimediaEvents/modules/ext.wikimediaEvents/webUIScroll.js

Future

There are two possible improvements that we could make either now or in future:

  1. Allow MetricsClient#newSubmitter() to accept a {streamName,schemaVersion} pair. Stream configs must have a schema_title property. Combining that property with a version creates a schema ID
  2. Allow MetricsClient#newSubmitter() to accept only streamName. Stream configs could include the schema ID in the producers.metrics_platform_client property and the Metrics Platform client libraries could be updated to use that property by default

Notes

  1. The Mobile Web team (who became the Web team) had the same idea with the mw.eventLog.Schema class.
Edited by Phuedx

Merge request reports