Skip to content

Add custom context to package Snowplow tracking

What does this MR do and why?

Add custom context to Snowplow event according to the new schema

Screenshots or screen recordings

Screen_Shot_2022-11-07_at_10.58.07_AM

How to set up and validate locally

[1] pry(main)> scope = 'npm_package'
=> "npm_package"
[2] pry(main)> event_name = "i_package_#{scope}_user"
=> "i_package_npm_package_user"
[3] pry(main)> category = 'sample_cat'
=> "sample_cat"
[4] pry(main)> action = 'push'
=> "push"
[6] pry(main)> project = Project.first
=> #<Project id:1 gitlab-org/gitlab-test>>
[7] pry(main)> namespace = project.namespace
=> #<Group id:22 @gitlab-org>
[8] pry(main)> args = {namespace: namespace}
=> {:namespace=>#<Group id:22 @gitlab-org>}
[9] pry(main)> ::Gitlab::Tracking.event(
          category,
          action.to_s,
          label: 'redis_hll_counters.user_packages.user_packages_total_unique_counts_monthly',
          context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: event_name).to_context],
POST http://localhost:9091/micro/good
Content-Type: application/json

{
  "contexts": [
    "iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-0"
  ],  "limit": 1
}

Verify the response contains

...
           "schema": "iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-0",
            "data": {
              "data_source": "redis_hll",
              "event_name": "i_package_npm_package_user"
            }
          }
        ]
      },
      "se_category": "sample_cat",
      "se_action": "push",
      "se_label": "redis_hll_counters.user_packages.user_packages_total_unique_counts_monthly",
...

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #371801 (closed)

Edited by Niko Belokolodov

Merge request reports