2019-08-28 02:52:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
class << self
|
|
|
|
def enabled?
|
2021-12-01 10:13:55 -05:00
|
|
|
snowplow.enabled?
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
|
2021-04-01 08:08:56 -04: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-14 22:10:30 -05:00
|
|
|
|
2021-03-12 10:09:33 -05:00
|
|
|
snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => error
|
2021-03-17 08:09:19 -04:00
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
|
2021-09-09 08:09:09 -04:00
|
|
|
def options(group)
|
2021-11-09 01:13:00 -05:00
|
|
|
snowplow.options(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
def collector_hostname
|
|
|
|
snowplow.hostname
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
|
2021-11-24 07:10:21 -05:00
|
|
|
def snowplow_micro_enabled?
|
|
|
|
Rails.env.development? && Gitlab::Utils.to_boolean(ENV['SNOWPLOW_MICRO_ENABLE'])
|
|
|
|
end
|
|
|
|
|
2019-08-28 02:52:14 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def snowplow
|
2021-11-09 01:13:00 -05:00
|
|
|
@snowplow ||= if snowplow_micro_enabled?
|
|
|
|
Gitlab::Tracking::Destinations::SnowplowMicro.new
|
|
|
|
else
|
|
|
|
Gitlab::Tracking::Destinations::Snowplow.new
|
|
|
|
end
|
|
|
|
end
|
2019-08-28 02:52:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|