Skip to content

Ensure that `gitlab_standard` comes first in the list of contexts

Alishan Ladhani requested to merge ali/update-ordering-of-standardcontext into master

What does this MR do?

As raised in https://gitlab.com/gitlab-data/analytics/-/issues/8099, the order of Snowplow contexts matters when we are parsing/flattening events.

To make the order consistent between frontend and backend, this MR changes the backend tracking module to always place gitlab_standard (represented in code as StandardContext) first in the list of contexts.

Based on discussion in this slack thread: https://gitlab.slack.com/archives/CL3A7GFPF/p1614977560157100?thread_ts=1614677571.084500&cid=CL3A7GFPF

Looking at this, it seems like we have an inconsistent ordering of contexts between BE and FE. On the frontend, gitlab_standard goes first:

const contexts = [STANDARD_CONTEXT];
  if (data.context) {
    contexts.push(data.context);
  } 

Whereas on the backend, gitlab_standard is added last:

context += [Tracking::StandardContext.new(project: project, user: user, namespace: namespace).to_context]

I think having gitlab_standard first makes sense, so I will make the appropriate change on the backend.

Screenshots

A good event with multiple contexts tested locally:

Screen_Shot_2021-03-11_at_3.23.44_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Alishan Ladhani

Merge request reports