Module: Gitlab::Tracking

Included in:
ProfilesController
Defined in:
lib/gitlab/tracking.rb,
lib/gitlab/tracking/helpers.rb,
lib/gitlab/tracking/event_definition.rb,
lib/gitlab/tracking/standard_context.rb,
lib/gitlab/tracking/destinations/base.rb,
lib/gitlab/tracking/incident_management.rb,
lib/gitlab/tracking/destinations/snowplow.rb,
lib/gitlab/tracking/destinations/snowplow_micro.rb

Defined Under Namespace

Modules: Destinations, Helpers, IncidentManagement Classes: EventDefinition, StandardContext

Constant Summary collapse

InvalidEventError =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.collector_hostnameObject


37
38
39
# File 'lib/gitlab/tracking.rb', line 37

def collector_hostname
  snowplow.hostname
end

.definition(basename, category: nil, action: nil, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) ⇒ Object

rubocop:disable Metrics/ParameterLists


18
19
20
21
22
# File 'lib/gitlab/tracking.rb', line 18

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

.dispatch_from_definition(definition, **event_data) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/gitlab/tracking.rb', line 24

def dispatch_from_definition(definition, **event_data)
  definition = definition.with_indifferent_access

  category ||= definition[:category]
  action ||= definition[:action]

  event(category, action, **event_data)
end

.enabled?Boolean

Returns:

  • (Boolean)

6
7
8
# File 'lib/gitlab/tracking.rb', line 6

def enabled?
  snowplow.enabled?
end

.event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) ⇒ Object

rubocop:disable Metrics/ParameterLists


10
11
12
13
14
15
16
# File 'lib/gitlab/tracking.rb', line 10

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

.options(group) ⇒ Object


33
34
35
# File 'lib/gitlab/tracking.rb', line 33

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

.snowplow_micro_enabled?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/gitlab/tracking.rb', line 41

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