Single Instrumentation Layer

Single Instrumentation Layer

The Single Instrumentation Layer is an event tracking abstraction that allows to track any events in GitLab using a single interface. It uses events definitions from Internal Event framework to declare event processing logic.

Why a Single Instrumentation Layer?

The Single Instrumentation Layer allows to:

  • Instrument events and processing logic in a single place
  • Use the same event definitions for both instrumentation and processing
  • Eliminate the need to write duplicate tracking code for the same event

How it works

See example MR.

Event definitions are used as a declarative specification for processing logic and are single source of truth for event properties, tracking parameters, and other metadata.

Additional tracking systems

When an event is intended to be processed by tracking systems (for example, AiTracking), the event definition is extended to include the additional processing logic. example

This logic is declared using additional processing classes using standard interface.

How to implement it for your tracking system

To implement it for your tracking system, you need to:

  1. Add a new event definition or use existing one (see events dictionary).

  2. Implement the processing logic in a new tracking class. The class should have a class method track_event that accepts an event name and additional named parameters

    module Gitlab
      module Tracking
        class NewTrackingSystemProcessor
          def self.track_event(event_name, **kwargs)
            # add your tracking logic here
          end
        end
      end
    end
  3. Extend the event definition with the new tracking class added in extra_tracking_classes: property

    extra_tracking_classes:
      - Gitlab::Tracking::NewTrackingSystemProcessor
  4. Trigger the event in your code using Internal Events framework

**kwargs is used to pass additional parameters to the tracking class from the Internal Events framework. The actual parameters depend on the tracking parameters passed to the event invocation above. Usually, it includes user, namespace and project along with additional_properties that can be used to pass any additional data.

The tracking systems will be triggered by the order of the extra_tracking_classes: property.

Systems that use the Single Instrumentation Layer

  1. Internal Event. Is the main system that implements the tracking layer.
  2. AiTracking. Work in progress on migrating to the new layer.