Skip to content

[PHP] Allow MetricsClient#submitInteraction() to accept custom data

Phuedx requested to merge work/phuedx/php into main

Background

Per David Martin's report on Slack (WMF-only):

  1. I'm using the schema in this patch, installed locally according to the instructions here.
  2. In mediawiki-eventlogging-1, I see
    1. Loading schema at /analytics/mediawiki/product_metrics/wikilambda/api/1.0.0
    2. followed by the entire schema, including the declarations of my function and success properties
  3. I also see Validating event..., followed by the event generated by my PHP instrument, but it's missing function and success.
  4. Then, because it's missing those 2 properties I've declared as required, the event fails validation.
  5. If I change my instrument to generate action_context instead of function then action_context  does show up in the generated event.

3 is the puzzling part.

Explanation

The issue occurs because MetricsClient#submitInteraction() has an internal allowlist for $interactionData properties, which is enforced by InteractionDataTrait#getInteractionData(). When that method is called, the function and success properties are removed from $interactionData and the event is submitted to the event ingestion service.

Fix

Update MetricsClient#submitInteraction() to mimic the method of the same name in the JS implementation.

Supporting changes:

  1. Remove InteractionDataTrait as it is unused
  2. Ensure the $schema and dt properties are added to the event after all other data has been added and add a test
Edited by Phuedx

Merge request reports