2019-08-28 06:52:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
class << self
|
|
|
|
def enabled?
|
2022-07-04 09:09:31 +00:00
|
|
|
tracker.enabled?
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
|
2021-04-01 12:08:56 +00:00
|
|
|
def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
|
|
|
|
contexts = [Tracking::StandardContext.new(project: project, user: user, namespace: namespace, **extra).to_context, *context]
|
2021-01-15 03:10:30 +00:00
|
|
|
|
2022-08-29 12:09:58 +00:00
|
|
|
action = action.to_s
|
|
|
|
|
2022-07-04 09:09:31 +00:00
|
|
|
tracker.event(category, action, label: label, property: property, value: value, context: contexts)
|
2021-04-26 12:09:44 +00:00
|
|
|
rescue StandardError => error
|
2021-03-17 12:09:19 +00:00
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
|
2022-04-13 18:08:33 +00:00
|
|
|
def definition(basename, category: nil, action: nil, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
|
|
|
|
definition = YAML.load_file(Rails.root.join("config/events/#{basename}.yml"))
|
|
|
|
|
|
|
|
dispatch_from_definition(definition, label: label, property: property, value: value, context: context, project: project, user: user, namespace: namespace, **extra)
|
|
|
|
end
|
|
|
|
|
|
|
|
def dispatch_from_definition(definition, **event_data)
|
|
|
|
definition = definition.with_indifferent_access
|
|
|
|
|
|
|
|
category ||= definition[:category]
|
|
|
|
action ||= definition[:action]
|
|
|
|
|
|
|
|
event(category, action, **event_data)
|
|
|
|
end
|
|
|
|
|
2021-09-09 12:09:09 +00:00
|
|
|
def options(group)
|
2022-07-04 09:09:31 +00:00
|
|
|
tracker.options(group)
|
2021-11-09 06:13:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def collector_hostname
|
2022-07-04 09:09:31 +00:00
|
|
|
tracker.hostname
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
|
2021-11-24 12:10:21 +00:00
|
|
|
def snowplow_micro_enabled?
|
2022-07-05 21:08:45 +00:00
|
|
|
Rails.env.development? && Gitlab.config.snowplow_micro.enabled
|
|
|
|
rescue Settingslogic::MissingSetting
|
2022-08-05 12:08:59 +00:00
|
|
|
false
|
2021-11-24 12:10:21 +00:00
|
|
|
end
|
|
|
|
|
2019-08-28 06:52:14 +00:00
|
|
|
private
|
|
|
|
|
2022-07-04 09:09:31 +00:00
|
|
|
def tracker
|
|
|
|
@tracker ||= if snowplow_micro_enabled?
|
|
|
|
Gitlab::Tracking::Destinations::SnowplowMicro.new
|
|
|
|
else
|
|
|
|
Gitlab::Tracking::Destinations::Snowplow.new
|
|
|
|
end
|
2021-11-09 06:13:00 +00:00
|
|
|
end
|
2019-08-28 06:52:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-04-13 18:08:33 +00:00
|
|
|
|
|
|
|
Gitlab::Tracking.prepend_mod_with('Gitlab::Tracking')
|