POC: Action level tracking on backend
Parent issue: https://gitlab.com/gitlab-org/telemetry/issues/290
Background
Currently, backend tracking is done by explicitly calling the GitLab::Tracking.event
class method. This method needs to be explicitly called in each controller action or model we want to track.
Since we're in the early stages of defining what to track, I'd like to explore implementing action-level global tracking which will track every request and action to our Rails application including all CRUD methods, page requests, form posts, API calls, etc.
The tracking can be implemented in ApplicationController which is a lower-level controller that other controllers will inherit from. Example of what an implementation could look like:
class ApplicationController < ActionController::Base
after_action :track_action
protected
def track_action
Gitlab::Tracking.event(controller, action, args)
end
end
Benefits
- This is an easy way to quickly build a dataset of events to explore and sift through. This is a similar approach to what we're doing on the frontend where we first track everything then afterwards define explicit structured frontend events. In this case, global tracking at the action-level allows us to capture everything on the backend then afterwards define explicit structured backend events.
- Backend tracking is likely more accurate than frontend tracking (which has to deal with browsers). More data via backend tracking can be arguably more accurate than more data on the frontend.
Drawbacks
- The entire Rails application can be potentially slowed down. We'll need to do this async and optimize our use of AsyncEmitter to avoid slow downs.
- Since this is a catch-all approach, we'll need to be careful to avoid tracking data not covered by our TOS.
Edited by Jerome Z Ng