debian-mirror-gitlab/lib/gitlab/tracking.rb

44 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Gitlab
module Tracking
SNOWPLOW_NAMESPACE = 'gl'
class << self
def enabled?
2021-12-11 22:18:48 +05:30
snowplow_micro_enabled? || Gitlab::CurrentSettings.snowplow_enabled?
2019-12-04 20:38:33 +05:30
end
2021-04-29 21:17:54 +05:30
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-03-08 18:12:59 +05:30
2021-04-17 20:07:23 +05:30
snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
2021-06-08 01:23:25 +05:30
rescue StandardError => error
2021-04-29 21:17:54 +05:30
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
2019-12-21 20:55:43 +05:30
end
2021-11-11 11:23:49 +05:30
def options(group)
2021-12-11 22:18:48 +05:30
snowplow.options(group)
end
def collector_hostname
snowplow.hostname
2019-12-04 20:38:33 +05:30
end
private
def snowplow
2021-12-11 22:18:48 +05:30
@snowplow ||= if snowplow_micro_enabled?
Gitlab::Tracking::Destinations::SnowplowMicro.new
else
Gitlab::Tracking::Destinations::Snowplow.new
end
2020-11-24 15:15:51 +05:30
end
2021-02-22 17:27:13 +05:30
2021-12-11 22:18:48 +05:30
def snowplow_micro_enabled?
Rails.env.development? && Gitlab::Utils.to_boolean(ENV['SNOWPLOW_MICRO_ENABLE'])
2021-02-22 17:27:13 +05:30
end
2019-12-04 20:38:33 +05:30
end
end
end