summaryrefslogtreecommitdiff
path: root/lib/gitlab/tracking.rb
blob: a58b4beb0dfd6bacf45449616da3ec741d6c613c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module Gitlab
  module Tracking
    class << self
      def enabled?
        snowplow.enabled?
      end

      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]

        snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
      rescue StandardError => error
        Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
      end

      def options(group)
        snowplow.options(group)
      end

      def collector_hostname
        snowplow.hostname
      end

      def snowplow_micro_enabled?
        Rails.env.development? && Gitlab::Utils.to_boolean(ENV['SNOWPLOW_MICRO_ENABLE'])
      end

      private

      def snowplow
        @snowplow ||= if snowplow_micro_enabled?
                        Gitlab::Tracking::Destinations::SnowplowMicro.new
                      else
                        Gitlab::Tracking::Destinations::Snowplow.new
                      end
      end
    end
  end
end