Skip to content

Additional internal event properties on Backend

Problem

General problem outlined in MVC: Enable passing of additional properties vi... (&12212 - closed) • Unassigned.

Specifically, there's no way to designate additional properties beyond user, project, namespace on Internal events within the Backend

Desired Outcome

Enable passing label, value and property to:

  • all internal events tracking methods
  • the internal events API used by the frontend
  • use a method signature that:
    • signifies that label etc are completely optional, and not pseudo-required like user etc, which always should be added if possible.
    • does not require migrations if we add the ability for completely custom properties.

and pass those on in the appropriate Snowplow field.

Out of scope:

  • Adding additional properties handling to template helpers.
  • Changing documentation/generator (will be covered with #434506 (closed))
  • Migrating an event to use the new methods (covered by #435136 (closed))

Proposed Solution

Discussion in !142839 (comment 1750471499)

New event

Ruby

Gitlab::InternalEvents.track_event(
  'create_import_access_level',
  category: self.class.name,
  user: current_user,
  properties: { 
    user_role: user_role(current_user, target_namespace),
    import_type: 'bitbucket' 
  }
)

JS

this.trackEvent(
  'create_import_access_level',
  properties: {
    user_role: user_role(current_user, target_namespace),
    import_type: 'bitbucket' 
  }

Event Definition

---
description: Creation of an access level during an import...
...
action: create_import_access_level
properties: 
  user_role:
    external_key: label
    description: User role that receives the access level
  import_type:
    external_key: property
    description: Type of import that caused the creation

Migration

Old

# app/controllers/import/bitbucket_controller.rb
 Gitlab::Tracking.event(
      self.class.name,
      'create',
      label: 'import_access_level',
      user: current_user,
      extra: { user_role: user_role(current_user, target_namespace), import_type: 'bitbucket'}
    )

New

# app/controllers/import/bitbucket_controller.rb
Gitlab::InternalEvents.track_event(
  'create',
  category: self.class.name,
  user: current_user,
  properties: { label: 'import_access_level, user_role: user_role(current_user, target_namespace), import_type: 'bitbucket' }
)

Event Definition

---
description: Legacy create event
...
action: create
properties: 
  label:
    external_key: label
    description: Target of the create action
  user_role:
    external_key: extra.user_role
    description: User role that receives the access level
  import_type:
    external_key: extra.import_type
    description: Type of import that caused the creation

How to verify

Verified via #434505 (closed) and #435136 (closed)

Edited by Sebastian Rehm